成品展示
涉及到:單片機,LCD1602,定時器,中斷,
這只是個基礎的程式,他可以演變許多復雜的模塊,比如:定時中斷,定時器,資料顯示,鬧鐘程式等等,
他所需要用到的代碼:
#include <REGX52.H>
#include “LCD1602.h” //
#include “Delay.h” //
#include “time.h” //這有三個模塊
unsigned char sec,min,hour;
void main()
{ LCD_Init();
sec=51; //這是時鐘的初值,可以刪去或者改變初值
hour=21; //之所以賦初值是方便觀察
min=59; //
Timer0Init();
LCD_ShowString(1,1,“timebomb”); //改變timebomb輸入你想表達的英文
LCD_ShowString(2,1," : : ");
while(1)
{
LCD_ShowNum(2,1,hour,2);
LCD_ShowNum(2,4,min,2);
LCD_ShowNum(2,7,sec,2);
}
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count;
TL0 = 0x18; //設定定時初值
TH0 = 0xFC; //設定定時初值
T0Count++;
if(T0Count>=1000)
{
T0Count=0;
sec++;
if(sec>=60)
{
sec=0;
min++;
if(min>=60)
{
min=0;
hour++;
if(hour>=24)
{
hour=0;
}
}
}
}
}
以上僅展示主程式
這個程式所需要的模塊若打出來的話所需頁面太大,如果有需要的話,可在百度網盤下載,
百度網盤:
鏈接:https://pan.baidu.com/s/1zpgV8QUCOHoRpEHF225ZZw
提取碼:0ifz
我只是一個小白,如果有錯誤的話,我會趕快改正,謝謝啦
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/254109.html
標籤:其他
下一篇:視覺學習 Task03
