89C52RC
1.定时器0,lcd1602显示时间。
文章来源:https://www.toymoban.com/news/detail-510940.html
main.c文章来源地址https://www.toymoban.com/news/detail-510940.html
#include<regx52.h>
#include "Timer0.h"
#include "lcd1602.h"
#include "Delay.h"
unsigned char sec=55,min=40,hour=17;
void main()
{
//lcd1602锟酵讹拷时锟斤拷锟斤拷始锟斤拷
LCD_Init();
Timer0Init();
LCD_ShowString(1,2,"Clock:");
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_Router() interrupt 1
{
static unsigned int T0Count=0;
TL0 = 0x66; //锟斤拷锟矫讹拷时锟斤拷值
TH0 = 0xFC; //锟斤拷锟矫讹拷时锟斤拷值
if(++T0Count>=1000) //ms
{
T0Count=0;
if(++sec>=60)
{
sec=0;
min++;
if(++min>=60)
{
min=0;
hour++;
if(++hour>=24)
hour=0;
}
}
}
}
到了这里,关于单片机-定时器时钟的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!