#include <STC12C5A60S2.h>
void InitLcd1602();
void LcdWriteDat(unsigned char dat);
void LcdWriteCmd(unsigned char cmd);
void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str, unsigned char len);
void LcdShowchar(unsigned char x,unsigned char y,unsigned char dat);
unsigned char cnt;
unsigned char Day,Month,Year,Weak,Hour,Minutes,Seconds;
void Init()
{
/******定时器初始化******/
TMOD&=0xF0;
TMOD|=0x01;
TH0=0x4C; //50ms
TL0=0x00;
TR0=1;
ET0=1;
EA=1;
/******初始时间初始化******/
Day=20;
Month=11;
Year=15;
Weak=5;
Hour=9;
Minutes=30;
Seconds=0;
}
/******时间显示******/
void TimeDisplay()
{
//显示年
LcdShowStr(0,0,"20",2);
LcdShowchar(2,0,Year/10+'0');
LcdShowchar(3,0,Year%10+'0');
LcdShowStr(4,0,"/",1);
//显示月
LcdShowchar(5,0,Month/10+'0');
LcdShowchar(6,0,Month%10+'0');
LcdShowStr(7,0,"/",1);
//显示日
LcdShowchar(8,0,Day/10+'0');
LcdShowchar(9,0,Day%10+'0');
//显示星期
LcdShowStr(11,0,"[",1);
LcdShowchar(12,0,Weak+'0');
LcdShowStr(13,0,"]",1);
//显示小时
LcdShowchar(0,1,Hour/10+'0');
LcdShowchar(1,1,Hour%10+'0');
LcdShowStr(2,1,":",1);
//显示分钟
LcdShowchar(3,1,Minutes/10+'0');
LcdShowchar(4,1,Minutes%10+'0');
LcdShowStr(5,1,":",1);
//显示秒
LcdShowchar(6,1,Seconds/10+'0');
LcdShowchar(7,1,Seconds%10+'0');
}
void main()
{
Init();
InitLcd1602();
while(1)
{
TimeDisplay();
}
}
void Timer0() interrupt 1
{
TH0=0x4C; //50ms
TL0=0x00;
cnt++;
if(cnt>19) //1s计时
{
cnt=0;
Seconds++;
if(Seconds>59)
{
Seconds=0;
Minutes++;
if(Minutes>59)
{
Minutes=0;
Hour++;
if(Hour>23)
{
Hour=0;
Day++;
Weak++;
}
}
}
}
}
|