资源描述:
《ds18b20自动搜索rom51c程序多点测温经验证》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、DS18B20自动搜索R0M51C程序多点测温经验证#inelude#include#defineucharunsignedchar//defineunsignedsinglebyte#defineuintunsignedint//defineunsignedplasticsurgery#defineMAXNUM2//definesthemaximumnumberofDS18B20thatisnotdisplayedPlsbitDQ=3;//definethedatalineSbitRS
2、二P2八4;SbitRW二P2八5;SbitE二P2"6;UcharcodelcdO[]SEARCHROMING…〃};Ucharcodelcdl[]SEARCHROMOK!Ucharcodelcd2[]Thetotalis:〃Ucharcodelcd3[]No.codeUchar'8','9','lcd4[]=f0T','2','3','4','5','7',UchardatL6J.Uchartemp_l,temp_h,is_fuwen,temp_x,temp_over,t;Ucharnum二0;UintI;Ucharal[
3、MAXNUM];IdataucharID[MAXNUM][8];//二{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Voidalarm_search(void);/***********************LCDmodule*4、;E二1;P0二com;E二0;Delay();}VoidLCD_write_data(uchardat){Delay();RS二1;RW二0;E二0;E二1;P0二dat;E二0;Delay();}Voidinit()//initialization{LCD_write_com(0xOl);X38LCDwritecom(0);XOcLCDwritecom(0);LCDwrite_comx06(0);}/************************dsl8b20**//Voiddelay_nus(uintn)//delay
5、program8+6(inandout)=14usWh订e(n-);}Voidreset(void)//dsl8b20initializestheresetoperation{Unsignedcharx二0;DQ二1;//DQresetDelay_nus(8);//slightlydelayDQ=0;//thechipmachinewilllowerDQDelay_nus(80);//exactdelayisgreaterthan480usDQ二1;//pullupbusDelay_nus(10);X二DQ;//slightl
6、ydelayedifx=0initializessuccessx二1failstoinitializeDQ二0;_nop_();_nop_();DQ二dat&0xOl;Delay_nus(5);DQ二1;}Voidwrite_byte(uchardat)//writeabyte{UnsignedcharI,j;For(1=8)Write_bit(j);Dat>>二1;}}Ucharread_2bit()/readtwosubroutines{UcharI;Uchardat二0;"For"(I二2;I>;I--)DQ二0;//t
7、hepulsesignalDat<<=1;DQ二1;//thepulsesignalIf(DQ)Delay_nus(4);Return(dat);}Ucharreadbyte{Uchar1=0;Uchardat二0;For(I=8){DQ=0;//theDat〉>二1;DQ二1;//theIf(DQ)()//readabytesubroutinepulsesignalpulsesignalDelay_nus(4);Return(dat);Voiddelay_nms(uintn){Uintj;For(j=0;j8、Voidread_temp(ucharI)//readingtemperaturesubroutine{Ucharf;Thereset();Write_byte(0XCC);Write_byte(0x44);Delay_nms(50000);Thereset();Write_