#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^6;
sbit EN=P2^7;
sbit RW=P2^5;
unsigned char n,miao;
uchar code lcd[]="0123456789";
uchar code lcd2[]="162101203";
void delay(uint Nms)
{
uint i;
uchar j;
for(i=0;i<Nms;i++)
for(j=0;j<120;j++)
;
}
int lcd_cmd (uint cmd)
{
RS=0;
delay(1);
RW=0;
delay(1);
P0=cmd;
delay(1);
EN=1;
delay(5);
EN=0;
delay(5);
}
int lcd_date (uint date)
{
RS=1;
delay(1);
RW=0;
delay(1);
P0=date;
delay(1);
EN=1;
delay(5);
EN=0;
delay(5);
}
void int_1() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
n++;
if(n==20)
{
n=0;
miao++;
if(miao==60)
{
miao=0;
}
}
}
void main()
{
uint i;
uchar m;
TMOD=0x10;
ET1=1;
EA=1;
TR1=1;
lcd_cmd(0x38);
lcd_cmd(0x0c);
lcd_cmd(0x06);
while(1)
{
lcd_cmd(0x80+0x03);
for(i=0;i<9;i++)
{
lcd_date(lcd2[i]);
}
lcd_cmd(0x80+0x40+0x07);
lcd_date(lcd[miao/10]);
lcd_cmd(0x80+0x40+0x08);
lcd_date(lcd[miao%10]);
}
}
|