2019-07-16 04:35发布
Savvy 发表于 2012-9-20 15:20 switch (mon) { case 4:
天下无灾 发表于 2012-9-24 15:19 好 ,值得借鉴
18256911258 发表于 2012-9-24 15:37 #include #include void delay(uint z)
最多设置5个标签!
o ,我知道了 ,谢谢
#include<reg52.h>
#include<define.h>
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<148;y++);
}
void write_com(uchar com)
{
rs=0;
rw=0;
e=0;
P0=com;
delay(5);
e=1;
delay(5);
e=0;
}
void write_date(uchar date)
{
rs=1;
rw=0;
e=0;
P0=date;
delay(5);
e=1;
delay(5);
e=0;
}
void init()
{
uchar num;
e=0;
nian=0;
yue=1;
tian=1;
week=1;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80+0x01);
for(num=0;num<14;num++)
{
write_date(table[num]);
//delay(20);
}
write_com(0x80+0x44);
for(num=0;num<8;num++)
{
write_date(table1[num]);
//delay(20);
}
TMOD=0x01;
TH0=19456/256;
TL0=19456%256;
EA=1;
ET0=1;
TR0=1;
}
void sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void main()
{
init();
while(1)
{
key();
if(t==20)
{
t=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
tian++;
week++;
if(week>7)
{
week=1;
}
switch(week)
{
case 1:write_com(0x80+12);write_date('S');write_date('u');write_date('n');break;
case 2:write_com(0x80+12);write_date('M');write_date('o');write_date('n');break;
case 3:write_com(0x80+12);write_date('T');write_date('u');write_date('e');break;
case 4:write_com(0x80+12);write_date('W');write_date('e');write_date('d');break;
case 5:write_com(0x80+12);write_date('T');write_date('h');write_date('u');break;
case 6:write_com(0x80+12);write_date('F');write_date('r');write_date('i');break;
case 7:write_com(0x80+12);write_date('S');write_date('a');write_date('t');break;
}
if((yue==1)||(yue==3)||(yue==5)||(yue==7)||(yue==8)||(yue==10)||(yue==12))
{
day=31;
}
if((yue==4)||(yue==6)||(yue==9)||(yue==11))
{
day=30;
}
if(yue==2)
{
if((nian%4==0)||(nian==0))
{
day=29;
}
else
{
day=28;
}
}
if(tian>day)
{
tian=1;
yue++;
if(yue>12)
{
yue=1;
nian++;
if(nian>99)
{
nian=0;
}
sfm(3,nian);
}
sfm(6,yue);
}
sfm(9,tian);
}
sfm(0x44+0,shi);
}
sfm(0x44+3,fen);
}
sfm(0x44+6,miao);
}
}
}
void time0() interrupt 1
{
TH0=19456/256;
TL0=19456%256;
t++;
}
这是我自己写的,没注释···
上原理图呀 很好 !思想很好,值得学习!
一周热门 更多>