基于STM32FIC8T6單片機的數字鐘實物圖如下:
IMG_20170624_113901.jpg (3.21 MB, 下載次數: 136)
下載附件
主界面
2017-6-24 11:44 上傳
IMG_20170624_113848.jpg (3.46 MB, 下載次數: 122)
下載附件
c8t6
2017-6-24 11:44 上傳
實測48小時沒有誤差:
IMG_20170624_113915.jpg (3.45 MB, 下載次數: 131)
下載附件
調試界面
2017-6-24 11:44 上傳
其余的子程序都在壓縮包里,包括鬧鐘,溫度檢測,時間調整。
單片機源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- #include "time.h"
- #include "temp.h"
- #include "key.h"
- u8 j=0;//j用來顯示星期數組變量
- u16 year=2017;
- u8 month=6;
- u8 day=5;
- u16 Tabyear[4]={0,0,0,0};
- u8 Tabmonth[2]={0,0};
- u8 Tabday[2]={0,0};
- u8 sec=0;
- u8 min=29;
- u8 hou=15;
- u8 Tabsec[2]={0,0};
- u8 Tabmin[2]={0,0};
- u8 Tabhou[2]={0,0};
- u8 week[21]="SunMonTueWedThuFriSat";
- u8 TP[3]={0,0,0};
- void Display_Date()
- {
- Tabyear[0]=year/1000;
- Tabyear[1]=year%1000/100;
- Tabyear[2]=year%1000%100/10;
- Tabyear[3]=year%10;
-
- Tabmonth[0]=month/10;
- Tabmonth[1]=month%10;
-
- Tabday[0]=day/10;
- Tabday[1]=day%10;
-
- LCD1602_Display_Date(1,0,0x30+Tabyear[0]);
- LCD1602_Display_Date(2,0,0x30+Tabyear[1]);
- LCD1602_Display_Date(3,0,0x30+Tabyear[2]);
- LCD1602_Display_Date(4,0,0x30+Tabyear[3]);
- LCD1602_Display_Date(5,0,45);
- LCD1602_Display_Date(6,0,0x30+Tabmonth[0]);
- LCD1602_Display_Date(7,0,0x30+Tabmonth[1]);
- LCD1602_Display_Date(8,0,45);
- LCD1602_Display_Date(9,0,0x30+Tabday[0]);
- LCD1602_Display_Date(10,0,0x30+Tabday[1]);
- LCD1602_Display_Table(12,0,week[j]);
- LCD1602_Display_Table(13,0,week[j+1]);
- LCD1602_Display_Table(14,0,week[j+2]);
- }
- void Display_Time()
- {
- if(sec==60)
- {
- sec=0;
- min++;
- if(min==60)
- {
- min=0;
- hou++;
- if(hou==24)
- {
- hou=0;
- min=0;
- sec=0;
- j=j+3;//j用來顯示星期數組變量,一天時間到,星期加一
- if(j==21)
- {
- j=0;
- }
- day++;
- if((month==2)&&(day>29))
- {
- month++;
- day=1;
- }
- if(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day>31))
- {
- month++;
- day=1;
- if(month>12)
- {
- year++;
- month=1;
- }
- }
- if(((month==4)||(month==6)||(month==9)||(month==11))&&(day>30))
- {
- month++;
- day=1;
- if(month>12)
- {
- year++;
- month=1;
- }
- }
- }
- }
- }
-
- Tabsec[0]=sec/10;
- Tabsec[1]=sec%10;
- Tabmin[0]=min/10;
- Tabmin[1]=min%10;
- Tabhou[0]=hou/10;
- Tabhou[1]=hou%10;
-
- LCD1602_Display_Date(1,1,0x30+Tabhou[0]);
- LCD1602_Display_Date(2,1,0x30+Tabhou[1]);
- LCD1602_Display_Date(3,1,58);
- LCD1602_Display_Date(4,1,0x30+Tabmin[0]);
- LCD1602_Display_Date(5,1,0x30+Tabmin[1]);
- LCD1602_Display_Date(6,1,58);
- LCD1602_Display_Date(7,1,0x30+Tabsec[0]);
- LCD1602_Display_Date(8,1,0x30+Tabsec[1]);
- }
- void Display_Temp(short temp)
- {
- if(temp<0)
- {
- LCD1602_Display_Date(9,1,58);
- TP[0]=temp/100;
- TP[1]=temp%100/10;
- TP[2]=temp%10;
- LCD1602_Display_Date(10,1,0x30+TP[0]);
- LCD1602_Display_Date(11,1,0x30+TP[1]);
- LCD1602_Display_Date(12,1,46);
- LCD1602_Display_Date(13,1,0x30+TP[2]);
- LCD1602_Display_Date(14,1,42);
- LCD1602_Display_Date(15,1,67);
- }
- else
- {
- TP[0]=temp/100;
- TP[1]=temp%100/10;
- TP[2]=temp%10;
- LCD1602_Display_Date(10,1,0x30+TP[0]);
- LCD1602_Display_Date(11,1,0x30+TP[1]);
- LCD1602_Display_Date(12,1,46);
- LCD1602_Display_Date(13,1,0x30+TP[2]);
- LCD1602_Display_Date(14,1,42);
- LCD1602_Display_Date(15,1,67);
- }
- }
- int main(void)
- {
- short temperature;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
sorce code.7z
(187.69 KB, 下載次數: 58)
2021-8-24 17:36 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|