找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4007|回复: 0
收起左侧

红外按键可调遥控万年历单片机课程设计 带仿真 源码 已做出实物

[复制链接]
ID:194350 发表于 2017-4-27 21:10 | 显示全部楼层 |阅读模式
给大家分享一个单片机课程设计,已经调试成功而且做出实物了如下图
红外遥控万年历的实物图:
1.jpg 2.jpg
     设计要求:
      1 具备在液晶上显示年、月、日、星期、时、分、秒的功能;
   2 具备年、月、日、时、分、秒校准功能(星期可以自动调整,用函数算出来)        
   3 具有与即时时间同步的功能红外按键调时;
   4 具有显示温度的功能,可设置闹钟;

红外遥控万年历课程设计proteus仿真图(51hei附件中可下载proteus仿真工程文件):
0.png

课程设计ppt文档:
0.png

¤难度系数:100

¤设计要求:

用LCD1602显示,红外遥控器输入,扬声器报警,DS18B20测量温度,DS1302计时

设计程序实现如下功能

   - 实时显示当前日期时间温度信息

   - 用遥控器设置日期时间和闹钟

¤需要器件:

51hei单片机开发板

LCD1602,红外遥控器,DS18B20

完成硬件设计,焊接,调试
编写软件,完成题目要求的功能
实物演示,答辩验收
完成设计报告
周一:12讲解题目,34查阅资料,56定题并给出设计方案,元件清单。
周二:上午检查硬件电路,领取元器件,下午完成硬件电路制作。
周三:程序设计,调试。
周四:程序设计,调试。
周五:上午完成设计报告,下午提交作品和设计报告。(实物、照片、录像)

