#include <regx52.h>
#include "time.h"
#include "LCD1602.h"
unsigned int ten_us ;
void delay_10us(u16 ten_us)
{
while(ten_us--); //循环递减
}
unsigned char Sec,Min,Hour;
void main()
{
LCD_Init();
Timer0_Init();
LCD_ShowString(1,1,"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);
}
}
typedef unsigned int u16;
void Timer0_Routine() interrupt 1
{
static u16 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;
}
}
}
}
}
|