|
程序是我這里復(fù)制的,按鍵程序是我自己寫的,求大神幫看下,為什么按鍵要長按下 才有反應(yīng);
- while (1)
- {
- if (flag1s) //每秒更新一次溫度
- {
- LcdShowStr(0, 1, "WD:"); //顯示到液晶屏上
- LcdShowStr(6, 1, "SD:"); //顯示到液晶屏上
- LcdShowStr(0, 0, "F:");
- DHT_Start();
- tmp1=DHT_ByteRead(&DHT);
- if(tmp1==1)
- {
- str[0] = (DHT[0]/10)%10 + '0'; //十位轉(zhuǎn)為ASCII碼
- str[1] = (DHT[0]%10) + '0'; //個(gè)位轉(zhuǎn)為ASCII
- str[2] = '\0';
- LcdShowStr(9, 1, str);
- str[0] = (DHT[2]/10)%10 + '0'; //十位轉(zhuǎn)為ASCII碼
- str[1] = (DHT[2]%10) + '0'; //個(gè)位轉(zhuǎn)為ASCII
- str[2] = '\0';
- LcdShowStr(3,1, str);
- WD= DHT[2];
- SD=DHT[0];
- temp2=adc0832(voc);
- if(temp2==1)
- {str[0] = voc/1000 + '0';
- str[1] = (voc%1000)/100 + '0';
- str[2] = ((voc%1000)%100)/10 + '0';
- str[3] = ('.') ;
- str[4] = ((voc%1000)%100)%10 + '0';
- str[5] = '\0';
- LcdShowStr(2, 0, str);
-
- }
-
- }
-
-
- key();
- }
-
-
-
-
-
-
- }
-
- }
- void key (void)
- { unsigned char str[12];
-
- if(Key1==0)
- {
- set++;
- delay();
- if(set==1)
- LcdShowStr(7, 0, "STH:");
- if(set==2)
- LcdShowStr(7, 0, "STL:");
- if(set==3)
- LcdShowStr(7, 0, "SRH:");
- if(set==4)
- LcdShowStr(7, 0, "SRL:");
- if(set==5)
- LcdShowStr(7, 0, "VOC:");
- if(set>=6)
- set=0;
- while(!Key1);
- }
- if(Key2==0)
- {
- if(set==1)
- {
- STH++;
- str[0] = (STH/10)%10 + '0';
- str[1] = (STH%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==2)
- {
- STL++;
- str[0] = (STL/10)%10 + '0';
- str[1] = (STL%10) + '0';
- str[2] = '\0';
- LcdShowStr(11,0, str);
- }
- if(set==3)
- {
- SRH++;
- str[0] = (SRH/10)%10 + '0';
- str[1] = (SRH%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==4)
- {
- SRL++;
- str[0] = (SRL/10)%10 + '0';
- str[1] = (SRL%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==5)
- {
- VOC++;
- str[0] = (VOC/10)%10 + '0';
- str[1] = (VOC%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- delay();
- }
- if(Key3==0)
- {
- if(set==1)
- {
- STH--;
- str[0] = (STH/10)%10 + '0';
- str[1] = (STH%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==2)
- {
- STL--;
- str[0] = (STL/10)%10 + '0';
- str[1] = (STL%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==3)
- {
- SRH--;
- str[0] = (SRH/10)%10 + '0';
- str[1] = (SRH%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==4)
- {
- SRL--;
- str[0] = (SRL/10)%10 + '0';
- str[1] = (SRL%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- if(set==5)
- {
- VOC--;
- str[0] = (VOC/10)%10 + '0';
- str[1] = (VOC%10) + '0';
- str[2] = '\0';
- LcdShowStr(11, 0, str);
- }
- delay();
- }
- if(Key4==0)
- {
- delay();
- set=0;
- InitLcd1602();
- //初始化液晶
- }
-
- }
-
- void ConfigTimer0(unsigned int ms)
- {
- unsigned long tmp; //臨時(shí)變量
- tmp = 11059200 / 12; //定時(shí)器計(jì)數(shù)頻率
- tmp = (tmp * ms) / 1000; //計(jì)算所需的計(jì)數(shù)值
- tmp = 65536 - tmp; //計(jì)算定時(shí)器重載值
- tmp = tmp + 12; //補(bǔ)償中斷響應(yīng)延時(shí)造成的誤差
- T0RH = (unsigned char)(tmp>>8); //定時(shí)器重載值拆分為高低字節(jié)
- T0RL = (unsigned char)tmp;
- TMOD &= 0xF0; //清零T0的控制位
- TMOD |= 0x01; //配置T0為模式1
- TH0 = T0RH; //加載T0重載值
- TL0 = T0RL;
- ET0 = 1; //使能T0中斷
- TR0 = 1; //啟動T0
- }
- /* T0中斷服務(wù)函數(shù),完成1秒定時(shí) */
- void InterruptTimer0() interrupt 1
- {
- static unsigned char tmr1s = 0;
- TH0 = T0RH; //重新加載重載值
- TL0 = T0RL;
- tmr1s++;
- if (tmr1s >= 100) //定時(shí)1s
- {
- tmr1s = 0;
- flag1s = 1;
-
- }
- }
復(fù)制代碼
|
|