這是我做的一個小的設計,使用了LCD1602顯示,DS1302時鐘芯片,51最小系統等。
0.png (91.72 KB, 下載次數: 42)
下載附件
2016-12-23 04:06 上傳
0.png (48.4 KB, 下載次數: 58)
下載附件
2016-12-23 04:06 上傳
所有資料打包下載:
4.教室節電.rar
(209.59 KB, 下載次數: 45)
2016-12-22 09:26 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
下面是部分源碼預覽:
- #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); //打開寫保護
- }
復制代碼
|