找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4205|回复: 0
打印 上一主题 下一主题
收起左侧

基于STM32FIC8T6的多功能数字钟程序(实测48小时没有误差)

[复制链接]
跳转到指定楼层
楼主
基于STM32FIC8T6单片机的数字钟实物图如下:

实测48小时没有误差:

其余的子程序都在压缩包里,包括闹钟,温度检测,时间调整。

单片机源程序如下:
  1. #include "delay.h"
  2. #include "sys.h"
  3. #include "usart.h"
  4. #include "lcd.h"
  5. #include "time.h"
  6. #include "temp.h"
  7. #include "key.h"

  8. u8 j=0;//j用来显示星期数组变量

  9. u16 year=2017;
  10. u8 month=6;
  11. u8 day=5;
  12. u16 Tabyear[4]={0,0,0,0};
  13. u8 Tabmonth[2]={0,0};
  14. u8 Tabday[2]={0,0};
  15. u8 sec=0;
  16. u8 min=29;
  17. u8 hou=15;
  18. u8 Tabsec[2]={0,0};
  19. u8 Tabmin[2]={0,0};
  20. u8 Tabhou[2]={0,0};

  21. u8 week[21]="SunMonTueWedThuFriSat";
  22. u8 TP[3]={0,0,0};

  23. void Display_Date()
  24. {
  25.         Tabyear[0]=year/1000;
  26.         Tabyear[1]=year%1000/100;
  27.         Tabyear[2]=year%1000%100/10;
  28.         Tabyear[3]=year%10;
  29.         
  30.         Tabmonth[0]=month/10;
  31.         Tabmonth[1]=month%10;
  32.         
  33.         Tabday[0]=day/10;
  34.         Tabday[1]=day%10;
  35.         
  36.         LCD1602_Display_Date(1,0,0x30+Tabyear[0]);
  37.         LCD1602_Display_Date(2,0,0x30+Tabyear[1]);
  38.         LCD1602_Display_Date(3,0,0x30+Tabyear[2]);
  39.         LCD1602_Display_Date(4,0,0x30+Tabyear[3]);
  40.         LCD1602_Display_Date(5,0,45);
  41.         LCD1602_Display_Date(6,0,0x30+Tabmonth[0]);
  42.         LCD1602_Display_Date(7,0,0x30+Tabmonth[1]);
  43.         LCD1602_Display_Date(8,0,45);
  44.         LCD1602_Display_Date(9,0,0x30+Tabday[0]);
  45.         LCD1602_Display_Date(10,0,0x30+Tabday[1]);
  46.         LCD1602_Display_Table(12,0,week[j]);
  47.         LCD1602_Display_Table(13,0,week[j+1]);
  48.         LCD1602_Display_Table(14,0,week[j+2]);
  49. }

  50. void Display_Time()
  51. {
  52.         if(sec==60)
  53.                 {
  54.                         sec=0;
  55.                         min++;
  56.                         if(min==60)
  57.                         {
  58.                                 min=0;
  59.                                 hou++;
  60.                                 if(hou==24)
  61.                                 {
  62.                                         hou=0;
  63.                                         min=0;
  64.                                         sec=0;
  65.                                         j=j+3;//j用来显示星期数组变量,一天时间到,星期加一
  66.                                         if(j==21)
  67.                                         {
  68.                                                 j=0;
  69.                                         }
  70.                                         day++;
  71.                                         if((month==2)&&(day>29))
  72.                                         {
  73.                                                 month++;
  74.                               day=1;
  75.                                         }
  76.                                         if(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day>31))
  77.                                         {
  78.                                                 month++;
  79.                                                 day=1;
  80.                                                 if(month>12)
  81.                                                 {
  82.                                                         year++;
  83.                                                         month=1;
  84.                                                 }
  85.                                         }
  86.                                         if(((month==4)||(month==6)||(month==9)||(month==11))&&(day>30))
  87.                                         {
  88.                                                 month++;
  89.                                                 day=1;
  90.                                                 if(month>12)
  91.                                                 {
  92.                                                         year++;
  93.                                                         month=1;
  94.                                                 }
  95.                                         }
  96.                                 }
  97.                         }
  98.                 }
  99.         
  100.         Tabsec[0]=sec/10;
  101.         Tabsec[1]=sec%10;
  102.         Tabmin[0]=min/10;
  103.         Tabmin[1]=min%10;
  104.         Tabhou[0]=hou/10;
  105.         Tabhou[1]=hou%10;
  106.         
  107.         LCD1602_Display_Date(1,1,0x30+Tabhou[0]);
  108.         LCD1602_Display_Date(2,1,0x30+Tabhou[1]);
  109.         LCD1602_Display_Date(3,1,58);
  110.         LCD1602_Display_Date(4,1,0x30+Tabmin[0]);
  111.         LCD1602_Display_Date(5,1,0x30+Tabmin[1]);
  112.         LCD1602_Display_Date(6,1,58);
  113.         LCD1602_Display_Date(7,1,0x30+Tabsec[0]);
  114.         LCD1602_Display_Date(8,1,0x30+Tabsec[1]);
  115. }

  116. void Display_Temp(short temp)
  117. {
  118.         if(temp<0)
  119.         {
  120.                 LCD1602_Display_Date(9,1,58);
  121.                 TP[0]=temp/100;
  122.                 TP[1]=temp%100/10;
  123.                 TP[2]=temp%10;
  124.                 LCD1602_Display_Date(10,1,0x30+TP[0]);
  125.                 LCD1602_Display_Date(11,1,0x30+TP[1]);
  126.                 LCD1602_Display_Date(12,1,46);
  127.                 LCD1602_Display_Date(13,1,0x30+TP[2]);
  128.                 LCD1602_Display_Date(14,1,42);
  129.                 LCD1602_Display_Date(15,1,67);
  130.         }
  131.         else
  132.         {
  133.                 TP[0]=temp/100;
  134.                 TP[1]=temp%100/10;
  135.                 TP[2]=temp%10;
  136.                 LCD1602_Display_Date(10,1,0x30+TP[0]);
  137.                 LCD1602_Display_Date(11,1,0x30+TP[1]);
  138.                 LCD1602_Display_Date(12,1,46);
  139.                 LCD1602_Display_Date(13,1,0x30+TP[2]);
  140.                 LCD1602_Display_Date(14,1,42);
  141.                 LCD1602_Display_Date(15,1,67);
  142.         }
  143. }

  144. int main(void)
  145. {
  146.         short temperature;
  147. ……………………

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

所有资料51hei提供下载:
sorce code.7z (187.69 KB, 下载次数: 58)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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