《基于MSP430G2553的DS18B20测温程序》由会员分享,可在线阅读,更多相关《基于MSP430G2553的DS18B20测温程序(15页珍藏版)》请在金锄头文库上搜索。
1、./* * main.c */*include header file*/#include #include system.h#include uart.h#include ds18b20.hunsigned int temp;char tx_buf6 = 0,0,0,0,n,0;/* Function name: main* Descriptions: main function* input parameters: none* output parameters: none* Returned value:none*/void main(void)System_Init();UartIni
2、t();_EINT();if (DS18B20_Init()P1OUT |= BIT0;elseP1OUT |= BIT6;while (1)_delay_cycles(800000);_delay_cycles(800000);temp = DS18B20_GetTemp();/x_buf0 = temp%10000/1000+0;/tx_buf1 = temp%1000/100+0;/tx_buf2 = temp%100/10+0;/tx_buf3 = temp%10+0;tx_buf0 = temp%100/10+0;tx_buf1 = temp%10+0;Uart_SendStr(tx
3、_buf);/*Include header file*/#include #include system.h/*Function Declaration*/void Config_WDT(void);void Config_Clock(void);void Config_IO(void);/* Function name: Config_WDT* Descriptions: WatchDog Timer Configuration* input parameters: none* output parameters: none* Returned value: none*/void Conf
4、ig_WDT(void)WDTCTL = WDTPW + WDTHOLD; / Stop watchdog timer/* Function name: Config_Clock* Descriptions: System Clock Configuration* input parameters: none* output parameters: none* Returned value: none*/void Config_Clock(void)BCSCTL1 = CALBC1_8MHZ;/ Set DCO 1M 8M 12M 16MDCOCTL = CALDCO_8MHZ;BCSCTL2
5、 = SELM_1 + DIVM_1 + DIVS_3;/ MCLK = 8M;SMCLK = 1MBCSCTL2 &= SELS;if (CALBC1_8MHZ = 0xFF | CALDCO_8MHZ = 0xFF)while(1);/hang-up/* Function name: Config_IO* Descriptions: IO Port Configuration* input parameters: none* output parameters: none* Returned value: none*/void Config_IO(void)/ set all IO por
6、t outputsP1DIR = 0xFF; / All P1.x outputsP1OUT = 0x00; / All P1.x resetP2DIR = 0xFF; / All P2.x outputsP2OUT = 0x00; / All P2.x reset/* Function name: System_Init* Descriptions: WatchDog Timer Configuration* input parameters: none* output parameters: none* Returned value: none*/void System_Init(void)Config_WDT();Config_Clock();Config_IO();_delay_cycles(800000);_delay_cycles(800000);#ifndef SYSTEM_H_#define SYSTEM_H_/*Extern Function Declaration*/extern void System_Init(void);#endif /* SYSTEM_H_ */*/#include #include #include uart.h/* Function name: UartInit* Descriptions: