完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include #include #include #define uchar unsigned char #define uint unsigned int ***it R=P2^3; ***it lcdrs=P2^0; ***it lcdrw=P2^1; ***it lcden=P2^2; ***it di=P2^4; unsigned char time ; uchar th,tl,a,b,c,d,f,j,e; uint temp; unsigned char code table[]={"0123456789.:'C"}; unsigned char code table1[]={"temp:"}; unsigned char code error[]={" error!"}; void delay1ms() { unsigned int x,y; for(x=0;x<10;x++) for(y=33;y>0;y--); } void delay(unsigned int z) { unsigned char x; for(x=z;x>0;x--) delay1ms();} void write_com(unsigned char com) { lcdrs=0; SBUF=com; while(TI==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } void write_data(unsigned char dat) { lcdrs=1; SBUF=dat; while(TI==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } void init(void) { lcden=0; lcdrw=0; write_com(0x01); write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x80); } /*DS18b20操作program*/ bit datayn(void) //初始化设置 { bit flag; di=1; for(time=0;time<2;time++); di=0; for(time=0;time<200;time++); di=1; for(time=0;time<10;time++); flag=di; for(time=0;time<100;time++); di=1; for(time=0;time<10;time++); return(flag) ; } uchar read_onechar(void) { uchar i,dat; for(i=0;i<8;i++); { di=1;_nop_(); di=0; dat>>=1; _nop_(); _nop_(); _nop_();_nop_(); _nop_(); di=1; for(time=0;time<2;time++); if(di==1) dat|=0x80; else dat|=0x00; for(time=0;time<4;time++); } return dat; } void write_onechar(uchar dat) { uchar i,time; for(i=0;i<8;i++); { di=1; _nop_(); di=0; for(time=0;time<5;time++); di=dat&0x01; for(time=0;time<15;time++); di=1; _nop_();_nop_(); dat>>=1; } for(time=0;time<3;time++); } void display(void) { unsigned int i=0; write_com(0x80); if(datayn()==1) { while(error[i]!=' |