#include <reg51.h>
sbit rw=P3^3;
sbit rs=P3^2;
sbit en=P3^4;
char hour=10;
char minute=13;
char second=30;
char count=20;
char time[8];
void LCD_startup();
void LCD_inst(char);
void LCD_ldata(char);
void delay1ms(char);
void time1(void);
main()
{
char num;
LCD_startup();
IE=0X82; //T0
TMOD=0X01;
TH0=(65636-50000)/256; //50ms
TL0=(65636-50000)%256;
TR0=1;
while(1)
{
time1();
LCD_inst(0x80);
for(num=0;num<8;num++)
{
LCD_ldata(time[num]);
}
}
}
void LCD_startup()
{
LCD_inst(0x38);
LCD_inst(0x08);
LCD_inst(0x01);
LCD_inst(0x06);
LCD_inst(0x0C);
}
void LCD_inst(char inst)
{
en=0;
rs=0;
rw=0;
delay1ms(5);
en=1;
P2=inst;
delay1ms(5);
en=0;
}
void LCD_ldata(char ldata)
{
en=0;
rs=1;
rw=0;
delay1ms(5);
en=1;
P2=ldata;
delay1ms(5);
en=0;
}
void delay1ms(char x)
{
char i,j;
for(i=0;i<x;i++)
{
for(j=0;j<120;j++)
{;}
}
}
void t0(void) interrupt 1
{
TH0=(65636-50000)/256; //50ms
TL0=(65636-50000)%256;
if(--count==0)
{
count=20;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==13)
hour=0;
}
}
}
}
void time1(void)
{
time[0]=hour/10+0X30;
time[1]=hour%10+0X30;
time[2]=':';
time[3]=minute/10+0X30;
time[4]=minute%10+0X30;
time[5]=':';
time[6]=second/10+0X30;
time[7]=second%10+0X30;
}
|