ds18b20程序 lm386 超声波测距
delay1(1); writebyte(0xcc); writebyte(0xbe); a=readbyte(); b=readbyte(); temp=b; temp<<=8; temp=temp|a; f_temp=temp*0.0625; temp=f_temp*10+0.5; f_temp=f_temp+0.05; return temp; }
void warn(uchar s) { uchar i; i=s; c=1; b=0; a=1; wr=0; beep=1; wr=1; delay1(s); c=1; b=0; a=1; wr=0; beep=0; wr=1; i=s; delay1(s); }
void deal(uint t) { uchar i; if(t>250&t<=270) { warn(40); } else if(t<=250) { warn(10); } else if(t<320&t>300)
{ warn(40); } else if(t>=320) { warn(10); } else { i=40; delay1(i); } }
void main() { uint x; while(1) { change(); x=get_temp(); display(x); deal(x); } }