#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
sbit dula=P3^7;
sbit rs=P2^4;
sbit rw=P2^5;
sbit en=P2^6;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
uchar count,shi,fen,miao,snum,dat;
uchar code table1[]="2011-07-21 MON";
uchar code table2[]="22:59:53";
void write_com(uchar com)
{
rs=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void write_date(uchar date)
{
rs=1;
en=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
}
void init();
void write_sfm(uchar add,uchar date);
void keyscan();
void main()//主函数
{
init();
while(1)
{
keyscan();
}
while(1);
}
void keyscan()
{
if(s1==0)
{
delay(5);
if(s1==0)
{
while(!s1);
delay(5);
while(!s1);
snum++;//位置放消抖前后均可
if(snum==1)
{
TR0=0;
write_com(0x80+0x40+7);
write_com(0x0f);
}
if(snum==2)
{
write_com(0x80+0x40+4);
}
if(snum==3)
{
write_com(0x80+0x40+1);
}
if(snum==4)
{
snum=0;
write_com(0x0c);
TR0=1;
}
}
}
if(snum!=0)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
delay(5);
while(!s2);
if(snum==1)
{
miao++;
if(miao==60)
{
miao=0;
}
write_sfm(6,miao);
write_com(0x80+0x40+7);
}
if(snum==2)
{
fen++;
if(fen==60)
{
fen=0;
}
write_sfm(3,fen);
write_com(0x80+0x40+4);
}
if(snum==3)
{
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(0,shi);
write_com(0x80+0x40+1);
}
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
delay(5);
while(!s3);
if(snum==1)
{
miao--;
if(miao==0)
{
miao=59;
}
write_sfm(6,miao);
write_com(0x80+0x40+7);
//“}”不能放这里 ,否则+了以后不显示
}
if(snum==2)
{
fen--;
if(fen==0)
{
fen=59;
}
write_sfm(3,fen);
write_com(0x80+0x40+4);
}
if(snum==3)
{
shi--;
if(shi==0)
{
shi=23;
}
write_sfm(0,shi);
write_com(0x80+0x40+1);
}
}
}
}
}
void init()
{
uchar num;
dula=1;
P0=0x00;
dula=0;
en=0;
rw=0;
fen=59;
miao=53;
shi=22;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<14;num++)
{
write_date(table1[num]);
delay(1);
}
write_com(0x80+0x40);
for(num=0;num<8;num++)
{
write_date(table2[num]);
delay(1);
}
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
//keyscan(); //会造成snum多加一位
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(0,shi);
}
write_sfm(3,fen);
}
write_sfm(6,miao);
}
}
顺便说下,阿莫大哥,我发的这贴算技术帖不,时间有限啊,三天发五技术帖貌似有点短,不过如果我审核过的话,我会发更多帖,不过我还是初学,只能这么多了哈
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>