89C52RC
1.定时器0,lcd1602显示时间。
main.c
#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;
}
}
}
}