j = 234;
k = 113;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Init_timer0() { TMOD &= 0xf0; TMOD |= 0x05; TH0 = TL0 = 0; TR0 = 1; ET0 = 0; } void Init_timer1()//50 { TMOD &= 0x0f; TMOD |= 0x10; TH1 = 0x3c; TL1 = 0xb0; TR1 = 1; EA = 1; ET1 = 1; } void sevice_timer1() interrupt 3 { TH1 = 0x3c; TL1 = 0xb0; count_1s++; if(count_1s == 20) { TR0 = 0; count_1s = 0; count_f = (TH0 << 8) | TL0; TH0 = TL0 = 0; TR0 = 1; } if(flag_caiji == 1) { count_3s++; if(count_3s == 60) { count_3s = 0; flag_caiji = 0; UI = UI_LS; UI_huixian = UI_huixian_LS; } } if(stat_changan == 1) { count_CA++; } if(stat_warn == 1) { count_01s++; if(count_01s == 2) { count_01s = 0; if(stat_shan == 0) { stat_shan = 1; } else { stat_shan = 0; } } } } void Init_mytemp() { unsigned char LSB,MSB; init_ds18b20(); Write_DS18B20(0xcc); Write_DS18B20(0x44); do{ init_ds18b20(); Write_DS18B20(0xcc); Write_DS18B20(0xbe); LSB = Read_DS18B20(); MSB = Read_DS18B20(); MSB = (MSB << 4) | (LSB >> 4); }while(MSB == 85); } void read_mytemp() { static unsigned char n = 0; unsigned char LSB,MSB; unsigned int temp; init_ds18b20(); Write_DS18B20(0xcc); Write_DS18B20(0x44); init_ds18b20(); Write_DS18B20(0xcc); Write_DS18B20(0xbe); LSB = Read_DS18B20(); MSB = Read_DS18B20(); temp = MSB << 8; temp = temp | LSB; if((temp & 0xf800) == 0x0000) { temp_value = temp * 0.0625; if(max_temp < (int)temp_value)max_temp = (int)temp_value; n++; aver_temp = (((aver_temp *(n-1)) + temp_value)/n); temp_smg = aver_temp * 10; if(n == 10)n=0; } } void Init_mytimer() { unsigned char i; Write_Ds1302_Byte(0x8e,0x00); for(i = 0;i < 7;i++) { Write_Ds1302_Byte(write_addre[i],now_timer[i]); } Write_Ds1302_Byte(0x8e,0x80); } void read_mytimer() { t_h = Read_Ds1302_Byte(0x85); t_m = Read_Ds1302_Byte(0x83); t_s = Read_Ds1302_Byte(0x81); } void read_myvolt() { I2CStart(); I2CSendByte(0x90); I2CWaitAck(); I2CSendByte(0x01); I2CWaitAck(); I2CStop();
I2CStart();
I2CSendByte(0x91);
I2CWaitAck();
adc_value = I2CReceiveByte();
I2CSendAck(1);
I2CStop();
} void SelectHC573(unsigned char channel,unsigned char dat) { P2 = (P2 & 0x1f) | 0x00; P0 = dat; switch(channel) { case 4: P2 = (P2 & 0x1f) | 0x80; break; case 5: P2 = (P2 & 0x1f) | 0xa0; break; case 6: P2 = (P2 & 0x1f) | 0xc0; break; case 7: P2 = (P2 & 0x1f) | 0xe0; break; case 0: P2 = (P2 & 0x1f) | 0x00; break; } P2 = (P2 & 0x1f) | 0x00; } void DelaySMG(unsigned int t) { while(t--); } void DisplaySMG_Bit(unsigned char pos,unsigned char value) { SelectHC573(6,0x01 << pos); SelectHC573(7,value); DelaySMG(TSMG); SelectHC573(6,0x01 << pos); SelectHC573(7,0xff); } void DisplaySMG_All(unsigned char value) { SelectHC573(6,0xff); SelectHC573(7,value); } void DisplaySMG_Info() { switch(UI) { case 0: DisplaySMG_Bit(0,Seg_Table[t_h >> 4]); DisplaySMG_Bit(1,Seg_Table[t_h & 0x0f]); DisplaySMG_Bit(2,0xbf); DisplaySMG_Bit(3,Seg_Table[t_m >> 4]); DisplaySMG_Bit(4,Seg_Table[t_m & 0x0f]); DisplaySMG_Bit(5,0xbf); DisplaySMG_Bit(6,Seg_Table[(t_s >> 4) & 0x07]); DisplaySMG_Bit(7,Seg_Table[t_s & 0x0f]); break; case 1: switch(UI_huixian) { case 0: DisplaySMG_Bit(0,0xc6); if(num_chufa != 0) { DisplaySMG_Bit(2,Seg_Table[max_temp / 10]); DisplaySMG_Bit(3,Seg_Table[max_temp % 10]); DisplaySMG_Bit(4,0xbf); DisplaySMG_Bit(5,Seg_Table[temp_smg / 100]); DisplaySMG_Bit(6,nodot[temp_smg / 10 % 10]); DisplaySMG_Bit(7,Seg_Table[temp_smg % 10]); } break; case 1: DisplaySMG_Bit(0,0x89); if(num_chufa != 0) { DisplaySMG_Bit(2,Seg_Table[max_shidu / 10]); DisplaySMG_Bit(3,Seg_Table[max_shidu % 10]); DisplaySMG_Bit(4,0xbf); DisplaySMG_Bit(5,Seg_Table[shidu_smg / 100]); DisplaySMG_Bit(6,nodot[shidu_smg / 10 % 10]); DisplaySMG_Bit(7,Seg_Table[shidu_smg % 10]); } break; case 2: DisplaySMG_Bit(0,0x8e); DisplaySMG_Bit(1,Seg_Table[num_chufa / 10]); DisplaySMG_Bit(2,Seg_Table[num_chufa % 10]); if(num_chufa != 0) { DisplaySMG_Bit(3,Seg_Table[cf_h >> 4]); DisplaySMG_Bit(4,Seg_Table[cf_h & 0x0f]); DisplaySMG_Bit(5,0xbf); DisplaySMG_Bit(6,Seg_Table[cf_m >> 4]); DisplaySMG_Bit(7,Seg_Table[cf_m & 0x0f]); } break; } break; case 2: DisplaySMG_Bit(0,0x8c); DisplaySMG_Bit(6,Seg_Table[temp_param / 10]); DisplaySMG_Bit(7,Seg_Table[temp_param % 10]); break; case 3: DisplaySMG_Bit(0,0x86); DisplaySMG_Bit(3,Seg_Table[temp_smg / 100]); DisplaySMG_Bit(4,Seg_Table[temp_smg / 10 % 10]); DisplaySMG_Bit(5,0xbf); if((count_f < 200) || (count_f > 2000)) { DisplaySMG_Bit(6,0x88); DisplaySMG_Bit(7,0x88); } else { DisplaySMG_Bit(6,Seg_Table[shidu_smg / 100]); DisplaySMG_Bit(7,Seg_Table[shidu_smg / 10 % 10]); }
break;
}
}
void average_data() { static unsigned char i = 0; if(count_f < 200) { shidu = 10; i++; } else if(count_f < 2000) { shidu = (80.0/1800)*count_f + 10.0/9; i++; } else { shidu = 90; i++; } if(max_shidu < shidu) max_shidu = shidu; aver_s = (((aver_s (i-1)) + shidu)/i); shidu_smg = aver_s10; if(i == 10)i = 0; } void caiji_chufa() { if(flag_caiji == 0) { if(stat_dat == 0) { stat_dat = 1; old_value = adc_value; old_temp = temp_value; old_shidu = shidu; } if((old_value > 20) && (adc_value < 20)) { flag_caiji = 1; num_chufa++; UI_LS = UI; UI_huixian_LS = UI_huixian; UI = 3; cf_h = t_h; cf_m = t_m; } old_value = adc_value; old_temp = temp_value; old_shidu = shidu; } if(stat_changan == 2) { if(count_CA > 40) { num_chufa = 0; cf_h = 0; cf_m = 0; count_CA = 0; stat_changan = 0; } } } void Scan_key() { s1 = 0; s2 = h1 = h2 = 1; if(h1 == 0)//s5 { Delay20ms(); if(h1 == 0) { if(UI == 1) { if(UI_huixian == 0) { UI_huixian = 1; } else if(UI_huixian == 1) { UI_huixian = 2; } else { UI_huixian = 0; } } while(h1 == 0) { DisplaySMG_Info(); } } } else if(h2 == 0)//s4 { Delay20ms(); if(h2 == 0) { if(UI == 0) { UI = 1; } else if(UI == 1) { UI = 2; } else { UI = 0; } while(h2 == 0) { DisplaySMG_Info(); } } } s2 = 0; s1 = h1 = h2 = 1; if(h1 == 0)//s9 { Delay20ms(); if(h1 == 0) { if(UI == 2) { if(temp_param == 0) { temp_param = 99; } else { temp_param -= 1; } } if(UI_huixian == 2) { stat_changan = 1; } while(h1 == 0) { DisplaySMG_Info(); } stat_changan = 2; }
收集整理了一份《2024年最新物联网嵌入式全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升的朋友。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!