这是我做的一个小的设计,使用了LCD1602显示,DS1302时钟芯片,51最小系统等。
所有资料打包下载:
4.教室节电.rar
(209.59 KB, 下载次数: 45)
下面是部分源码预览:
- #include "includes.h"
- #include "structions.h"
- sbit relay = P1^7; //继电器接口 0:吸合,1:断开
- void Read_Time(void); //读取时间
- void LCD_DIS_CurrenTime(); //液晶显示当前时间
- void LCD_Const0(); //在液晶上显示固定东西
- void LCD_Const1();
- void LCD_Const2(); //在液晶上显示固定东西
- void Key_Handle_Work(void); //工作模式中,按键处理
- void Key_Handle_Cfg(void); //设置模式中,按键处理
- void Ds1302_Set_CurrentTime(void);
- uchar keyValue = 0; //键值
- uchar relayMode = 0; //默认为自动模式
- uchar workMode = 1; //0:设置,1:工作
- uchar disMode = 0; //显示模式:0显示当前时间 1显示第一组开关灯时间 2显示第二组开关灯时间
- uchar lcdPoint1 = 0; //lcd显示第一页光标位置
- uchar lcdPoint2 = 0; //lcd显示第二页光标位置
- uchar lcdPoint3 = 0; //lcd显示第三页光标位置
- uchar workENA1 = 0; //第一组工作使能
- uchar workENA2 = 0; //第二组工作使能
- void main()
- {
- // Uart_Init(9600);//串口初始化
- Ds1302_Init();
- LCD_Init();
- Timer1_Init();
- relay = 1;
- Read_Time(); //读取当前时间
- LCD_Const0();
- Read_Time(); //读取当前时间
- LCD_DIS_CurrenTime();
- while(1)
- {
-
- keyValue = Read_KeyNum(); //读键值
-
- if(workMode == 1)
- {
- Key_Handle_Work();
- if(relayMode == 0) //自动模式
- {
- if(CurrentTime.Week == 1)
- {
- workENA1 = WeekENA1.Mon,workENA2 = WeekENA2.Mon;
- }
- if(CurrentTime.Week == 2)
- {
- workENA1 = WeekENA1.Tue,workENA2 = WeekENA2.Tue;
- }
- if(CurrentTime.Week == 3)
- {
- workENA1 = WeekENA1.Wed,workENA2 = WeekENA2.Wed;
- }
- if(CurrentTime.Week == 4)
- {
- workENA1 = WeekENA1.Thu,workENA2 = WeekENA2.Thu;
- }
- if(CurrentTime.Week == 5)
- {
- workENA1 = WeekENA1.Fri,workENA2 = WeekENA2.Fri;
- }
- if(CurrentTime.Week == 6)
- {
- workENA1 = WeekENA1.Sat,workENA2 = WeekENA2.Sat;
- }
- if(CurrentTime.Week == 7)
- {
- workENA1 = WeekENA1.Sun,workENA2 = WeekENA2.Sun;
- }
-
- if(workENA1 == 1||workENA2 == 1)
- {
- if(CurrentTime.Hour==OpenTime1.Hour&&CurrentTime.Minute==OpenTime1.Minute&&CurrentTime.Second==0)
- {
- relay = 0;
- }
- if(CurrentTime.Hour==CloseTime1.Hour&&CurrentTime.Minute==CloseTime1.Minute&&CurrentTime.Second==0)
- {
- relay = 1;
- }
- //上面是第一组
- //下面是第二组
- if(CurrentTime.Hour==OpenTime2.Hour&&CurrentTime.Minute==OpenTime2.Minute&&CurrentTime.Second==0)
- {
- relay = 0;
- }
- if(CurrentTime.Hour==CloseTime2.Hour&&CurrentTime.Minute==CloseTime2.Minute&&CurrentTime.Second==0)
- {
- relay = 1;
- }
- }
- }
-
- LCD_DIS_CurrenTime(); //显示当前时间
- if(keyValue == 5)
- {
- LCD_Write_Com(0x80+1);
- LCD_Write_Com(0x0f); //光标闪烁
- lcdPoint1 = 1;
- }
- }
-
- if(workMode == 0)
- {
- Key_Handle_Cfg();
- relay =1; //关灯(继电器)
-
- }
-
-
- }
- }
- void Timer1_Isr(void) interrupt 3
- {
- uint t;
- TR1=0;
- TH1=(65536-50000) / 256;
- TL1=(65536-50000) %256;
- t++;
- if(t == 20)
- {
- t = 0;
- if(workMode == 1) //处于工作模式的时候才需要读取现在时间
- {
- Read_Time(); //读取当前时间
- }
- }
-
- TR1=1;
- }
- void Key_Handle_Work(void)
- {
- if(relayMode == 0) //如果在自动模式下按下按键 ,就是手动开关灯
- {
- if(keyValue == 1)
- {
- if(workENA1 == 1||workENA2 == 1)
- {
- relay = ~relay;
- }
- }
- }
- if(keyValue == 2)
- {
- relayMode++;
- if(relayMode == 0)
- {
- LCD_Write_Char(14,1,'A');
- LCD_Write_Char(15,1,'u');
- }
- if(relayMode == 1)
- {
- LCD_Write_Char(14,1,'O');
- LCD_Write_Char(15,1,'p');
- relay = 0;
- }
- if(relayMode == 2)
- {
- LCD_Write_Char(14,1,'C');
- LCD_Write_Char(15,1,'l');
- relay = 1;
- }
- if(relayMode>=3)
- {
- relayMode = 0;
- LCD_Write_Char(14,1,'A');
- LCD_Write_Char(15,1,'u');
- }
- }
-
- if(keyValue == 5) //按下设置按键
- {
- workMode = 0;
- LCD_Write_Char(14,1,'C');
- LCD_Write_Char(15,1,'F');
- disMode = 0;
- lcdPoint1 = 0;
- lcdPoint2 = 0;
- lcdPoint3 = 0;
-
- }
-
-
- }
- void Key_Handle_Cfg(void)
- {
- uchar dayMax = 0;
- if(keyValue == 1) //按下移位
- {
- if(disMode == 0) //显示当前时间
- {
- lcdPoint1++;
- if(lcdPoint1 == 1) //
- {
- LCD_Write_Com(0x80+1);
- }
- if(lcdPoint1 == 2)
- {
- LCD_Write_Com(0x80+4);
- }
- if(lcdPoint1 == 3)
- {
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint1 == 4)
- {
- LCD_Write_Com(0xc0+1);
- }
- if(lcdPoint1 == 5)
- {
- LCD_Write_Com(0xc0+4);
- }
- if(lcdPoint1 == 6)
- {
- LCD_Write_Com(0xc0+7);
- }
- if(lcdPoint1>6)
- {
- lcdPoint1 = 1;
- LCD_Write_Com(0x80+1);
- }
- }
- if(disMode == 1) //显示开关灯时间1
- {
- lcdPoint2++;
- if(lcdPoint2 == 1) //
- {
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint2 == 2)
- {
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint2 == 3)
- {
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint2 == 4)
- {
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint2 == 5)
- {
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint2 == 6)
- {
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint2 == 7)
- {
- LCD_Write_Com(0x80+12);
- }
- if(lcdPoint2 == 8)
- {
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint2 == 9)
- {
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint2 == 10)
- {
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint2 == 11)
- {
- LCD_Write_Com(0xc0+15);
- }
-
- if(lcdPoint2>11)
- {
- lcdPoint2 = 1;
- LCD_Write_Com(0x80+6);
- }
- }
- if(disMode == 2) //显示开关灯时间2
- {
- lcdPoint3++;
- if(lcdPoint3 == 1) //
- {
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint3 == 2)
- {
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint3 == 3)
- {
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint3 == 4)
- {
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint3 == 5)
- {
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint3 == 6)
- {
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint3 == 7)
- {
- LCD_Write_Com(0x80+12);
- }
- if(lcdPoint3 == 8)
- {
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint3 == 9)
- {
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint3 == 10)
- {
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint3 == 11)
- {
- LCD_Write_Com(0xc0+15);
- }
-
- if(lcdPoint3>11)
- {
- lcdPoint3 = 1;
- LCD_Write_Com(0x80+6);
- }
- }
-
- }
- if(keyValue == 2) //按下加
- {
- if(disMode == 0) //显示当前时间
- {
- if(lcdPoint1 == 1) //指向当前小时
- {
- CurrentTime.Hour++;
- if(CurrentTime.Hour>23)
- {CurrentTime.Hour = 0;}
-
- LCD_Write_Char(0,0,CurrentTime.Hour/10+0x30);
- LCD_Write_Char(1,0,CurrentTime.Hour%10+0x30);
- LCD_Write_Com(0x80+1);
- }
-
- if(lcdPoint1 == 2) //指向当前分钟
- {
- CurrentTime.Minute++;
- if(CurrentTime.Minute>59)
- {CurrentTime.Minute = 0;}
- LCD_Write_Char(3,0,CurrentTime.Minute/10+0x30);
- LCD_Write_Char(4,0,CurrentTime.Minute%10+0x30);
- LCD_Write_Com(0x80+4);
- }
-
- if(lcdPoint1 == 3) //指向当前秒
- {
- CurrentTime.Second++;
- if(CurrentTime.Second>59)
- {CurrentTime.Second = 0;}
- LCD_Write_Char(6,0,CurrentTime.Second/10+0x30);
- LCD_Write_Char(7,0,CurrentTime.Second%10+0x30);
- LCD_Write_Com(0x80+7);
- }
-
- if(lcdPoint1 == 4) //指向当前年
- {
- CurrentTime.Year++;
- if(CurrentTime.Year>30)
- {CurrentTime.Year = 16;}
-
- LCD_Write_Char(0,1,CurrentTime.Year/10+0x30);
- LCD_Write_Char(1,1,CurrentTime.Year%10+0x30);
- LCD_Write_Com(0xc0+1);
- }
- if(lcdPoint1 == 5) //指向当前月
- {
- CurrentTime.Month++;
- if(CurrentTime.Month>12)
- {CurrentTime.Month = 1;}
- LCD_Write_Char(3,1,CurrentTime.Month/10+0x30);
- LCD_Write_Char(4,1,CurrentTime.Month%10+0x30);
- LCD_Write_Com(0xc0+4);
-
- }
- if(lcdPoint1==6) //指向当前日
- {
- if(CurrentTime.Month == 1||CurrentTime.Month == 3||CurrentTime.Month == 5||CurrentTime.Month == 7||CurrentTime.Month == 8||CurrentTime.Month == 10||CurrentTime.Month == 12)
- {dayMax = 31;}
- if(CurrentTime.Month == 4||CurrentTime.Month == 6||CurrentTime.Month == 9||CurrentTime.Month == 11)
- {dayMax = 30;}
- if(CurrentTime.Month == 2&&((CurrentTime.Year%4)!=0))
- {dayMax = 28;}
- if(CurrentTime.Month == 2&&((CurrentTime.Year%4)==0))
- {dayMax = 29;}
- CurrentTime.Day++;
- if(CurrentTime.Day>dayMax)
- {CurrentTime.Day = 1;}
- LCD_Write_Char(6,1,CurrentTime.Day/10+0x30);
- LCD_Write_Char(7,1,CurrentTime.Day%10+0x30);
- LCD_Write_Com(0xc0+7);
- }
- }
- if(disMode == 1) //显示开关灯时间1
- {
- if(lcdPoint2 == 1) //指向星期1使能位
- {
- WeekENA1.Mon = !WeekENA1.Mon;
- LCD_Write_Char(6,0,WeekENA1.Mon+0x30);
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint2 == 2) //指向星期2使能位
- {
- WeekENA1.Tue = !WeekENA1.Tue;
- LCD_Write_Char(7,0,WeekENA1.Tue+0x30);
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint2 == 3) //指向星期3使能位
- {
- WeekENA1.Wed = !WeekENA1.Wed;
- LCD_Write_Char(8,0,WeekENA1.Wed+0x30);
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint2 == 4) //指向星期4使能位
- {
- WeekENA1.Thu = !WeekENA1.Thu;
- LCD_Write_Char(9,0,WeekENA1.Thu+0x30);
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint2 == 5) //指向星期5使能位
- {
- WeekENA1.Fri = !WeekENA1.Fri;
- LCD_Write_Char(10,0,WeekENA1.Fri+0x30);
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint2 == 6) //指向星期6使能位
- {
- WeekENA1.Sat = !WeekENA1.Sat;
- LCD_Write_Char(11,0,WeekENA1.Sat+0x30);
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint2 == 7) //指向星期7使能位
- {
- WeekENA1.Sun = !WeekENA1.Sun;
- LCD_Write_Char(12,0,WeekENA1.Sun+0x30);
- LCD_Write_Com(0x80+12);
- }
- if(lcdPoint2 == 8)
- {
- OpenTime1.Hour++;
- if(OpenTime1.Hour>23)
- {
- OpenTime1.Hour = 0;
- }
- LCD_Write_Char(2,1,OpenTime1.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime1.Hour%10+0x30);
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint2 == 9)
- {
- OpenTime1.Minute++;
- if(OpenTime1.Minute>59)
- {
- OpenTime1.Minute = 0;
- }
- LCD_Write_Char(5,1,OpenTime1.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime1.Minute%10+0x30);
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint2 == 10)
- {
- CloseTime1.Hour++;
- if(CloseTime1.Hour>23)
- {
- CloseTime1.Hour = 0;
- }
- LCD_Write_Char(11,1,CloseTime1.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime1.Hour%10+0x30);
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint2 == 11)
- {
- CloseTime1.Minute++;
- if(CloseTime1.Minute>59)
- {
- CloseTime1.Minute = 0;
- }
- LCD_Write_Char(14,1,CloseTime1.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime1.Minute%10+0x30);
- LCD_Write_Com(0xc0+15);
- }
-
- }
- if(disMode == 2) //显示开关灯时间2
- {
- if(lcdPoint3 == 1) //指向星期1使能位
- {
- WeekENA2.Mon = !WeekENA2.Mon;
- LCD_Write_Char(6,0,WeekENA2.Mon+0x30);
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint3 == 2) //指向星期2使能位
- {
- WeekENA2.Tue = !WeekENA2.Tue;
- LCD_Write_Char(7,0,WeekENA2.Tue+0x30);
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint3 == 3) //指向星期3使能位
- {
- WeekENA2.Wed = !WeekENA2.Wed;
- LCD_Write_Char(8,0,WeekENA2.Wed+0x30);
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint3 == 4) //指向星期4使能位
- {
- WeekENA2.Thu = !WeekENA2.Thu;
- LCD_Write_Char(9,0,WeekENA2.Thu+0x30);
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint3 == 5) //指向星期5使能位
- {
- WeekENA2.Fri = !WeekENA2.Fri;
- LCD_Write_Char(10,0,WeekENA2.Fri+0x30);
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint3 == 6) //指向星期6使能位
- {
- WeekENA2.Sat = !WeekENA2.Sat;
- LCD_Write_Char(11,0,WeekENA2.Sat+0x30);
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint3 == 7) //指向星期7使能位
- {
- WeekENA2.Sun = !WeekENA2.Sun;
- LCD_Write_Char(12,0,WeekENA2.Sun+0x30);
- LCD_Write_Com(0x80+12);
- }
-
- if(lcdPoint3 == 8)
- {
- OpenTime2.Hour++;
- if(OpenTime2.Hour>23)
- {
- OpenTime2.Hour = 0;
- }
- LCD_Write_Char(2,1,OpenTime2.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime2.Hour%10+0x30);
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint3 == 9)
- {
- OpenTime2.Minute++;
- if(OpenTime2.Minute>59)
- {
- OpenTime2.Minute = 0;
- }
- LCD_Write_Char(5,1,OpenTime2.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime2.Minute%10+0x30);
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint3 == 10)
- {
- CloseTime2.Hour++;
- if(CloseTime2.Hour>23)
- {
- CloseTime2.Hour = 0;
- }
- LCD_Write_Char(11,1,CloseTime2.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime2.Hour%10+0x30);
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint3 == 11)
- {
- CloseTime2.Minute++;
- if(CloseTime2.Minute>59)
- {
- CloseTime2.Minute = 0;
- }
- LCD_Write_Char(14,1,CloseTime2.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime2.Minute%10+0x30);
- LCD_Write_Com(0xc0+15);
- }
- }
- }
-
- if(keyValue == 3) //按下减
- {
- if(disMode == 0) //显示当前时间
- {
- if(lcdPoint1 == 1) //指向当前小时
- {
- CurrentTime.Hour--;
- if(CurrentTime.Hour<0)
- {CurrentTime.Hour = 23;}
-
- LCD_Write_Char(0,0,CurrentTime.Hour/10+0x30);
- LCD_Write_Char(1,0,CurrentTime.Hour%10+0x30);
- LCD_Write_Com(0x80+1);
- }
-
-
- if(lcdPoint1 == 2) //指向当前分钟
- {
- CurrentTime.Minute--;
- if(CurrentTime.Minute<0)
- {CurrentTime.Minute = 59;}
- LCD_Write_Char(3,0,CurrentTime.Minute/10+0x30);
- LCD_Write_Char(4,0,CurrentTime.Minute%10+0x30);
- LCD_Write_Com(0x80+4);
- }
-
- if(lcdPoint1 == 3) //指向当前秒
- {
- CurrentTime.Second--;
- if(CurrentTime.Second<0)
- {CurrentTime.Second = 59;}
- LCD_Write_Char(6,0,CurrentTime.Second/10+0x30);
- LCD_Write_Char(7,0,CurrentTime.Second%10+0x30);
- LCD_Write_Com(0x80+7);
- }
-
- if(lcdPoint1 == 4) //指向当前年
- {
- CurrentTime.Year--;
- if(CurrentTime.Year<16)
- {CurrentTime.Year = 30;}
-
- LCD_Write_Char(0,1,CurrentTime.Year/10+0x30);
- LCD_Write_Char(1,1,CurrentTime.Year%10+0x30);
- LCD_Write_Com(0xc0+1);
- }
- if(lcdPoint1 == 5) //指向当前月
- {
- CurrentTime.Month--;
- if(CurrentTime.Month<1)
- {CurrentTime.Month = 12;}
- LCD_Write_Char(3,1,CurrentTime.Month/10+0x30);
- LCD_Write_Char(4,1,CurrentTime.Month%10+0x30);
- LCD_Write_Com(0xc0+4);
-
- }
- if(lcdPoint1==6) //指向当前日
- {
- if(CurrentTime.Month == 1||CurrentTime.Month == 3||CurrentTime.Month == 5||CurrentTime.Month == 7||CurrentTime.Month == 8||CurrentTime.Month == 10||CurrentTime.Month == 12)
- {dayMax = 31;}
- if(CurrentTime.Month == 4||CurrentTime.Month == 6||CurrentTime.Month == 9||CurrentTime.Month == 11)
- {dayMax = 30;}
- if(CurrentTime.Month == 2&&((CurrentTime.Year%4)!=0))
- {dayMax = 28;}
- if(CurrentTime.Month == 2&&((CurrentTime.Year%4)==0))
- {dayMax = 29;}
- CurrentTime.Day--;
- if(CurrentTime.Day<1)
- {CurrentTime.Day = dayMax;}
- LCD_Write_Char(6,1,CurrentTime.Day/10+0x30);
- LCD_Write_Char(7,1,CurrentTime.Day%10+0x30);
- LCD_Write_Com(0xc0+7);
- }
- }
- if(disMode == 1) //显示开关灯时间1
- {
- if(lcdPoint2 == 1) //指向星期1使能位
- {
- WeekENA1.Mon = !WeekENA1.Mon;
- LCD_Write_Char(6,0,WeekENA1.Mon+0x30);
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint2 == 2) //指向星期2使能位
- {
- WeekENA1.Tue = !WeekENA1.Tue;
- LCD_Write_Char(7,0,WeekENA1.Tue+0x30);
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint2 == 3) //指向星期3使能位
- {
- WeekENA1.Wed = !WeekENA1.Wed;
- LCD_Write_Char(8,0,WeekENA1.Wed+0x30);
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint2 == 4) //指向星期4使能位
- {
- WeekENA1.Thu = !WeekENA1.Thu;
- LCD_Write_Char(9,0,WeekENA1.Thu+0x30);
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint2 == 5) //指向星期5使能位
- {
- WeekENA1.Fri = !WeekENA1.Fri;
- LCD_Write_Char(10,0,WeekENA1.Fri+0x30);
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint2 == 6) //指向星期6使能位
- {
- WeekENA1.Sat = !WeekENA1.Sat;
- LCD_Write_Char(11,0,WeekENA1.Sat+0x30);
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint2 == 7) //指向星期7使能位
- {
- WeekENA1.Sun = !WeekENA1.Sun;
- LCD_Write_Char(12,0,WeekENA1.Sun+0x30);
- LCD_Write_Com(0x80+12);
- }
- if(lcdPoint2 == 8)
- {
- OpenTime1.Hour--;
- if(OpenTime1.Hour<0)
- {
- OpenTime1.Hour = 23;
- }
- LCD_Write_Char(2,1,OpenTime1.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime1.Hour%10+0x30);
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint2 == 9)
- {
- OpenTime1.Minute--;
- if(OpenTime1.Minute<0)
- {
- OpenTime1.Minute = 59;
- }
- LCD_Write_Char(5,1,OpenTime1.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime1.Minute%10+0x30);
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint2 == 10)
- {
- CloseTime1.Hour--;
- if(CloseTime1.Hour<0)
- {
- CloseTime1.Hour = 23;
- }
- LCD_Write_Char(11,1,CloseTime1.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime1.Hour%10+0x30);
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint2 == 11)
- {
- CloseTime1.Minute--;
- if(CloseTime1.Minute<0)
- {
- CloseTime1.Minute = 59;
- }
- LCD_Write_Char(14,1,CloseTime1.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime1.Minute%10+0x30);
- LCD_Write_Com(0xc0+15);
- }
-
- }
- if(disMode == 2) //显示开关灯时间2
- {
- if(lcdPoint3 == 1) //指向星期1使能位
- {
- WeekENA2.Mon = !WeekENA2.Mon;
- LCD_Write_Char(6,0,WeekENA2.Mon+0x30);
- LCD_Write_Com(0x80+6);
- }
- if(lcdPoint3 == 2) //指向星期2使能位
- {
- WeekENA2.Tue = !WeekENA2.Tue;
- LCD_Write_Char(7,0,WeekENA2.Tue+0x30);
- LCD_Write_Com(0x80+7);
- }
- if(lcdPoint3 == 3) //指向星期3使能位
- {
- WeekENA2.Wed = !WeekENA2.Wed;
- LCD_Write_Char(8,0,WeekENA2.Wed+0x30);
- LCD_Write_Com(0x80+8);
- }
- if(lcdPoint3 == 4) //指向星期4使能位
- {
- WeekENA2.Thu = !WeekENA2.Thu;
- LCD_Write_Char(9,0,WeekENA2.Thu+0x30);
- LCD_Write_Com(0x80+9);
- }
- if(lcdPoint3 == 5) //指向星期5使能位
- {
- WeekENA2.Fri = !WeekENA2.Fri;
- LCD_Write_Char(10,0,WeekENA2.Fri+0x30);
- LCD_Write_Com(0x80+10);
- }
- if(lcdPoint3 == 6) //指向星期6使能位
- {
- WeekENA2.Sat = !WeekENA2.Sat;
- LCD_Write_Char(11,0,WeekENA2.Sat+0x30);
- LCD_Write_Com(0x80+11);
- }
- if(lcdPoint3 == 7) //指向星期7使能位
- {
- WeekENA2.Sun = !WeekENA2.Sun;
- LCD_Write_Char(12,0,WeekENA2.Sun+0x30);
- LCD_Write_Com(0x80+12);
- }
-
- if(lcdPoint3 == 8)
- {
- OpenTime2.Hour--;
- if(OpenTime2.Hour<0)
- {
- OpenTime2.Hour = 23;
- }
- LCD_Write_Char(2,1,OpenTime2.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime2.Hour%10+0x30);
- LCD_Write_Com(0xc0+3);
- }
- if(lcdPoint3 == 9)
- {
- OpenTime2.Minute--;
- if(OpenTime2.Minute<0)
- {
- OpenTime2.Minute = 59;
- }
- LCD_Write_Char(5,1,OpenTime2.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime2.Minute%10+0x30);
- LCD_Write_Com(0xc0+6);
- }
- if(lcdPoint3 == 10)
- {
- CloseTime2.Hour--;
- if(CloseTime2.Hour<0)
- {
- CloseTime2.Hour = 23;
- }
- LCD_Write_Char(11,1,CloseTime2.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime2.Hour%10+0x30);
- LCD_Write_Com(0xc0+12);
- }
- if(lcdPoint3 == 11)
- {
- CloseTime2.Minute--;
- if(CloseTime2.Minute<0)
- {
- CloseTime2.Minute = 59;
- }
- LCD_Write_Char(14,1,CloseTime2.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime2.Minute%10+0x30);
- LCD_Write_Com(0xc0+15);
- }
- }
- }
-
- if(keyValue == 4) //按下了翻页按键 ,用于调整显示的内容,只在设置模式里起作用
- {
-
- disMode++;
- if(disMode>2)
- {
- disMode = 0;
- }
- if(disMode == 0)
- {
- LCD_Clear();
- LCD_Const0();
- LCD_Write_Char(14,1,'C');
- LCD_Write_Char(15,1,'F');
- LCD_DIS_CurrenTime(); //显示当前时间
- LCD_Write_Com(0x80+1);
- lcdPoint1 = 1;
- }
- if(disMode == 1)
- {
- LCD_Clear();
- LCD_Const1();
- LCD_Write_Char(6,0,WeekENA1.Mon+0x30);
- LCD_Write_Char(7,0,WeekENA1.Tue+0x30);
- LCD_Write_Char(8,0,WeekENA1.Wed+0x30);
- LCD_Write_Char(9,0,WeekENA1.Thu+0x30);
- LCD_Write_Char(10,0,WeekENA1.Fri+0x30);
- LCD_Write_Char(11,0,WeekENA1.Sat+0x30);
- LCD_Write_Char(12,0,WeekENA1.Sun+0x30);
- LCD_Write_Char(2,1,OpenTime1.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime1.Hour%10+0x30);
- LCD_Write_Char(5,1,OpenTime1.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime1.Minute%10+0x30);
-
- LCD_Write_Char(11,1,CloseTime1.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime1.Hour%10+0x30);
- LCD_Write_Char(14,1,CloseTime1.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime1.Minute%10+0x30);
-
- LCD_Write_Com(0x80+6);
- lcdPoint2 = 1;
- }
- if(disMode == 2)
- {
- LCD_Clear();
- LCD_Const2();
-
- LCD_Write_Char(6,0,WeekENA2.Mon+0x30);
- LCD_Write_Char(7,0,WeekENA2.Tue+0x30);
- LCD_Write_Char(8,0,WeekENA2.Wed+0x30);
- LCD_Write_Char(9,0,WeekENA2.Thu+0x30);
- LCD_Write_Char(10,0,WeekENA2.Fri+0x30);
- LCD_Write_Char(11,0,WeekENA2.Sat+0x30);
- LCD_Write_Char(12,0,WeekENA2.Sun+0x30);
-
- LCD_Write_Char(2,1,OpenTime2.Hour/10+0x30);
- LCD_Write_Char(3,1,OpenTime2.Hour%10+0x30);
- LCD_Write_Char(5,1,OpenTime2.Minute/10+0x30);
- LCD_Write_Char(6,1,OpenTime2.Minute%10+0x30);
- LCD_Write_Char(11,1,CloseTime2.Hour/10+0x30);
- LCD_Write_Char(12,1,CloseTime2.Hour%10+0x30);
- LCD_Write_Char(14,1,CloseTime2.Minute/10+0x30);
- LCD_Write_Char(15,1,CloseTime2.Minute%10+0x30);
- LCD_Write_Com(0x80+6);
- lcdPoint3 = 1;
- }
- }
-
- if(keyValue == 6) //按下确认按键
- {
- workMode = 1;
- LCD_Write_Com(0x0c); /*显示开及光标设置*/
- LCD_Clear();
- LCD_Const0();
- Ds1302_Set_CurrentTime();
- relayMode = 0;
- disMode = 0;
- lcdPoint1 = 0;
- lcdPoint2 = 0;
- lcdPoint3 = 0;
- }
-
- }
- void Read_Time(void) //读取时间
- {
- uchar Curtime[7];
- v_Get1302(Curtime);
- CurrentTime.Second = bcdtodec(Curtime[0]);
- CurrentTime.Minute = bcdtodec(Curtime[1]);
- CurrentTime.Hour = bcdtodec(Curtime[2]);
- CurrentTime.Day = bcdtodec(Curtime[3]);
- CurrentTime.Month = bcdtodec(Curtime[4]);
- CurrentTime.Week = Conver_week(CurrentTime.Year,CurrentTime.Month,CurrentTime.Day); //自动计算星期
-
- //CurrentTime.Week = bcdtodec(Curtime[5]);
- CurrentTime.Year = bcdtodec(Curtime[6]);
- }
- void LCD_DIS_CurrenTime() //LCD显示当前时间
- {
- LCD_Write_Char(0,0,CurrentTime.Hour/10+0x30);
- LCD_Write_Char(1,0,CurrentTime.Hour%10+0x30);
- LCD_Write_Char(3,0,CurrentTime.Minute/10+0x30);
- LCD_Write_Char(4,0,CurrentTime.Minute%10+0x30);
-
- LCD_Write_Char(6,0,CurrentTime.Second/10+0x30);
- LCD_Write_Char(7,0,CurrentTime.Second%10+0x30);
- LCD_Write_Char(13,0,CurrentTime.Week+0x30);
-
- LCD_Write_Char(0,1,CurrentTime.Year/10+0x30);
- LCD_Write_Char(1,1,CurrentTime.Year%10+0x30);
- LCD_Write_Char(3,1,CurrentTime.Month/10+0x30);
- LCD_Write_Char(4,1,CurrentTime.Month%10+0x30);
-
- LCD_Write_Char(6,1,CurrentTime.Day/10+0x30);
- LCD_Write_Char(7,1,CurrentTime.Day%10+0x30);
- }
- void LCD_Const0() //显示固定的东西,只需要显示一次
- {
- char *s = "Mode:Au";
- LCD_Write_Char(2,0,'-');
- LCD_Write_Char(5,0,'-');
- LCD_Write_Char(10,0,'W');
- LCD_Write_Char(11,0,'-');
- LCD_Write_Char(12,0,'<');
- LCD_Write_Char(14,0,'>');
-
- LCD_Write_Char(2,1,'-');
- LCD_Write_Char(5,1,'-');
- LCD_Write_String(9,1,s);
- }
- void LCD_Const1() //显示固定的东西,只需要显示一次
- {
- LCD_Write_Char(0,0,'0');
- LCD_Write_Char(1,0,'1');
- LCD_Write_Char(2,0,':');
- LCD_Write_Char(4,1,'-');
-
- LCD_Write_Char(0,1,'S');
- LCD_Write_Char(1,1,':');
- LCD_Write_Char(9,1,'X');
- LCD_Write_Char(10,1,':');
- LCD_Write_Char(13,1,'-');
- }
- void LCD_Const2() //显示固定的东西,只需要显示一次
- {
- LCD_Write_Char(0,0,'0');
- LCD_Write_Char(1,0,'2');
- LCD_Write_Char(2,0,':');
- LCD_Write_Char(4,1,'-');
-
- LCD_Write_Char(0,1,'S');
- LCD_Write_Char(1,1,':');
- LCD_Write_Char(9,1,'X');
- LCD_Write_Char(10,1,':');
- LCD_Write_Char(13,1,'-');
- }
- void Ds1302_Set_CurrentTime(void)
- {
- T_RST = 0; //RST脚置低
- T_CLK = 0; //SCK脚置低
- v_W1302(0x8e,0x00);
- Write_DS1302Init(CurrentTime.Year,CurrentTime.Month,CurrentTime.Day,CurrentTime.Week,CurrentTime.Hour,CurrentTime.Minute,CurrentTime.Second);
- v_W1302(0x8e,0x80); //打开写保护
- }
复制代码
|