- #include<iom16v.h>
- #include<macros.h>
- #include"DEFINE.H"
- #include"DELAY.H"
- #include"LCD_1602_DRIVE.H"
- #include"MATRIX_KEYBOARD_DRIVE.H"
- #include"DIGITAL-TEMPERATURE-PROBE_DS18B20_DRIVE.H"
- #include"UART_GPRS_DTU.H"
- extern unsigned char uart_receive_data_buffer[60];
- extern unsigned char phone_number[11];
- unsigned char uart_dtu_online_ok;
- uint setting_temperature_h=40;
- uint setting_temperature_l=20;
- uint current_temperature=0;
- uchar over_count=0;
- uchar send;
- uchar temp_number[11];
- void temperature_display()
- {
- uint temp;
- lcd_1602_show_character_string(1,1,"H ");
- lcd_1602_show_datas(1,3,2,setting_temperature_h);
- lcd_1602_show_character_string(1,5,".");
- lcd_1602_show_datas(1,6,1,0);
- lcd_1602_show_character_string(1,7,"C");
- lcd_1602_show_character_string(1,10,"L ");
- lcd_1602_show_datas(1,12,2,setting_temperature_l);
- lcd_1602_show_character_string(1,14,".");
- lcd_1602_show_datas(1,15,1,0);
- lcd_1602_show_character_string(1,16,"C");
- lcd_1602_show_character_string(2,1,"Current:");
- lcd_1602_show_character_string(2,12,".");
- lcd_1602_show_character_string(2,14,"C");
- temp=ds18b20_read_temperature();
- if(temp>0x0fff)
- {
- lcd_1602_show_character_string(2,9,"-");
- current_temperature=((~(temp>>4))&0x007f)+1;
- lcd_1602_show_datas(2,10,2,current_temperature);
- lcd_1602_show_datas(2,13,1,(temp&0x000f)*(0.625));
- }
- else
- {
- lcd_1602_show_character_string(2,9," ");
- current_temperature=(((temp>>4))&0x007f);
- lcd_1602_show_datas(2,10,2,current_temperature);
- lcd_1602_show_datas(2,13,1,(temp&0x000f)*(0.625));
- }
- }
- void key_setting()
- {
- uchar key,i;
- key=_4x3_matrix_keyboard_keys_read();
- if(key==SET_ALARM)
- {
- lcd_1602_write_com(0x01);
- lcd_1602_show_character_string(1,1,"AlarmTemperature");
- lcd_1602_show_character_string(2,1,"H ");
- lcd_1602_show_character_string(2,5,".");
- lcd_1602_show_character_string(2,7,"C");
- lcd_1602_show_character_string(2,10,"L ");
- lcd_1602_show_character_string(2,14,".");
- lcd_1602_show_character_string(2,16,"C");
- while(1)
- {
- lcd_1602_show_datas(2,3,2,setting_temperature_h);
- lcd_1602_show_datas(2,6,1,0);
- lcd_1602_show_datas(2,12,2,setting_temperature_l);
- lcd_1602_show_datas(2,15,1,0);
- key=_4x3_matrix_keyboard_keys_read();
- if(key==UP_H)
- {
- if(setting_temperature_h<255)
- {
- setting_temperature_h++;
- }
- }
- else if(key==DOWN_H)
- {
- if(setting_temperature_h>0)
- {
- setting_temperature_h--;
- }
- }
- else if(key==UP_L)
- {
- if(setting_temperature_l<255)
- {
- setting_temperature_l++;
- }
- }
- else if(key==DOWN_L)
- {
- if(setting_temperature_l>0)
- {
- setting_temperature_l--;
- }
- }
- else if(key==OK)
- {
- lcd_1602_write_com(0x01);
- break;
- }
- }
- }
- else if(key==SET_NUM)
- {
- lcd_1602_write_com(0x01);
- lcd_1602_show_character_string(1,1,"Cell phone number");
- lcd_1602_show_character_string(2,1,"Num:");
- for(i=0;i<11;i++)
- {
- lcd_1602_show_datas(2,(5+i),1,phone_number[i]);
- }
- lcd_1602_show_character_string(2,4,":");
- i=0;
- lcd_1602_write_com(0x0F);
- while(1)
- {
- key=_4x3_matrix_keyboard_keys_read();
- if(key==OK)
- {
- for(i=0;i<11;i++)
- {
- phone_number[i]=temp_number[i];
- }
- lcd_1602_write_com(0x0c);
- lcd_1602_write_com(0x01);
- break;
- }
- else if(key==CLE)
- {
- lcd_1602_write_com(0x0c);
- lcd_1602_write_com(0x01);
- break;
- }
- else if(key!=NOT)
- {
-
- if(i<11)
- {
- lcd_1602_show_datas(2,(5+i),1,key);
- temp_number[i]=key;
- i++;
- if(i>10)
- {
- lcd_1602_show_character_string(2,4,":");
- i=0;
- }
- }
- }
- }
- }
- else if(key==CLE)
- {
- ALARM_STOP;
- }
- }
- void overheat_alarm()
- {
- if((current_temperature>setting_temperature_h)||(current_temperature<setting_temperature_l))
- {
- if(over_count>=10)
- {
- if(send==0)
- {
- ALARM_START;
- DTU_ONLINE
- while(!uart_send_short_message(setting_temperature_h,setting_temperature_l,current_temperature));
- DTU_SHELVE
- send=1;
- }
- }
- else
- {
- over_count++;
- }
- }
- else if((current_temperature<(setting_temperature_h-1))&&(current_temperature>(setting_temperature_l+1)))
- {
- ALARM_STOP;
- send=0;
- over_count=0;
- }
- }
- void main(void)
- {
- lcd_1602_init();
- lcd_1602_write_com(0x01);
- while(1)
- {
- key_setting();
- temperature_display();
- overheat_alarm();
- }
- }
复制代码
|