万年历的单片机源程序:
  1. /*
  2. *************************************************************************************************************
  3. *                                                                                                                                                                        clock.c
  4. * 说                明:时钟
  5. * 作    者:Jonelec
  6. * 首发:51黑电子论坛
  7. *                 修改者:                                修改内容:                                修改日期:                               
  8. *           Jonelec       第一版          2017-04-20
  9. *                       Copyright(c) 2015-2025 skytech.org Inc.
  10. *************************************************************************************************************
  11. */
  12. #include "clock.h"
  13. #include "display.h"

  14. /* 时钟计时闪烁设置 */
  15. bit FlashTimeFlag = 0;           /*闪烁冒号*/
  16. #define FlashTimeTMR_ID   0      /*冒号闪烁定时器ID*/
  17. #define FlashTimeTIME     1000   /*冒号闪烁定时时间*/
  18. /* 切换界面参数设置*/
  19. bit SwitchDisplayFlag = 0;
  20. #define SwitchDispTMR_ID  1     /*切换显示方式定时器ID*/
  21. #define SwitchDispTIME    3000  /*切换显示方式定时时间*/

  22. extern float idata CurTemp; /*获取温度值,3s采集一次*/

  23. uint8_t idata DispSetIndex = 0; /*光标索引*/
  24. uint8_t idata AlarmSetIndex = 0;

  25. AlarmSetInitTypeDef RingTime,SetRing;
  26. RealTimeInitTypeDef CurTime,SetTime;

  27. void DispNormalClock(void);

  28. /*
  29. *************************************************************************************************************
  30. *                                  main()
  31. *函数功能:主函数,执行程序入口
  32. *函数参数:无
  33. *返 回 值:无
  34. *************************************************************************************************************
  35. */
  36. int main(void)
  37. {       
  38.         bsp_Init();
  39.           RingTime = SetRing;
  40.         while(1)
  41.         {
  42.                 DispNormalClock();
  43.         }
  44. }
  45. /*
  46. *************************************************************************************************************
  47. *                                  RefreshTime()
  48. *函数功能:时间显示刷新
  49. *函数参数:_ucFlag 【为0时正常显示时间,为1时显示闹铃时间,不影响日期温度等显示】
  50. *返 回 值:无
  51. *************************************************************************************************************
  52. */
  53. void RefreshTime(uint8_t _ucFlag)
  54. {       
  55.         if(_ucFlag != 1) /*正常显示时间*/
  56.         {
  57.                 bsp_GetTime(&CurTime);
  58.        
  59.                 if(bsp_CheckTimer(FlashTimeTMR_ID))
  60.                 {
  61.                         FlashTimeFlag = !FlashTimeFlag;  /*冒号闪烁*/
  62.                 }
  63.                 Lcd1602_DispNum(1,0,CurTime.Hour>>4);
  64.                 Lcd1602_DispNum(1,1,CurTime.Hour&0xF);
  65.                 Lcd1602_DispNum(1,3,CurTime.Minute>>4);
  66.                 Lcd1602_DispNum(1,4,CurTime.Minute&0xF);
  67.                 Lcd1602_DispNum(1,6,CurTime.Second>>4);
  68.                 Lcd1602_DispNum(1,7,CurTime.Second&0xF);
  69.                
  70.                 Lcd1602_DispStr(1,8,"  ");
  71.                 if(FlashTimeFlag)
  72.                 {
  73.                         Lcd1602_DispChar(1,2,':');
  74.                         Lcd1602_DispChar(1,5,':');
  75.                 }
  76.                 else
  77.                 {
  78.                         Lcd1602_DispChar(1,2,' ');
  79.                         Lcd1602_DispChar(1,5,' ');
  80.                 }
  81.         }
  82.         else  /*显示闹铃时间*/
  83.         {
  84.                 if(RingTime.OpenFlag != 1)
  85.                 {
  86.                         Lcd1602_DispStr(1,0,"OFF");
  87.                 }
  88.                 else
  89.                 {
  90.                         Lcd1602_DispStr(1,0,"ON ");
  91.                 }
  92.                 Lcd1602_DispChar(1,3,' ');
  93.                 Lcd1602_DispNum(1,4,RingTime.Hour>>4);
  94.                 Lcd1602_DispNum(1,5,RingTime.Hour&0xF);
  95.                 Lcd1602_DispChar(1,6,':');
  96.                 Lcd1602_DispNum(1,7,RingTime.Minute>>4);
  97.                 Lcd1602_DispNum(1,8,RingTime.Minute&0xF);
  98.                 Lcd1602_DispChar(1,9,' ');
  99.         }
  100. }
  101. /*
  102. *************************************************************************************************************
  103. *                                  RefreshDate()
  104. *函数功能:日期显示刷新
  105. *函数参数:_ucFlag 【为0时如果日期有变化则会刷新,为1时则立即刷新】
  106. *返 回 值:无
  107. *************************************************************************************************************
  108. */
  109. void RefreshDate(uint8_t _ucFlag)
  110. {
  111.         uint8_t pdata week;
  112.         static uint8_t day_backup = 0;
  113.        
  114.         week = bsp_CulateDate(CurTime); /*计算星期*/
  115.        
  116.         if(day_backup != CurTime.Day || _ucFlag != 0)
  117.         {
  118.                 Lcd1602_DispNum(0,0,CurTime.YearH>>4);
  119.                 Lcd1602_DispNum(0,1,CurTime.YearH&0xF);
  120.                 Lcd1602_DispNum(0,2,CurTime.YearL>>4);
  121.                 Lcd1602_DispNum(0,3,CurTime.YearL&0xF);
  122.                 Lcd1602_DispChar(0,4,'-');
  123.                 Lcd1602_DispNum(0,5,CurTime.Month>>4);
  124.                 Lcd1602_DispNum(0,6,CurTime.Month&0xF);
  125.                 Lcd1602_DispChar(0,7,'-');
  126.                 Lcd1602_DispNum(0,8,CurTime.Day>>4);
  127.                 Lcd1602_DispNum(0,9,CurTime.Day&0xF);
  128.                        
  129.                 Lcd1602_DispStr(0,12,"W:");
  130.                 Lcd1602_DispNum(0,14,week>>4);
  131.                 Lcd1602_DispNum(0,15,week&0xF);
  132.                 day_backup = CurTime.Day;
  133.         }
  134. }
  135. /*
  136. *************************************************************************************************************
  137. *                                  RefreshTemp()
  138. *函数功能:温度显示刷新
  139. *函数参数:_ucFlag 【为0时如果温度有变化则会刷新,为1时则立即刷新】
  140. *返 回 值:无
  141. *************************************************************************************************************
  142. */
  143. void RefreshTemp(uint8_t _ucFlag)
  144. {
  145.         int16_t pdata temp;
  146.         static int16_t tmp_backup = 0;
  147.        
  148.         temp = CurTemp*10;
  149.         temp >>= 4; /*保留整数部分*/
  150.        
  151.         if((tmp_backup != temp) || (_ucFlag != 0))
  152.         {
  153.                 Lcd1602_DispStr(1,10,"T:");
  154.                 if(temp < 0)
  155.                 {
  156.                         Lcd1602_DispChar(1,12,'-');
  157.                 }
  158.                 else
  159.                 {
  160.                         Lcd1602_DispChar(1,12,'+');
  161.                 }
  162.                 Lcd1602_DispNum(1,13,temp/10);
  163.                 Lcd1602_DispNum(1,14,temp%10);
  164.                 Lcd1602_WriteGram();
  165.                 Lcd1602_DispChar(1,15,0x00);
  166.                 tmp_backup = temp;
  167.         }
  168. }
  169. /*
  170. *************************************************************************************************************
  171. *                                  DispNormalClock()
  172. *函数功能:正常显示时钟
  173. *函数参数:无
  174. *返 回 值:无
  175. *************************************************************************************************************
  176. */
  177. void DispNormalClock(void)
  178. {       
  179.         uint8_t  ucKeyCode;
  180.                                                   
  181.         Lcd1602_ClearScreen();     /*清屏*/
  182.         Lcd1602_OpenCursor(0);     /*关闭光标闪烁*/
  183.         RefreshDate(1);            /*立即更新日期和温度*/
  184.         RefreshTemp(1);
  185.         bsp_StartAutoTimer(FlashTimeTMR_ID,FlashTimeTIME);  /*秒闪烁定时器*/
  186.         bsp_StartAutoTimer(SwitchDispTMR_ID,SwitchDispTIME);/*切换显示定时器*/
  187.         while(1)
  188.         {
  189.                 ucKeyCode = bsp_GetIRKey();
  190.                
  191.                 if(bsp_CheckTimer(SwitchDispTMR_ID))
  192.           {
  193.                   SwitchDisplayFlag = !SwitchDisplayFlag;
  194.           }
  195.                  RefreshTime(SwitchDisplayFlag);/*时间显示,即刻刷新,每秒更新*/
  196.                  RefreshDate(0);/*年份及日期显示,只有当日期变化的时候才会刷新*/
  197.                  RefreshTemp(0);/*温度显示,只有当温度变化的时候才会刷新*/
  198.                
  199.                 if(ucKeyCode != IR_KEY_NONE)
  200.                 {
  201.                         switch(ucKeyCode)
  202.                         {        case IR_KEY_POWER:
  203.                              {
  204.                                         RingTime.OpenFlag = !RingTime.OpenFlag;
  205.                                 }break;
  206.                                 case IR_KEY_MENU:
  207.                                 {
  208.                                         bsp_StopTimer(SwitchDispTMR_ID);
  209.                                         bsp_StopTimer(FlashTimeTMR_ID);
  210.                                         LCD_ChangeMenu();
  211.                                 }break;
  212.                                 default :break;
  213.                         }                       
  214.                 }
  215.         }
  216. }
  217. /*
  218. *************************************************************************************************************
  219. *                                  ShiftRightCursor()
  220. *函数功能:光标索引右移
  221. *函数参数:_ucFlag : 0【设置闹钟】 1【设置时钟】
  222. *返 回 值:无
  223. *************************************************************************************************************
  224. */
  225. void ShiftRightCursor(uint8_t _ucFlag)
  226. {
  227.         if(_ucFlag != 0) //设置时钟
  228.         {
  229.                 switch(DispSetIndex)
  230.                 {
  231.                         case 0: DispSetIndex = 1;Lcd1602_SetPos(0,1);break;
  232.                         case 1: DispSetIndex = 2;Lcd1602_SetPos(0,2);break;
  233.                         case 2: DispSetIndex = 3;Lcd1602_SetPos(0,3);break;
  234.                         case 3: DispSetIndex = 4;Lcd1602_SetPos(0,5);break;
  235.                         case 4: DispSetIndex = 5;Lcd1602_SetPos(0,6);break;
  236.                         case 5: DispSetIndex = 6;Lcd1602_SetPos(0,8);break;
  237.                         case 6: DispSetIndex = 7;Lcd1602_SetPos(0,9);break;
  238.                         case 7: DispSetIndex = 8;Lcd1602_SetPos(1,0);break;
  239.                     case 8:  DispSetIndex = 9; Lcd1602_SetPos(1,1);break;
  240.                         case 9:  DispSetIndex = 10;Lcd1602_SetPos(1,3);break;
  241.                         case 10: DispSetIndex = 11;Lcd1602_SetPos(1,4);break;
  242.                         case 11: DispSetIndex = 12;Lcd1602_SetPos(1,6);break;
  243.                         case 12: DispSetIndex = 13;Lcd1602_SetPos(1,7);break;
  244.                         default :DispSetIndex = 0;Lcd1602_SetPos(0,0);break;
  245.                 }
  246.         }
  247.         else  /*设置闹钟*/
  248.         {
  249.                 switch(AlarmSetIndex)
  250.                 {
  251.                         case 0:AlarmSetIndex = 1;Lcd1602_SetPos(1,1);break;
  252.                         case 1:AlarmSetIndex = 2;Lcd1602_SetPos(1,3);break;
  253.                         case 2:AlarmSetIndex = 3;Lcd1602_SetPos(1,4);break;
  254.                         case 3:AlarmSetIndex = 4;Lcd1602_SetPos(1,10);break;
  255.                         default :AlarmSetIndex = 0;Lcd1602_SetPos(1,0);break;
  256.                 }
  257.         }
  258. }
  259. /*
  260. *************************************************************************************************************
  261. *                                  ShiftLeftCursor()
  262. *函数功能:光标索引左移
  263. *函数参数:_ucFlag : 0【设置闹钟】 1【设置时钟】
  264. *返 回 值:无
  265. *************************************************************************************************************
  266. */
  267. void ShiftLeftCursor(uint8_t _ucFlag)
  268. {
  269.         if(_ucFlag != 0) //设置时钟
  270.         {
  271.                 switch(DispSetIndex)
  272.                 {
  273.                         case 0: DispSetIndex = 13;Lcd1602_SetPos(1,7);break;
  274.                        
  275.                         case 1: DispSetIndex = 0;Lcd1602_SetPos(0,0);break;
  276.                         case 2: DispSetIndex = 1;Lcd1602_SetPos(0,1);break;
  277.                         case 3: DispSetIndex = 2;Lcd1602_SetPos(0,2);break;
  278.                         case 4: DispSetIndex = 3;Lcd1602_SetPos(0,3);break;
  279.                        
  280.                         case 5: DispSetIndex = 4;Lcd1602_SetPos(0,5);break;
  281.                         case 6: DispSetIndex = 5;Lcd1602_SetPos(0,6);break;
  282.                        
  283.                         case 7: DispSetIndex = 6;Lcd1602_SetPos(0,8);break;
  284.                     case 8: DispSetIndex = 7;Lcd1602_SetPos(0,9);break;
  285.                        
  286.                         case 9:  DispSetIndex = 8;Lcd1602_SetPos(1,0);break;
  287.                         case 10: DispSetIndex = 9;Lcd1602_SetPos(1,1);break;
  288.                        
  289.                         case 11: DispSetIndex = 10;Lcd1602_SetPos(1,3);break;
  290.                         case 12: DispSetIndex = 11;Lcd1602_SetPos(1,4);break;
  291.                         default :DispSetIndex = 12;Lcd1602_SetPos(1,6);break;
  292.                 }
  293.         }
  294.         else
  295.         {
  296.                 switch(AlarmSetIndex)
  297.                 {
  298.                         case 0:AlarmSetIndex = 4;Lcd1602_SetPos(1,10);break;
  299.                         case 1:AlarmSetIndex = 0;Lcd1602_SetPos(1,0);break;
  300.                         case 2:AlarmSetIndex = 1;Lcd1602_SetPos(1,1);break;
  301.                         case 3:AlarmSetIndex = 2;Lcd1602_SetPos(1,3);break;
  302.                         default :AlarmSetIndex = 3;Lcd1602_SetPos(1,4);break;
  303.                 }
  304.         }
  305. }
  306. /*
  307. *************************************************************************************************************
  308. *                                  InputSetNumber()
  309. *函数功能:将输入数字进行判断赋值
  310. *函数参数:_ucFlag : 0【设置闹钟】 1【设置时钟】
  311. *返 回 值:无
  312. *************************************************************************************************************
  313. */
  314. void InputSetNumber(uint8_t _ucFlag,uint8_t _ucNum)
  315. {
  316.         if(_ucFlag != 0)
  317.         {
  318.                 switch(DispSetIndex)
  319.                 {
  320.                         case 0: /*设置年份的最高位*/
  321.                         {
  322.                                 SetTime.YearH = (SetTime.YearH&0x0F)|(_ucNum<<4);
  323.                                 Lcd1602_DispNum(0,0,_ucNum);
  324.                         }break;
  325.                         case 1:
  326.                         {
  327.                                 SetTime.YearH = (SetTime.YearH&0xF0)|_ucNum; /*年份第三位数字*/
  328.                                 Lcd1602_DispNum(0,1,_ucNum);
  329.                         }break;
  330.                         case 2:
  331.                         {
  332.                                 SetTime.YearL = (SetTime.YearL&0x0F)|(_ucNum<<4); /*年份第二位数字*/
  333.                                 Lcd1602_DispNum(0,2,_ucNum);
  334.                         }break;
  335.                         case 3:
  336.                         {
  337.                                 SetTime.YearL = (SetTime.YearL&0xF0)|_ucNum;     /*年份第一位数字*/
  338.                                 Lcd1602_DispNum(0,3,_ucNum);
  339.                         }break;
  340.                         case 4:
  341.                         {       
  342.                                 if(_ucNum > 1)
  343.                                 {
  344.                                         Lcd1602_DispChar(0,5,'E');                    /*月份输入有误*/
  345.                                 }       
  346.                                 else
  347.                                 {
  348.                                         SetTime.Month = (SetTime.Month&0x0F)|(_ucNum<<4); /*设置月份*/
  349.                                         Lcd1602_DispNum(0,5,_ucNum);
  350.                                 }
  351.                                        
  352.                         }break;
  353.                         case 5:
  354.                         {
  355.                                 if((SetTime.Month>>4) == 1)
  356.                                 {
  357.                                         if(_ucNum > 2)
  358.                                         {
  359.                                                 Lcd1602_DispChar(0,6,'E');
  360.                                         }
  361.                                         else
  362.                                         {
  363.                                                 SetTime.Month = (SetTime.Month&0xF0)|_ucNum;
  364.                                     Lcd1602_DispNum(0,6,_ucNum);
  365.                                         }
  366.                                 }
  367.                                 else
  368.                                 {
  369.                                         SetTime.Month = (SetTime.Month&0xF0)|_ucNum;
  370.                                   Lcd1602_DispNum(0,6,_ucNum);
  371.                                 }
  372.                         }
  373.                         case 6:  /*设置 天数*/         
  374.                         {
  375.                                 if(_ucNum > 3)
  376.                                 {
  377.                                         Lcd1602_DispChar(0,8,'E');
  378.                                 }
  379.                                 else
  380.                                 {
  381.                                         SetTime.Day   = (SetTime.Day&0x0F)|(_ucNum<<4);
  382.                                         Lcd1602_DispNum(0,8,_ucNum);
  383.                                 }
  384.                         }break;
  385.                         case 7:
  386.                         {
  387.                                 if((SetTime.Day>>4)==3)  /*判断是否为3,最多只有31天*/
  388.                                 {
  389.                                         if(_ucNum > 1)
  390.                                         {
  391.                                                 Lcd1602_DispChar(0,9,'E');
  392.                                         }
  393.                                         else
  394.                                         {
  395.                                                 SetTime.Day = (SetTime.Day&0xF0)|_ucNum;
  396.                                                 Lcd1602_DispNum(0,9,_ucNum);
  397.                                         }
  398.                                 }
  399.                                 else
  400.                                 {
  401.                                         SetTime.Day = (SetTime.Day&0xF0)|_ucNum;
  402.                                         Lcd1602_DispNum(0,9,_ucNum);
  403.                                 }
  404.                         }break;
  405.                         case 8:  /*设置小时*/
  406.                         {
  407.                                 if(_ucNum > 2)
  408.                                 {
  409.                                         Lcd1602_DispChar(1,0,'E');
  410.                                 }
  411.                                 else
  412.                                 {
  413.                                         SetTime.Hour = (SetTime.Hour&0x0F)|(_ucNum<<4);
  414.                                         Lcd1602_DispNum(1,0,_ucNum);
  415.                                 }
  416.                         }break;
  417.                         case 9:
  418.                         {
  419.                                 if((SetTime.Hour>>4) == 2)
  420.                                 {
  421.                                         if(_ucNum > 3)
  422.                                         {
  423.                                                 Lcd1602_DispChar(1,1,'E');
  424.                                         }
  425.                                         else
  426.                                         {
  427.                                                 SetTime.Hour = (SetTime.Hour&0xF0)|_ucNum;
  428.                                     Lcd1602_DispNum(1,1,_ucNum);
  429.                                         }
  430.                                 }
  431.                                 else
  432.                                 {
  433.                                         SetTime.Hour = (SetTime.Hour&0xF0)|_ucNum;
  434.                                   Lcd1602_DispNum(1,1,_ucNum);
  435.                                 }
  436.                         }break;
  437.                         case 10: /*设置分钟*/
  438.                         {
  439.                                 if(_ucNum > 5)
  440.                                 {
  441.                                         Lcd1602_DispChar(1,3,'E');
  442.                                 }
  443.                                 else
  444.                                 {
  445.                                         SetTime.Minute = (SetTime.Minute&0x0F)|(_ucNum<<4);
  446.                                         Lcd1602_DispNum(1,3,_ucNum);
  447.                                 }
  448.                         }break;
  449.                         case 11:
  450.                         {
  451.                                 SetTime.Minute = (SetTime.Minute&0xF0)|_ucNum;
  452.                                 Lcd1602_DispNum(1,4,_ucNum);
  453.                         }break;
  454.                         case 12: /*设置秒钟*/
  455.                         {
  456.                                 if(_ucNum > 5)
  457.                                 {
  458.                                         Lcd1602_DispChar(1,6,'E');
  459.                                 }
  460.                                 else
  461.                                 {
  462.                                         SetTime.Second = (SetTime.Second&0x0F)|(_ucNum<<4);
  463.                                         Lcd1602_DispNum(1,6,_ucNum);
  464.                                 }
  465.                         }break;
  466.                         default :
  467.                         {
  468.                                 SetTime.Second = (SetTime.Second&0xF0)|_ucNum;
  469.                                 Lcd1602_DispNum(1,7,_ucNum);
  470.                         }break;
  471.                 }
  472.                 ShiftRightCursor(1);
  473.         }       
  474.   else  /*设置闹钟*/
  475.         {
  476.                 switch(AlarmSetIndex)
  477.                 {
  478.                         case 0:
  479.                         {
  480.                                 if(_ucNum > 2)
  481.                                 {
  482.                                         Lcd1602_DispChar(1,0,'E');
  483.                                 }
  484.                                 else
  485.                                 {
  486.                                         SetRing.Hour = (SetRing.Hour&0x0F)|(_ucNum<<4);
  487.                                         Lcd1602_DispNum(1,0,_ucNum);
  488.                                 }
  489.                         }break;
  490.                         case 1:
  491.                         {
  492.                                 if((SetRing.Hour>>4) == 2)
  493.                                 {
  494.                                         if(_ucNum >3)
  495.                                         {
  496.                                                 Lcd1602_DispChar(1,1,'E');
  497.                                         }
  498.                                         else
  499.                                         {
  500.                                                 SetRing.Hour = (SetRing.Hour&0xF0)|_ucNum;
  501.                                                 Lcd1602_DispNum(1,1,_ucNum);
  502.                                         }
  503.                                 }
  504.                                 else
  505.                                 {
  506.                                         SetRing.Hour = (SetRing.Hour&0xF0)|_ucNum;
  507.                                         Lcd1602_DispNum(1,1,_ucNum);
  508.                                 }       
  509.                         }break;
  510.                         case 2:
  511.                         {
  512.                                 if(_ucNum > 5)
  513.                                 {
  514.                                         Lcd1602_DispChar(1,3,'E');
  515.                                 }
  516.                                 else
  517.                                 {
  518.                                         SetRing.Minute = (SetRing.Minute&0x0F)|(_ucNum<<4);
  519.                                         Lcd1602_DispNum(1,3,_ucNum);
  520.                                 }
  521.                         }break;
  522.                         case 3:
  523.                         {
  524.                                 SetRing.Minute = (SetRing.Minute&0xF0)|_ucNum;
  525.                                 Lcd1602_DispNum(1,4,_ucNum);
  526.                         }break;
  527.                         default :
  528.                         {
  529.                                 if(_ucNum == IR_KEY_POWER) /*按下开关按键*/
  530.                                 {
  531.                                         SetRing.OpenFlag = !SetRing.OpenFlag;
  532.                                        
  533.                                         if(SetRing.OpenFlag != 0) /*开启闹钟*/
  534.                                                 Lcd1602_DispStr(1,10,"ON ");
  535.                                         else
  536.                                                 Lcd1602_DispStr(1,10,"OFF");
  537.                                 }
  538.                         }break;
  539.                 }
  540.                 ShiftRightCursor(0); /*光标自加*/
  541.         }               
  542. }
  543. /*
  544. *************************************************************************************************************
  545. *                                  DisplaySetTime()
  546. *函数功能:将当前的时间加载到设置菜单当中
  547. *函数参数:无
  548. *返 回 值:无
  549. *************************************************************************************************************
  550. */
  551. void DisplaySetTime(void)
  552. {
  553.         bsp_GetTime(&CurTime);
  554.        
  555.         SetTime = CurTime ;
  556.        
  557.         Lcd1602_DispNum(1,0,CurTime.Hour>>4);
  558.         Lcd1602_DispNum(1,1,CurTime.Hour&0xF);
  559.         Lcd1602_DispNum(1,3,CurTime.Minute>>4);
  560.         Lcd1602_DispNum(1,4,CurTime.Minute&0xF);
  561.         Lcd1602_DispNum(1,6,CurTime.Second>>4);
  562.         Lcd1602_DispNum(1,7,CurTime.Second&0xF);
  563.         Lcd1602_DispChar(1,2,':');
  564.         Lcd1602_DispChar(1,5,':');
  565.        
  566.         Lcd1602_DispNum(0,0,CurTime.YearH>>4);
  567.         Lcd1602_DispNum(0,1,CurTime.YearH&0xF);
  568.         Lcd1602_DispNum(0,2,CurTime.YearL>>4);
  569.         Lcd1602_DispNum(0,3,CurTime.YearL&0xF);
  570.         Lcd1602_DispChar(0,4,'-');
  571.         Lcd1602_DispNum(0,5,CurTime.Month>>4);
  572.         Lcd1602_DispNum(0,6,CurTime.Month&0xF);
  573.         Lcd1602_DispChar(0,7,'-');
  574.         Lcd1602_DispNum(0,8,CurTime.Day>>4);
  575.         Lcd1602_DispNum(0,9,CurTime.Day&0xF);
  576. }
  577. /*
  578. *************************************************************************************************************
  579. *                                  SetClockTime()
  580. *函数功能:设置时间
  581. *函数参数:无
  582. *返 回 值:无
  583. *************************************************************************************************************
  584. */
  585. void SetClockTime(void)
  586. {
  587.         uint8_t pdata ucKeyCode;
  588.        
  589.         Lcd1602_ClearScreen();
  590.        
  591.   DisplaySetTime();       
  592.        
  593.         Lcd1602_SetPos(0,0);
  594.         Lcd1602_OpenCursor(1);
  595.                
  596.         while(1)
  597.         {
  598.                 ucKeyCode = bsp_GetIRKey();
  599.                
  600.                 if(ucKeyCode != IR_KEY_NONE)
  601.                 {
  602.                         switch(ucKeyCode)
  603.                         {
  604.                                 case IR_KEY_LEFT : ShiftLeftCursor(1);break;
  605.                                 case IR_KEY_RIGHT: ShiftRightCursor(1);break;
  606.                                 case IR_KEY_0:     InputSetNumber(1,0);break;
  607.                                 case IR_KEY_1:     InputSetNumber(1,1);break;
  608.                                 case IR_KEY_2:     InputSetNumber(1,2);break;
  609.                                 case IR_KEY_3:     InputSetNumber(1,3);break;
  610.                                 case IR_KEY_4:     InputSetNumber(1,4);break;
  611.                                 case IR_KEY_5:     InputSetNumber(1,5);break;
  612.                                 case IR_KEY_6:     InputSetNumber(1,6);break;
  613.                                 case IR_KEY_7:     InputSetNumber(1,7);break;
  614.                                 case IR_KEY_8:     InputSetNumber(1,8);break;
  615.                                 case IR_KEY_9:     InputSetNumber(1,9);break;
  616.                                 case IR_KEY_RETURN :
  617.                                 {
  618.                                         DispSetIndex = 0;
  619.                                         LCD_ChangeMenu();
  620.                                 }break;
  621.                                 case IR_KEY_OK  :
  622.                                 {
  623.                                         CurTime = SetTime;
  624.                                         bsp_SetTime(&CurTime);
  625.                                         DispNormalClock();
  626.                                 }break;
  627.                                 default : break;
  628.                         }
  629.                 }
  630.         }
  631. }
  632. /*
  633. *************************************************************************************************************
  634. *                                  SetClockTime()
  635. *函数功能:设置闹钟


  636. …………限于本文篇幅 余下代码请从51电子黑下载附件…………
复制代码


0.png
下载:
基于单片机的多功能遥控万年历设计.rar (2.54 MB, 下载次数: 48)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表