#include "reg51.h" //???????????????????? #include "lcd1602.h" //lcd1602?????,??????LCD????? #include "temp.h" //DS18B20????????,??????DS18B20?????,????????????? typedef unsigned int u16; //??????????? typedef unsigned char u8; sbit k1 = P1^0; //??6????? sbit k2 = P1^1; sbit k3 = P1^2; sbit k4 = P1^3; sbit k5 = P1^4; sbit k6 = P1^5; sbit led=P2^3; //led? int f; //??????? unsigned int temp;//???????,???,???????2???,??????100???? char state = 0; //0???,1??? unsigned char lcd[11]; //??lcd????? unsigned char lcd_data[9][5]; //??10???????? char key_state=0; //???1, ?????????? char local = 1;// ????????,???local?? void delay(u16 i) //????,???????,led???? { while(i--); } void Delay1s() //????,???????,key3?????????? { unsigned char i, j, k; i = 21; j = 12; k = 155; do { do { while (--k); } while (--j); } while (--i); } /******************************************************************************* * ??? :Keypros() * ???? :?????? * ?? : ? * ?? : ? *******************************************************************************/ void Keypros() { int n=1; if(k1==0) { delay(1000); //???? if(k1==0) //??key1??,??????,?/? { TR0=0; if(state==0) { key_state=0; state = 1; lcd[0] = '0'; lcd[1] = '0'; lcd[2] = '.'; lcd[3] = '0'; lcd[4] = '0'; lcd[5] = ' '; LCD_Display(0,0,lcd); //???,??00.00 } else { key_state=0; state = 0; lcd[0] = ' '; lcd[1] = ' '; lcd[2] = ' '; lcd[3] = ' '; lcd[4] = ' '; lcd[5] = ' '; LCD_Display(0,0,lcd);//???,??? } } while(!k1); } if(k2==0) //??key2??,key_state????,?/?,key_state???(1),???????,????????? { delay(1000); //???? if(k2==0) { if(state==1) { if(key_state==0) { key_state=1; //key_state=1??????,???????? } else { key_state=0; } } } while(!k2); } if(k3==0) //key3???,???????,??????????lcd_data? { delay(1000); //???? if(k3==0) { TR0=0; key_state=0; if(state==1) { for(n=1;n<=10;n++) { f=Ds18b20ReadTemp(); //??10?DS18B20???,??? temp=f*0.0625*100+0.5; lcd[0] = temp % 10000 / 1000+'0'; lcd[1] = temp % 1000 / 100+'0'; lcd[2] = '.'; lcd[3] = temp % 100 / 10+'0'; lcd[4] = temp % 10+'0'; LCD_Display(0,0,lcd);//???10?? if(temp>=3700) { while(1) { delay(50000); led=~led; } } lcd_data[n-1][0] = lcd[0]; lcd_data[n-1][1] = lcd[1]; lcd_data[n-1][2] = lcd[2]; lcd_data[n-1][3] = lcd[3]; lcd_data[n-1][4] = lcd[4]; Delay1s(); } } } while(!k3); } if(k4==0)//k4???,????????LCD1602??,????,local??1,??????????? { delay(1000); //???? if(k4==0) { TR0=0; key_state=0; if(state==1) { if(local==10) { local=1; } else { local=local+1; } lcd[0] = lcd_data[local-1][0]; lcd[1] = lcd_data[local-1][1]; lcd[2] = lcd_data[local-1][2]; lcd[3] = lcd_data[local-1][3]; lcd[4] = lcd_data[local-1][4]; LCD_Display(0,0,lcd);//?? } } while(!k4); } if(k5==0)//k5???,????????LCD1602??,????,local??1,??????????? { delay(1000); //???? if(k5==0) { TR0=0; key_state=0; if(state==1) { if(local==1) { local=10; } else { local=local-1; } lcd[0] = lcd_data[local-1][0]; lcd[1] = lcd_data[local-1][1]; lcd[2] = lcd_data[local-1][2]; lcd[3] = lcd_data[local-1][3]; lcd[4] = lcd_data[local-1][4]; LCD_Display(0,0,lcd);//?? } } while(!k5); } if(k6==0)//k6???,???????0 { delay(1000); //???? if(k6==0) { TR0=0; key_state=0; for(n=1;n<=10;n++) { lcd[0] = '0'; lcd[1] = '0'; lcd[2] = '.'; lcd[3] = '0'; lcd[4] = '0'; lcd_data[n-1][0] = lcd[0]; lcd_data[n-1][1] = lcd[1]; lcd_data[n-1][2] = lcd[2]; lcd_data[n-1][3] = lcd[3]; lcd_data[n-1][4] = lcd[4]; } LCD_Display(0,0,lcd); //??00.00 } while(!k6); } } void Timer0Init() { TMOD|=0X01;//??????0??,????1,??TR0????? TH0=0XFC; //???????,??1ms TL0=0X18; ET0=1;//?????0???? EA=1;//????? TR0=1;//????? } void T0Function() interrupt 1 //?????,key2???,???????,?????????? { static int m=0; if(m<500) { m++; } else { TR0=0;//????????DS18B20???,???????????? f=Ds18b20ReadTemp(); //??10?DS18B20???,??? temp=f*0.0625*100+0.5; lcd[0] = temp % 10000 / 1000+'0'; lcd[1] = temp % 1000 / 100+'0'; lcd[2] = '.'; lcd[3] = temp % 100 / 10+'0'; lcd[4] = temp % 10+'0'; LCD_Display(0,0,lcd);//???10?? if(temp>=3700)//????37?,led???? { while(1) { delay(50000); led=~led; } } m=0; TR0=1; } TH0=0XFC; //???????,??1ms TL0=0X18; } void main()//??? { LCD_Init();//LCD1602??? led = 0; Timer0Init();//T0????? EA=1; TR0=0; f==Ds18b20ReadTemp(); while(1) { if(key_state==1)//??????? { TR0=1; } else { TR0=0; } Keypros();//???? } } |