|
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define shuchu P0
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit weixuan=P3^0;
sbit jia=P3^2;
sbit jan=P3^3;
uchar shi,fen,miao;
uchar shishi,shige,fenshi,fenge,miaoshi,miaoge;
void T1chushi();
uchar hang1[]={"1250321 CLASS"};
uchar hang2[]={"MCU_LESSON"};
uchar shizhong[]={"23:59:00"};
uchar rili[]={"2014-11-18"};
uchar n,n20;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=123;y>0;y--);
}
void xiezhiling(uchar zhiling)
{
E=0;
RS=0;
RW=0;
shuchu=zhiling;
E=1;
delay(5);
E=0;
}
void xieshuju(uchar shuju)
{
E=0;
RS=1;
RW=0;
shuchu=shuju;
E=1;
delay(5);
E=0;
}
void chushi()
{
xiezhiling(0x38);
xiezhiling(0x0c);
xiezhiling(0x06);
xiezhiling(0x80);
xiezhiling(0x01);
}
/*******显示并移动字符**********/
void main()
{
chushi();
xiezhiling(0x81);
for(n=0;n<13;n++)
{
xieshuju(hang1[n]);
delay(20);
}
//while(1);
//xiezhiling(0xc0);
xiezhiling(0xc3);
for(n=0;n<10;n++)
{
xieshuju(hang2[n]);
delay(20);
}
//while(1);
delay(1000);
xiezhiling(0x01);
xiezhiling(0x90);
for(n=0;n<13;n++)
{
xieshuju(hang1[n]);
delay(5);
}
xiezhiling(0xd2);
for(n=0;n<10;n++)
{
xieshuju(hang2[n]);
delay(5);
}
//for(n=0;n<16;n++)
for(n=0;n<15;n++)
{
xiezhiling(0x0c);
xiezhiling(0x1c);
delay(50);
}
delay(1000);
xiezhiling(0x01);
T1chushi();
while(1)
{
if(weixuan==0)
{
delay(5);
if(weixuan==0)
{
TR1=0;
xiezhiling(0xc7);
xiezhiling(0x0e);
while(weixuan);
}
}
}
}
/************数字钟***************/
void T1chushi()
{
TMOD=0x10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
EA=1;
ET1=1;
n20=0;
miao=0;
fen=59;
shi=23;
xiezhiling(0xc3);
for(n=0;n<8;n++)
{
xieshuju(shizhong[n]);
delay(5);
//xiezhiling(0x0c);
}
xiezhiling(0x82);
for(n=0;n<10;n++)
{
xieshuju(rili[n]);
delay(5);
//xiezhiling(0x0c);
}
}
void T1zhongduan() interrupt 3
{
n20++;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(n20==20)
{
n20=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
shi=0;
shishi=0x30+shi/10;
shige=0x30+shi%10;
xiezhiling(0xc3);
xieshuju(shishi);
delay(5);
xieshuju(shige);
delay(5);
}
fenshi=0x30+fen/10;
fenge=0x30+fen%10;
xiezhiling(0xc6);
xieshuju(fenshi),
delay(5);
xieshuju(fenge);
delay(5);
}
miaoshi=0x30+miao/10;
miaoge=0x30+miao%10;
xiezhiling(0xc9);
xieshuju(miaoshi);
delay(5);
xieshuju(miaoge);
delay(5);
}
}
|
|