{ DS=0;
i++;i++; DS=1;
i=8;while(i>0)i--; } else {
DS=0; i=8;while(i>0)i--; DS=1; i++;i++; } } }
uchar dsread(void) {
uchar i,j,dat; dat=0;
for(i=1;i<=8;i++) {
j=dsreadbit();
dat=(j<<7)|(dat>>1);
}
return(dat); }
35
bit dsreadbit(void) {
uint i; bit dat;
DS=0;i++; DS=1;i++;i++; dat=DS;
i=8;while(i>0)i--; return (dat); }
void dsreset(void) {
uint i; DS=0; i=103;
while(i>0)i--; DS=1; i=4;
while(i>0)i--; }
void tmprchange(void) {
dsreset(); delay(1); dswrite(0xcc); dswrite(0x44);
36
}
void getspeed(void) {
uint temp;
float tempr;
uchar a,b;
dsreset(); //初始化 delay(1);
dswrite(0xcc); //跳过ROM dswrite(0xbe); //读温度命令 a=dsread(); //读低八位 b=dsread(); //读高八位 temp=b;
temp<<=8;
temp=temp|a; //高低八位合并
if(b > 127){ //判断温度正负,并作相应处理
temp=~temp+1; tempr=temp*0.0625;
speed=(((331.4-tempr*0.61)/1000000)*10)/2;
}else{
temp=temp;
tempr=temp*0.0625;
speed=(((331.4+tempr*0.61)/1000000)*10)/2;
} }
tmp=tempr;
37
//*************键盘扫描***************
void keyscan(void){ if( !key1 ){ delay(10);
if( key1 ){
return; }
write_com(0x01); displayword(b); warn=1; while( !key1 ); write_com(0x01); displayword(c); return;
}
if( !key2 || !key3 ){
delay(10); if( !key2 || !key3 ){ warn=1; setflag =0; write_com(0x01); displayword(a); displaynum(alarmdis);
while(1){ loop: if(key2 == 0){ setflag++;
if(setflag == 1){
38
}
}
displayword(a1);
if(setflag == 2){ while( !key2 ); }
while( !key2 ); delay(10);
goto loop;
setflag=0; write_com(0x01); displayword(c); return;
if(key3 == 0){
if( !setflag ){
disl++;
if( disl == 10 ){ }
disl=0;
}else{ }
alarmdis=dish*10+disl; displaynum(alarmdis); while( !key3 );
39
dish++;
if( dish == 2 ){ }
dish=0;