本设计为基于单片机的热水器仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
太阳能热水器单片机源程序如下:
- #include"reg52.h"
- #include"LCD1602.h"
- #include"delay.h"
- #include"DS1302.h"
- #include"DS18B20.h"
- uchar DS_Data[]={0x46,0x20,0x21,0x20,0x10,0x01,0x15}; //05年10月20 21:20:30
- uchar Data_RTO[7];
- uchar Week[]="MON TUE WEN THU FRI SAT SUN";
- uchar *Date,N,SW_Flag,Change_Flag;
- char Knum,T_SET=25,H_SET=2,Height=1;
- void init() //液晶初始化子函数
- {
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void RTO_Display()
- {
- v_Get1302(0x81,Data_RTO,7);
-
- write_com(0x80);
- write_data('2');
- write_data('0');
- write_data((Data_RTO[6]>>4&0x0f)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[6]&0x0f)+0x30);
- write_data('-');
- write_data((Data_RTO[4]>>4&0x0f)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[4]&0x0f)+0x30);
- write_data('-');
- write_data((Data_RTO[3]>>4&0x0f)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[3]&0x0f)+0x30);
- write_com(0xc0);
- write_data((Data_RTO[2]>>4&0x0f)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[2]&0x0f)+0x30);
- write_data(':');
- write_data((Data_RTO[1]>>4&0x0f)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[1]&0x0f)+0x30);
- write_data(':');
- write_data((Data_RTO[0]>>4&0x07)+0x30); //备注:+ 的优先级高于&;>>优先级高于&
- write_data((Data_RTO[0]&0x0f)+0x30);
- Date=&Week[((Data_RTO[5]&0x0f)-1)*4]; //显示星期
- LCD_write_string1(10,1,Date);
- }
- void KEY_SCAN()
- {
- char High,Low;
- if(K1==0)
- {
- delay(10);
- while(!K1);
- N++;
- SW_Flag=0;
- write_com(0x0e);
- switch(N)
- {
- case 1: write_com(0x82); break;
- case 2: write_com(0x85); break;
- case 3: write_com(0x88); break;
- case 4: write_com(0xc0); break;
- case 5: write_com(0xc3); break;
- case 6: write_com(0xc6); break;
- case 7: write_com(0xca); break;
- case 8:
- {
- write_com(0x0c);
- N=0;
- if(Change_Flag==1)
- {
- Change_Flag=0;
- v_Set1302(0x80 ,DS_Data,7);
- }
- } break;
- }
- }
- if(N!=0)
- {
- if(SW==0)
- {
- delay(10);
- while(!SW);
- SW_Flag++;
- // SW_Temp=SW_Flag;
- if(SW_Flag==1)
- {
- switch(N)
- {
- case 1: write_com(0x83); break;
- case 2: write_com(0x86); break;
- case 3: write_com(0x89); break;
- case 4: write_com(0xc1); break;
- case 5: write_com(0xc4); break;
- case 6: write_com(0xc7); break;
- }
- }
- if(SW_Flag==2)
- {
- SW_Flag=0;
- switch(N)
- {
- case 1: write_com(0x82); break;
- case 2: write_com(0x85); break;
- case 3: write_com(0x88); break;
- case 4: write_com(0xc0); break;
- case 5: write_com(0xc3); break;
- case 6: write_com(0xc6); break;
- }
- }
- }
- if(UP==0)
- {
- delay(10);
- while(!UP);
- Change_Flag=1;
- //********************************************** Year
- if((SW_Flag==0)&&(N==1))
- {
- Low=Data_RTO[6]&0x0f;
- High=(Data_RTO[6]>>4&0x0f);
- High++;
- if(High>9)
- High=0;
- write_data(High+0x30);
- write_com(0x82);
-
- Data_RTO[6]=DS_Data[6]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==1))
- {
- Low=Data_RTO[6]&0x0f;
- High=(Data_RTO[6]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0x83);
-
- Data_RTO[6]=DS_Data[6]=(High<<4)|Low;
- }
- //****************************************************** Year
- //****************************************************** Month
- if((SW_Flag==0)&&(N==2))
- {
- Low=Data_RTO[4]&0x0f;
- High=(Data_RTO[4]>>4&0x0f);
- High++;
- if(High>1)
- High=0;
- write_data(High+0x30);
- write_com(0x85);
-
- Data_RTO[4]=DS_Data[4]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==2))
- {
- Low=Data_RTO[4]&0x0f;
- High=(Data_RTO[4]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0x86);
-
- Data_RTO[4]=DS_Data[4]=(High<<4)|Low;
- }
- //******************************************************Month
- //******************************************************Date
- if((SW_Flag==0)&&(N==3))
- {
- Low=Data_RTO[3]&0x0f;
- High=(Data_RTO[3]>>4&0x0f);
- High++;
- if(High>3)
- High=0;
- write_data(High+0x30);
- write_com(0x88);
-
- Data_RTO[3]=DS_Data[3]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==3))
- {
- Low=Data_RTO[3]&0x0f;
- High=(Data_RTO[3]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0x89);
-
- Data_RTO[3]=DS_Data[3]=(High<<4)|Low;
- }
- //******************************************************Date
- //******************************************************Hour
- if((SW_Flag==0)&&(N==4))
- {
- Low=Data_RTO[2]&0x0f;
- High=(Data_RTO[2]>>4&0x0f);
- High++;
- if(High>2)
- High=0;
- write_data(High+0x30);
- write_com(0xc0);
-
- Data_RTO[2]=DS_Data[2]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==4))
- {
- Low=Data_RTO[2]&0x0f;
- High=(Data_RTO[2]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0xc1);
-
- Data_RTO[2]=DS_Data[2]=(High<<4)|Low;
- }
- //******************************************************Hour
- //******************************************************Munite
- if((SW_Flag==0)&&(N==5))
- {
- Low=Data_RTO[1]&0x0f;
- High=(Data_RTO[1]>>4&0x0f);
- High++;
- if(High>5)
- High=0;
- write_data(High+0x30);
- write_com(0xc3);
-
- Data_RTO[1]=DS_Data[1]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==5))
- {
- Low=Data_RTO[1]&0x0f;
- High=(Data_RTO[1]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0xc4);
-
- Data_RTO[1]=DS_Data[1]=(High<<4)|Low;
- }
- //******************************************************Munite
- //******************************************************Second
- if((SW_Flag==0)&&(N==6))
- {
- Low=Data_RTO[0]&0x0f;
- High=(Data_RTO[0]>>4&0x0f);
- High++;
- if(High>5)
- High=0;
- write_data(High+0x30);
- write_com(0xc6);
-
- Data_RTO[0]=DS_Data[0]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==6))
- {
- Low=Data_RTO[0]&0x0f;
- High=(Data_RTO[0]>>4&0x0f);
- Low++;
- if(Low>9)
- Low=0;
- write_data(Low+0x30);
- write_com(0xc7);
-
- Data_RTO[0]=DS_Data[0]=(High<<4)|Low;
- }
- //******************************************************Second
- //******************************************************Day
- if(N==7)
- {
- Low=Data_RTO[5];
- Low++;
- if(Low>7)
- Low=1;
- Date=&Week[(Low-1)*4]; //显示星期
- LCD_write_string(10,1,Date);
- write_com(0xca);
- Data_RTO[5]=DS_Data[5]=Low;
- }
- //******************************************************Day
- }
- if(DOWN==0)
- {
- delay(10);
- while(!DOWN);
- Change_Flag=1;
- //******************************************************Year
- if((SW_Flag==0)&&(N==1))
- {
- Low=Data_RTO[6]&0x0f;
- High=(Data_RTO[6]>>4&0x0f);
- High--;
- if(High<0)
- High=9;
- write_data(High+0x30);
- write_com(0x82);
-
- Data_RTO[6]=DS_Data[6]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==1))
- {
- Low=Data_RTO[6]&0x0f;
- High=(Data_RTO[6]>>4&0x0f);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0x83);
-
- Data_RTO[6]=DS_Data[6]=(High<<4)|Low;
- }
- //******************************************************Year
- //******************************************************Month
- if((SW_Flag==0)&&(N==2))
- {
- Low=Data_RTO[4]&0x0f;
- High=(Data_RTO[4]>>4&0x0f);
- High--;
- if(High<0)
- High=1;
- write_data(High+0x30);
- write_com(0x85);
-
- Data_RTO[4]=DS_Data[4]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==2))
- {
- Low=Data_RTO[4]&0x0f;
- High=(Data_RTO[4]>>4&0x0f);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0x86);
-
- Data_RTO[4]=DS_Data[4]=(High<<4)|Low;
- }
- //******************************************************Month
- //******************************************************Date
- if((SW_Flag==0)&&(N==3))
- {
- Low=Data_RTO[3]&0x0f;
- High=(Data_RTO[3]>>4&0x0f);
- High--;
- if(High<0)
- High=3;
- write_data(High+0x30);
- write_com(0x88);
-
- Data_RTO[3]=DS_Data[3]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==3))
- {
- Low=Data_RTO[3]&0x0f;
- High=(Data_RTO[3]>>4&0x0f);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0x89);
-
- Data_RTO[3]=DS_Data[3]=(High<<4)|Low;
- }
- //******************************************************Date
- //******************************************************Hour
- if((SW_Flag==0)&&(N==4))
- {
- Low=Data_RTO[2]&0x0f;
- High=(Data_RTO[2]>>4&0x0f);
- High--;
- if(High<0)
- High=2;
- write_data(High+0x30);
- write_com(0xc0);
-
- Data_RTO[2]=DS_Data[2]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==4))
- {
- Low=Data_RTO[2]&0x0f;
- High=(Data_RTO[2]>>4&0x0f);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0xc1);
-
- Data_RTO[2]=DS_Data[2]=(High<<4)|Low;
- }
- //******************************************************Hour
- //******************************************************Munite
- if((SW_Flag==0)&&(N==5))
- {
- Low=Data_RTO[1]&0x0f;
- High=(Data_RTO[1]>>4&0x0f);
- High--;
- if(High<0)
- High=5;
- write_data(High+0x30);
- write_com(0xc3);
-
- Data_RTO[1]=DS_Data[1]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==5))
- {
- Low=Data_RTO[1]&0x0f;
- High=(Data_RTO[1]>>4&0x0f);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0xc4);
-
- Data_RTO[1]=DS_Data[1]=(High<<4)|Low;
- }
- //******************************************************Munite
- //******************************************************Second
- if((SW_Flag==0)&&(N==6))
- {
- Low=Data_RTO[0]&0x0f;
- High=(Data_RTO[0]>>4&0x0f);
- High--;
- if(High<0)
- High=5;
- write_data(High+0x30);
- write_com(0xc6);
-
- Data_RTO[0]=DS_Data[0]=(High<<4)|Low;
- }
- if((SW_Flag==1)&&(N==6))
- {
- Low=Data_RTO[0]&0x0f;
- High=(Data_RTO[0]>>4&0x07);
- Low--;
- if(Low<0)
- Low=9;
- write_data(Low+0x30);
- write_com(0xc7);
-
- Data_RTO[0]=DS_Data[0]=(High<<4)|Low;
- }
- //******************************************************Second
- //******************************************************Day
- if(N==7)
- {
- Low=Data_RTO[5];
- Low--;
- if(Low<1)
- Low=7;
- Date=&Week[(Low-1)*4]; //显示星期
- LCD_write_string1(10,1,Date);
- write_com(0xca);
- Data_RTO[5]=DS_Data[5]=Low;
- }
- //******************************************************Day
- }
- }
- }
- void HeightorTemp_Set()
- {
- if(TorW_SET==0)
- {
- delay(5);
- while(!TorW_SET);
- Knum++;
- if(Knum==1)
- {
- write_com(0x01);
- LCD_write_string(0,0," Heignt Set");
- LCD_write_string(0,1,"Please Input:1L");
- }
- else if(Knum==2)
- {
- write_com(0x01);
- LCD_write_string(0,0,"Temprature Set");
- LCD_write_string(0,1,"Please Input:00");
- }
- else if(Knum==3)
- {
- Knum=0;
- write_com(0x01);
- }
- }
- if(Knum==1)
- {
- if(Jia==0)
- {
- delay(5);
- while(!Jia);
- H_SET++;
- if(H_SET>4)
- H_SET=4;
- }
- if(Jian==0)
- {
- delay(5);
- while(!Jian);
- H_SET--;
- if(H_SET<0)
- H_SET=0;
- }
- write_com(0xC0+13);
- write_data(H_SET+0x30);
- }
-
- if(Knum==2)
- {
- if(Jia==0)
- {
- delay(5);
- while(!Jia);
- T_SET++;
- if(T_SET>99)
- T_SET=99;
- }
- if(Jian==0)
- {
- delay(5);
- while(!Jian);
- T_SET--;
- if(T_SET<0)
- T_SET=0;
- }
- write_com(0xC0+13);
- write_data(T_SET/10+0x30);
- write_data(T_SET%10+0x30);
- }
- }
- void HeightCheck()
- {
- if(W1L==0)
- {
- delay(5);
- while(!W1L);
- Height=1;
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
仿真 程序.rar
(124.23 KB, 下载次数: 227)
|