#include <reg52.h>
#define uchar unsigned char
#define DB P0
sbit RS = P2^0;
sbit RW = P2^1;
sbit E = P2^2;
sbit P32=P3^2;
sbit P33=P3^3;
sbit P34=P3^5;
uchar code table[]=" ZHAO WEI WEI IS PRINCE CHARMING";
uchar flag=0,cnt=0;
uchar h='0',f=0,sec='0',hs='0',hg='0',fs='0',fg='0',ss='0',sg='0', j1=':',j2=' ';
uchar *p,*mhg,*mhs,*mfg,*mfs,*msg,*mss,*mj1,*mj2,i=0;
void set();
void ready();
void show(uchar*p);
void delay(uchar t);
void writecmd(uchar cmd);
void main()
{
IT0=1;IE0=0;EX0=1;
IT1=1;IE1=0;EX1=1;
TMOD=0x01;TH0=0xB8;TL0=0x00;ET0=1;EA=1;TR0=1;
p=&table;
while(1)
{
if(P34==0)TR0=~TR0;
if(sg>'9'){sg='0';ss++;}
if(ss>'5'){ss='0';fg++;}
if(fg>'9'){fg='0';fs++;}
if(fs>'5'){fs='0';hg++;}
if(hg>'9'){hg='0';hs++;}
if(hs>'2'&&hg>'3'){hs='0';hg='0';}
mhs=&hs;mhg=&hg;mj1=&j1;
mfs=&fs; mfg=&fg;mj2=&j2;
mss=&ss;msg=&sg;
set();
writecmd(0x00|0x80);show(p);
p++;if(*p=='\0') p=&(table);
writecmd(0x47+0x80); show(mhs);
writecmd(0x48+0x80); show(mhg);
writecmd(0x49+0x80); show(mj1);
writecmd(0x4a+0x80); show(mfs);
writecmd(0x4b+0x80); show(mfg);
writecmd(0x4c+0x80); show(mj1);
writecmd(0x4d+0x80); show(mss);
writecmd(0x4e+0x80); show(msg);
writecmd(0x4f+0x80); ready();
RS=1;
RW=0;
DB=' ';
E=1;
E=0;
delay(1000);
delay(1000);
}
}
void writecmd(uchar cmd) //寫命令
{
ready();
RS=0;
RW=0;
DB=cmd;
E=1;
E=0;
}
void writedat(uchar dat) //寫數據
{
ready();
RS=1;
RW=0;
DB=dat;
E=1;
E=0;
}
void show(uchar *p)
{
while(*p!='\0')
{
writedat(*p++);
}
}
void ready() //準備
{
uchar sta;
DB=0xff;
RS=0;
RW=1;
do{
E=1;
sta=DB;
E=0;
}while(sta&0X80);
}
void set()
{
writecmd(0x38);
writecmd(0x0c);
writecmd(0x06);
writecmd(0x01);
}
void delay (uchar t)
{
uchar i,j;
for(i=0;i<=t;i++)
for(j=0;j<=100;j++);
}
void Interrupt() interrupt 1 using 2
{
TH0=0xB8;TL0=0x00;cnt++;
if(cnt>=50){cnt=0;sg++;}
}
void int0_sev(void) interrupt 0 using 1
{
if(P32==0){fg++;}
}
void int1_sev(void) interrupt 2 using 3
{
if(P33==0){hg++;}
}
|