资源描述:
《温度传感c语言程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、温度传感C语言程序//function:readthetemperatureanddisplayitonthedigitaltube#include〃msp430xl4x.H〃#defineSHUMAPORTDIRP2DIR//digitalpipedataPoundsigndefineSHUMAPORTOUTP20UT#defineSHUMA1LOWPlOUT&二、BIT1//thefirstP6.6controlofthedigitaltubePoundsigndefineSHUMA1HIGHPlOUT
2、=BIT1//destroythe
3、firstdigitaltubeDefineSHUMA2LOWPlOUT&二~BIT2//openthesecondplaceofthedigitaltubePoundsigndefineSHUMA2HIGHPlOUT
4、二BIT2//thesecondplaceofthedigitaltubeDefineSHUMA3LOWPlOUT&二~BIT3//opendigitalPoundsigndefineSHUMA3HIGHPlOUT
5、=BIT3//thethirdplaceofthedigitaltubeDefineSHUMA_4_L0WPlO
6、UT&二~BIT4//opendigitalPoundsigndefineSHUMA4HIGHP1OUT
7、=thefourthplaceofBIT4//thedigitaltube//DS18B20controlpindefinition#defineDQ_0UTP1DIR二BITO#defineDQ_INP1DIR#defineDQ_HPlOUT
8、二二BITO#definedq_ploutPoundsigndefineDQ_DATE(P1IN&BITO)Voidint_clk();//theclockinitializerdeclarati
9、onVoiddelay_352us(unsignedintI);//352usdelayproceduredeclarationVoidint_shuma_io();//digitalpipedataportinitializationVoiddelay_us(unsignedintI);//delay2.5usat8MUnsignedcharrest_dsl8b20(void);//DS18B20resetprogramUnsignedintRead_Temperature();//readingtemperatureVoidWriteOn
10、eChar(unsignedcharvalue);//writeabyteUnsignedcharReadOneChar(void);Unsignedcharconsttab11[]二{0X3F,0x06,0x4f,0x6d,0x7d,0x7f,0x6d,0x6d.Unsignedcharconsttab12[]二{OXBF,0x86,Oxdb,Oxfd,0x87,Oxff,Oxef}Thestaticunsignedchartempitemph;///v{>v{>v{>k{xk{xk{>^T>^T>^T>^T>^T>//readingtem
11、peratureUnsignedintRead_Temperature(){Unsignedcharc=0;C二rest_dsl8b20();If(c二二0){WriteOneChar(0XCC);//skiptheoperationofnumberOxcf,0xe6,theserialX44WriteOneChar(0);//startthetemperatureconversionDelay_us(10);C二rest_dsl8b20();WriteOneChar(0XCC);//skiptheoperationoftheserialnu
12、mberThexbeWriteOneChar(0);//readingthetemperatureregister,whichisthefirsttwoofthenineregisters,isthetemperatureTemp1二ReadOneChar();Temph二ReadOneChar();}Return((temph*256+tempi)/16);}//readabyteUnsignedcharReadOneChar(void){Unsignedchar1=0;For(1=0;I<8;I++)Thevalue>>=1;DQ_OUT
13、;DQ_L;DQ_IN;//DQ二1DQ_L;If(DQ_DATE)value
14、二0x80;Delay_us(16);//delay40us}Thereturnva