基于stm32c8t6,结合DHT12 、 DS1302 、OLED 屏 、 5独立按键,可实现5界面切换:第一界面时间显示,温湿度显示;第二界面秒表功能,按键开启、结束与清零;第三界面录放音,同步记录录放音时间显示 ;第四界面三闹钟,按键选择闹钟,并制定闹钟时间;第五界面时间调整,通过按键手动调节1302时间。同时具备简单串口接收功能,上位机发送1,
单片机即回传1.程序未优化,main函数1000多行基本全是界面设计,但逻辑比较清晰
单片机源程序如下:
- #include "Systerm.h"
- /*****************秒表变量*********************/
- u32 Stopwatch_counting = 0;
- u8 Stopwatch_Start = 0;
- u8 Stopwatch_RST = 0;
- /*****************录音变量*********************/
- u16 Luyin_counting = 0;
- u8 Luyin_start = 0;
- /*****************放音变量*********************/
- u16 Fangyin_counting = 0;
- u8 Fangyin_start = 0;
- /*****************时间调整*********************/
- int clock_gengxin[7] = {0,1,1};
- int main(void)
- {
- static uint8 key=0;
- static uint8 key1=0;
- static uint8 key2=0;
-
- static uint8 key3=0;
- // static uint8 key4=0;
-
-
-
- uint8 Add1=0,Add2=0,Add3=0,Add4=0,Add5=0,Add6 = 0;
- uint8 ADd1=0;
-
- /*****************录放音变量*********************/
- u32 Stopwatch_count[2];
- u16 Luyin_count[2] = {0,0};
- u16 Fangyin_count[2] = {0,0};
- uint8 i;
- /*****************闹钟变量*********************/
- uint16 Shi = 0,Shi1 = 0,Shi2 = 0,Fen = 0,Fen1 = 0,Fen2 = 0,Miao = 0,Miao1 = 0,Miao2 = 0;
- uint16 Alarm_clock_S1 = 0,Alarm_clock_F1 = 0,Alarm_clock_M1 = 0;
- uint16 Alarm_clock_S2 = 0,Alarm_clock_F2 = 0,Alarm_clock_M2 = 0;
- uint16 Alarm_clock_S3 = 0,Alarm_clock_F3 = 0,Alarm_clock_M3 = 0;
-
- /*****************时间调整变量*********************/
- u32 t = 2000;
-
- Systerm_Init();
-
-
-
- while(1)
- {
-
- BLED_ON; //蓝色指示灯
-
- DHT12_READ(); //读取温湿度
- Ds1302_Readtime(); //读取时间
-
- key = KEY_Scan(); //读取按键值
-
- /*************************************************一界面------------------秒表*********************************************/
- if(key == 1) //一界面------------------秒表
- {
- if(!Add1)
- {
- OLED_Clear(); //先清屏
- Add1 = 1;
- }
- Add2 = 0;
- Add3 = 0;
- Add4 = 0;
- Add5 = 0;
- Add6 = 0;
-
- for(i=10;i<12;i++)
- {
- OLED_P16x16Ch(46+(i-10)*16,0,i);//一界面显示“秒表”
- }
- for(i=14;i<16;i++)
- {
- OLED_P16x8Ch(1+(i-14)*16,3,i);//一界面显示“计时”
- }
- if(KEY2==1)
- {
- Stopwatch_Start = 1;
- }
- else if(KEY3==1)
- {
- Stopwatch_Start = 0;
- }
- else if(WK_UP==1)
- {
- Stopwatch_counting = 0;
- Stopwatch_Start = 0;
- }
-
- Stopwatch_count[1] = Stopwatch_counting/10;
- Stopwatch_count[0] = Stopwatch_counting%10;
-
- OLED_F6x8Str1(84,6,Stopwatch_count[1],4);
- OLED_P6x8Str(108,6,".");
- OLED_F6x8Str1(114,6,Stopwatch_count[0],1);
- }
- /*************************************************二界面------------------录放音*********************************************/
- else if(key == 2) //二界面------------------录放音
- {
- if(!Add2)
- {
- OLED_Clear(); //先清屏
- Add2 = 1;
- }
- Add1 = 0;
- Add3 = 0;
- Add4 = 0;
- Add5 = 0;
- Add6 = 0;
-
- for(i=12;i<15;i++)
- {
- OLED_P16x16Ch(38+(i-12)*16,0,i);//二界面显示“录放音”
- }
-
- OLED_P16x16Ch(5,3,12);//二界面显示“录”
- OLED_P16x16Ch(5+16,3,14);//二界面显示“音”
- OLED_P16x16Ch(5+32,3,23);//二界面显示“:”
-
- OLED_P16x16Ch(5,6,13);//二界面显示“放”
- OLED_P16x16Ch(5+16,6,14);//二界面显示“音”
- OLED_P16x16Ch(5+32,6,23);//二界面显示“:”
- if(Luyin_counting<100)
- {
- OLED_F6x8Str1(104,4,Luyin_count[1],2);
- OLED_P6x8Str(116,4,".");
- OLED_F6x8Str1(122,4,Luyin_count[0],1);
-
- OLED_F6x8Str1(104,7,Fangyin_count[1],2);
- OLED_P6x8Str(116,7,".");
- OLED_F6x8Str1(122,7,Fangyin_count[0],1);
- }
- /*************************************************录音*********************************************/
- if(KEY4 == 1)
- {
-
- if(Luyin_counting>100)
- {
-
- Luyin_start = 0;
- for(i=24;i<29;i++)
- {
- OLED_P16x16Ch(55+(i-24)*16,3,i);//二界面显示“录音超时”
- ADd1 = 1;
- }
- }
- else
- {
- LY_start;
- Luyin_start = 1;
-
- for(i=16;i<18;i++)
- {
- OLED_P16x8Ch(55+(i-16)*16,4,i);//二界面显示“开始”
- }
- Luyin_count[1] = Luyin_counting/10;
- Luyin_count[0] = Luyin_counting%10;
- }
-
- }
- else
- {
- Luyin_counting = 0;
- LY_stop;
- Luyin_start = 0;
- if(ADd1 == 1)
- {
- ADd1 = 0;
- for(i=55;i<128;i++)
- {
- OLED_P6x8Str(i,3," ");
- OLED_P6x8Str(i,4," ");
- }
- }
- for(i=18;i<20;i++)
- {
- OLED_P16x8Ch(55+(i-18)*16,4,i);//二界面显示“结束”
- }
- }
- /*************************************************放音*********************************************/
- if(WK_UP == 1)
- {
- BF_start;
- Fangyin_start = 1;
-
- for(i=16;i<18;i++)
- {
- OLED_P16x8Ch(55+(i-16)*16,7,i);//二界面显示“开始”
- }
- }
- Fangyin_count[1] = Fangyin_counting/10;
- Fangyin_count[0] = Fangyin_counting%10;
- if(Fangyin_counting>Luyin_count[1]*10+Luyin_count[0])
- {
- TBF_stop;
- Fangyin_start = 0;
- Fangyin_counting =0;
- for(i=18;i<20;i++)
- {
- OLED_P16x8Ch(55+(i-18)*16,7,i);//二界面显示“结束”
- }
- }
- }
- /*************************************************三界面------------------闹钟*********************************************/
- else if(key == 3)
- {
- if(!Add3)
- {
- OLED_Clear(); //先清屏
- Add3 = 1;
- }
- Add1 = 0;
- Add2 = 0;
- Add4 = 0;
- Add5 = 0;
- Add6 = 0;
-
- for(i=29;i<31;i++)
- {
- OLED_P16x16Ch(46+(i-29)*16,0,i);//三界面显示“闹钟”
- }
- key1 = KEY_Scan2(); //读取按键值
-
- if(key1 == 1)
- {
- for(i=23;i<26;i++)
- {
- OLED_P16x8Ch(5+(i-23)*16,5,i);//三界面显示“定时二”
- }
- OLED_P16x8Ch(5+3*16,5,29);//三界面显示“:”
- for(i=26;i<29;i++)
- {
- OLED_P16x8Ch(5+(i-26)*16,7,i);//三界面显示“定时三”
- }
- OLED_P16x8Ch(5+3*16,5,29);//三界面显示“:”
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
-
- OLED_P16x8Ch(5+3*16,7,29);//三界面显示“:”
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
- /***************************上面是把上一界面消掉*********************************/
- for(i=20;i<23;i++)
- {
- OLED_P16x8Ch1(5+(i-20)*16,3,i);//三界面显示“定时一”
- }
- OLED_P16x8Ch1(5+3*16,3,29);//三界面显示“:”
- key2 = KEY_Scan3(); //读取按键值
- if(key2 == 1)
- {
- OLED_F6x8Str2(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Shi++;
- if(Shi>24)
- {
- Shi = 0;
- }
- }
- }
- }
- else if(key2 == 2)
- {
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str2(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Fen++;
- if(Fen>60)
- {
- Fen = 0;
- }
- }
- }
- }
- else if(key2 == 3)
- {
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str2(115,3,Miao,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Miao++;
- if(Miao>60)
- {
- Miao = 0;
- }
- }
- }
- }
- else
- {
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
- }
- if(WK_UP == 1)
- {
-
- Alarm_clock_S1 = Shi;
- Alarm_clock_F1 = Fen;
- Alarm_clock_M1 = Miao;
- counting = 0;
- }
- /***************************界面准备完毕,开始变量*********************************/
-
- }
- else if(key1 == 2)
- {
- for(i=26;i<29;i++)
- {
- OLED_P16x8Ch(5+(i-26)*16,7,i);//三界面显示“定时三”
- }
- OLED_P16x8Ch(5+3*16,7,29);//三界面显示“:”
- for(i=20;i<23;i++)
- {
- OLED_P16x8Ch(5+(i-20)*16,3,i);//三界面显示“定时一”
- }
- OLED_P16x8Ch(5+3*16,3,29);//三界面显示“:”
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
-
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
- /***************************上面是把上一界面消掉*********************************/
- for(i=23;i<26;i++)
- {
- OLED_P16x8Ch1(5+(i-23)*16,5,i);//三界面显示“定时二”
- }
- OLED_P16x8Ch1(5+3*16,5,29);//三界面显示“:”
- key2 = KEY_Scan3(); //读取按键值
- if(key2 == 1)
- {
- OLED_F6x8Str2(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Shi1++;
- if(Shi1>23)
- {
- Shi1 = 0;
- }
- }
- }
-
- }
- else if(key2 == 2)
- {
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str2(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Fen1++;
- if(Fen1>60)
- {
- Fen1 = 0;
- }
- }
- }
- }
- else if(key2 == 3)
- {
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str2(115,5,Miao1,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Miao1++;
- if(Miao1>60)
- {
- Miao1 = 0;
- }
- }
- }
- }
- else
- {
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
-
- }
- if(WK_UP == 1)
- {
-
- Alarm_clock_S2 = Shi1;
- Alarm_clock_F2 = Fen1;
- Alarm_clock_M2 = Miao1;
- counting = 0;
- }
- /***************************界面准备完毕,开始变量*********************************/
-
- }
- else if(key1 == 3)
- {
- for(i=20;i<23;i++)
- {
- OLED_P16x8Ch(5+(i-20)*16,3,i);//三界面显示“定时一”
- }
- OLED_P16x8Ch(5+3*16,3,29);//三界面显示“:”
- for(i=23;i<26;i++)
- {
- OLED_P16x8Ch(5+(i-23)*16,5,i);//三界面显示“定时二”
- }
- OLED_P16x8Ch(5+3*16,5,29);//三界面显示“:”
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
-
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
- /***************************上面是把上一界面消掉*********************************/
- for(i=26;i<29;i++)
- {
- OLED_P16x8Ch1(5+(i-26)*16,7,i);//三界面显示“定时三”
- }
- OLED_P16x8Ch1(5+3*16,7,29);//三界面显示“:”
- key2 = KEY_Scan3(); //读取按键值
- if(key2 == 1)
- {
- OLED_F6x8Str2(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Shi2++;
- if(Shi2>23)
- {
- Shi2 = 0;
- }
- }
- }
- }
- else if(key2 == 2)
- {
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str2(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Fen2++;
- if(Fen2>59)
- {
- Fen2 = 0;
- }
- }
- }
- }
- else if(key2 == 3)
- {
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str2(115,7,Miao2,2); //shi
- if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- Miao2++;
- if(Miao2>59)
- {
- Miao2 = 0;
- }
- }
- }
- }
- else
- {
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
-
- }
- if(WK_UP == 1)
- {
-
- Alarm_clock_S2 = Shi2;
- Alarm_clock_F2 = Fen2;
- Alarm_clock_M2 = Miao2;
- counting = 0;
- }
- /***************************界面准备完毕,开始变量*********************************/
-
- }
- else
- {
- /*******************************定时一*******************************/
- for(i=20;i<23;i++)
- {
- OLED_P16x8Ch(5+(i-20)*16,3,i);//三界面显示“定时一”
- }
- OLED_P16x8Ch(5+3*16,3,29);//三界面显示“:”
-
- OLED_F6x8Str1(67,3,Shi,2); //shi
- OLED_P6x8Str(82,3,":");
- OLED_F6x8Str1(91,3,Fen,2); //shi
- OLED_P6x8Str(106,3,":");
- OLED_F6x8Str1(115,3,Miao,2); //shi
-
- /*******************************定时二*******************************/
- for(i=23;i<26;i++)
- {
- OLED_P16x8Ch(5+(i-23)*16,5,i);//三界面显示“定时二”
- }
- OLED_P16x8Ch(5+3*16,5,29);//三界面显示“:”
-
- OLED_F6x8Str1(67,5,Shi1,2); //shi
- OLED_P6x8Str(82,5,":");
- OLED_F6x8Str1(91,5,Fen1,2); //shi
- OLED_P6x8Str(106,5,":");
- OLED_F6x8Str1(115,5,Miao1,2); //shi
-
- /*******************************定时三*******************************/
- for(i=26;i<29;i++)
- {
- OLED_P16x8Ch(5+(i-26)*16,7,i);//三界面显示“定时三”
- }
- OLED_P16x8Ch(5+3*16,7,29);//三界面显示“:”
-
- OLED_F6x8Str1(67,7,Shi2,2); //shi
- OLED_P6x8Str(82,7,":");
- OLED_F6x8Str1(91,7,Fen2,2); //shi
- OLED_P6x8Str(106,7,":");
- OLED_F6x8Str1(115,7,Miao2,2); //shi
-
- /*******************************定时初始界面结束*******************************/
- }
-
- }
- /*************************************************四界面------------------时间调整*********************************************/
- else if(key == 4)
- {
- if(!Add4)
- {
- OLED_Clear(); //先清屏
- Add4 = 1;
- }
- Add1 = 0;
- Add2 = 0;
- Add3 = 0;
- Add5 = 0;
- Add6 = 0;
-
- for(i=31;i<35;i++)
- {
- OLED_P16x16Ch(28+(i-31)*16,0,i);//三界面显示“闹钟”
- }
-
- key3 = KEY_Scan21();
-
-
- if(key3 == 1)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str2(96,2,t+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[0]++;
- if(clock_gengxin[0]>99)
- {
- clock_gengxin[0] = 0;
- t+=100;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[0]--;
- if(clock_gengxin[0]<0)
- {
- clock_gengxin[0] = 99;
- t-=100;
- }
- }
- }
-
- }
- else if(key3 == 2)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str2(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[1]++;
- if(clock_gengxin[1]>12)
- {
- clock_gengxin[1] = 1;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[1]--;
- if(clock_gengxin[1]<1)
- {
- clock_gengxin[1] = 12;
- }
- }
- }
- }
- else if(key3 == 3)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str2(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[2]++;
- if(clock_gengxin[2]>31)
- {
- clock_gengxin[2] = 1;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[2]--;
- if(clock_gengxin[2]<1)
- {
- clock_gengxin[2] = 31;
- }
- }
- }
-
- }
- else if(key3 == 4)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str2(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[3]++;
- if(clock_gengxin[3]>23)
- {
- clock_gengxin[3] = 0;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[3]--;
- if(clock_gengxin[3]<1)
- {
- clock_gengxin[3] = 24;
- }
- }
- }
- }
- else if(key3 == 5)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str2(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[4]++;
- if(clock_gengxin[4]>59)
- {
- clock_gengxin[4] = 0;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[4]--;
- if(clock_gengxin[4]<0)
- {
- clock_gengxin[4] = 59;
- }
- }
- }
- }
- else if(key3 == 6)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
-
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str2(108,7,clock_gengxin[5],2); //shi
- if(KEY3 == 1)
- {
- delay_ms(100);
- if(KEY3 == 1)
- {
- clock_gengxin[5]++;
- if(clock_gengxin[5]>59)
- {
- clock_gengxin[5] = 0;
- }
- }
- }
- else if(KEY4 == 1)
- {
- delay_ms(100);
- if(KEY4 == 1)
- {
- clock_gengxin[5]--;
- if(clock_gengxin[5]<0)
- {
- clock_gengxin[5] = 59;
- }
- }
- }
- }
- else
- {
-
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- }
- if(WK_UP == 1)
- {
- delay_ms(100);
- if(WK_UP == 1)
- {
- OLED_P16x8Ch(5,3,30);//四界面显示“时”
- OLED_P16x8Ch(5,6,31);//四界面显示“间”
-
- OLED_P16x8Ch(40,2,0);//四界面显示“年”
- OLED_P16x8Ch(61,2,29);//四界面显示“:”
- OLED_P16x8Ch(40,3,1);//四界面显示“月”
- OLED_P16x8Ch(61,3,29);//四界面显示“:”
- OLED_P16x8Ch(40,4,2);//四界面显示“日”
- OLED_P16x8Ch(61,4,29);//四界面显示“:”
- OLED_P16x8Ch(40,5,3);//四界面显示“时”
- OLED_P16x8Ch(61,5,29);//四界面显示“:”
- OLED_P16x8Ch(40,6,4);//四界面显示“分”
- OLED_P16x8Ch(61,6,29);//四界面显示“:”
- OLED_P16x8Ch(40,7,5);//四界面显示“秒”
- OLED_P16x8Ch(61,7,29);//四界面显示“:”
- OLED_F6x8Str1(96,2,2000+clock_gengxin[0],4); //shi
- OLED_F6x8Str1(108,3,clock_gengxin[1],2); //shi
- OLED_F6x8Str1(108,4,clock_gengxin[2],2); //shi
- OLED_F6x8Str1(108,5,clock_gengxin[3],2); //shi
- OLED_F6x8Str1(108,6,clock_gengxin[4],2); //shi
- OLED_F6x8Str1(108,7,clock_gengxin[5],2); //shi
- coun2 = 0;
- Ds1302_Write_Time_All1();
- }
- }
-
- }
- /*************************************************五界面------------------操作提示*********************************************/
- else if(key == 5)
- {
- if(!Add5)
- {
- OLED_Clear(); //先清屏
- Add5 = 1;
- }
- Add1 = 0;
- Add2 = 0;
- Add3 = 0;
- Add4 = 0;
- Add6 = 0;
-
- for(i=35;i<39;i++)
- {
- OLED_P16x16Ch(30+(i-35)*16,1,i);//主界面显示“演示结束”
- }
- for(i=39;i<44;i++)
- {
- OLED_P16x16Ch(28+(i-39)*16,4,i);//主界面显示“谢谢师傅!”
- }
- }
- else //主界面---------------时间、温湿度
- {
- if(!Add6)
- {
- OLED_Clear(); //先清屏
- Add6 = 1;
- }
- Add1 = 0;
- Add2 = 0;
- Add3 = 0;
- Add4 = 0;
- Add5 = 0;
-
- for(i=0;i<7;i++)
- {
- OLED_P16x16Ch(8+i*16,0,i);//主界面显示“多功能电子时钟”
- }
-
- for(i=0;i<3;i++)
- {
- OLED_P16x8Ch(1+i*16,3,i);//主界面显示“年月日”
- }
- for(i=3;i<6;i++)
- {
- OLED_P16x8Ch(1+(i-3)*16,4,i);//主界面显示“时分秒”
- }
- OLED_P6x8Str(1,6,"Temperature:");
- OLED_P6x8Str(1,7,"Humidity:");
-
-
- clock_NYR();
- clock_SFM();
- Temperature_and_humidity();
- }
- if(ascii_time[2] == Alarm_clock_S1 && ascii_time[1] == Alarm_clock_F1 && ascii_time[0] == Alarm_clock_M1 ) //闹钟
- {
- BEEP_ON;
- }
- else if(ascii_time[2] == Alarm_clock_S2 && ascii_time[1] == Alarm_clock_F2 && ascii_time[0] == Alarm_clock_M2)
- {
- BEEP_ON;
- }
- else if(ascii_time[2] == Alarm_clock_S3 && ascii_time[1] == Alarm_clock_F3 && ascii_time[0] == Alarm_clock_M3)
- {
- BEEP_ON;
- }
- else
- {
-
- if(WK_UP == 1)
- {
- BEEP_OFF;
- }
- }
-
-
- /***********************************程序结束**************************************/
- }
-
- }
复制代码
所有资料51hei提供下载:
源程序.7z
(210.03 KB, 下载次数: 200)
|