stc89c52 简单1602万年历程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
break;
case 7:
write_com(0x0c);
TR0=1;
KNUM=0;
break;
}
}
}
if(KNUM==1)
{
if(KUP==0)
{
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
fen--;
if(fen==-1)
delay(5);
if(KUP==0)
{
while(!KUP)
;
shi++;
if(shi==24)
shi=0;
sfmdisplay(0x40+0x03,shi);
write_com(0x80+0X40+0x04);
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define lcd_data P0
#define lcd_com P0
sbit lcd_en=P2^7;
sbit lcd_rw=P3^7;
sbit lcd_rs=P3^6;
ri++;
if(yue==2&&ri==29)
{
ri=0;
yue++;
}
if((yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)&&ri==32)
sfmdisplay(0x08,yue);
}
sfmdisplay(0x0b,ri);
}
sfmdisplay(0x40+0x03,shi);
}
Hale Waihona Puke sfmdisplay(0x40+0x06,fen);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
ri--;
if(yue==2&&ri==0)
ri=28;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==00)
write_com(0x08);//关闭显示屏
write_com(0x01);//清楚显示屏
write_com(0x0c);//开启显示屏(无光标)
write_com(0x06);//读写字符时指针自动加1(整屏不移动)
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
sbit KEY=P3^3;
sbit KUP=P3^4;
sbit KDOWN=P3^5;
uchar code disp1[]=" 2009-01-01";
uchar code disp2[]=" 00:00:00";
uchar aa,shi,fen,miao,ri=1,yue=1,nian=9,KNUM;
{
ri=0;
yue++;
if(yue==13)
{
yue=0;
nian++;
sfmdisplay(0x05,nian);
}
}
void write_str(uchar addr,uchar *str)//显示字符串
{
write_com(addr);
do
{
write_data(*str);
str++;
}
while(*str!='\0')
;
}
void init()
{
write_com(0x38);//设置显示模式
ri=1;
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
ri=1;
sfmdisplay(0x0a,ri);
write_com(0x80+0x0b);
write_com(0x0f);
delay(1);
lcd_en=0;
}
void write_data(uchar lcddata)//显示字符
{
lcd_rw=0;
lcd_rs=1;
lcd_en=0;
delay(1);
lcd_en=1;
lcd_data=lcddata;
delay(1);
lcd_en=0;
void delay(uint);
void write_com(uchar);
void write_data(uchar);
void write_str(uchar,uchar *str);
void init();
void sfmdisplay(uchar,uchar);
void keyscan();
delay(5);
if(KUP==0)
{
while(!KUP)
;
ri++;
if(yue==2&&ri==29)
ri=1;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==32)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--)
;
}
void write_com(uchar com)//写控制字
{
lcd_rw=0;
lcd_rs=0;
lcd_en=0;
delay(1);
lcd_en=1;
lcd_com=com;
{
delay(5);
if(KUP==0)
{
while(!KUP)
;
fen++;
if(fen==60)
fen=0;
sfmdisplay(0x40+0x06,fen);
write_com(0x80+0X40+0x07);
miao=59;
sfmdisplay(0x40+0x09,miao);
write_com(0x80+0X40+0x0a);
write_com(0x0f);
}
}
}
if(KNUM==2)
{
if(KUP==0)
EA=1;
ET0=1;
TR0=1;
}
void sfmdisplay(uchar addr,uchar date)
{
write_com(0x80+addr);
write_data(date/10+0x30);
write_data(date%10+0x30);
}
void keyscan()
shi=23;
sfmdisplay(0x40+0x03,shi);
write_com(0x80+0X40+0x04);
write_com(0x0f);
}
}
}
if(KNUM==4)
{
if(KUP==0)
{
{
ri=0;
yue++;
if(yue==13)
{
yue=0;
nian++;
}
}
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
shi--;
if(shi==-1)
{
P0=0X0F;
if(KEY==0)
{
delay(5);
if(KEY==0)
{
while(!KEY)
;
KNUM++;
switch(KNUM)
{
case 1:
TR0=0;
write_com(0x80+0X40+0x0a);
}
sfmdisplay(0x40+0x09,miao);
}
}
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
aa++;
}
void delay(uint z)
write_com(0x0f);
break;
case 2:
write_com(0x80+0x40+0x07);
break;
case 3:
write_com(0x80+0x40+0x04);
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
break;
case 4:
write_com(0x80+0x0b);
break;
case 5:
write_com(0x80+0x08);
break;
case 6:
write_com(0x80+0x05);
fen=59;
sfmdisplay(0x40+0x06,fen);
write_com(0x80+0X40+0x07);
write_com(0x0f);
}
}
}
if(KNUM==3)
{
if(KUP==0)
{
delay(5);
if(KUP==0)
{
while(!KUP)
;
miao++;
if(miao==60)
miao=0;
sfmdisplay(0x40+0x09,miao);
write_com(0x80+0X40+0x0a);
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
miao--;
if(miao==-1)
void shanping();
void main()
{
init();
write_str(0x80,disp1);
write_str(0x80+0x40,disp2);
while(1)
{
keyscan();
if(aa==20)
{
aa=0;
case 7:
write_com(0x0c);
TR0=1;
KNUM=0;
break;
}
}
}
if(KNUM==1)
{
if(KUP==0)
{
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
fen--;
if(fen==-1)
delay(5);
if(KUP==0)
{
while(!KUP)
;
shi++;
if(shi==24)
shi=0;
sfmdisplay(0x40+0x03,shi);
write_com(0x80+0X40+0x04);
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define lcd_data P0
#define lcd_com P0
sbit lcd_en=P2^7;
sbit lcd_rw=P3^7;
sbit lcd_rs=P3^6;
ri++;
if(yue==2&&ri==29)
{
ri=0;
yue++;
}
if((yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)&&ri==32)
sfmdisplay(0x08,yue);
}
sfmdisplay(0x0b,ri);
}
sfmdisplay(0x40+0x03,shi);
}
Hale Waihona Puke sfmdisplay(0x40+0x06,fen);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
ri--;
if(yue==2&&ri==0)
ri=28;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==00)
write_com(0x08);//关闭显示屏
write_com(0x01);//清楚显示屏
write_com(0x0c);//开启显示屏(无光标)
write_com(0x06);//读写字符时指针自动加1(整屏不移动)
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
sbit KEY=P3^3;
sbit KUP=P3^4;
sbit KDOWN=P3^5;
uchar code disp1[]=" 2009-01-01";
uchar code disp2[]=" 00:00:00";
uchar aa,shi,fen,miao,ri=1,yue=1,nian=9,KNUM;
{
ri=0;
yue++;
if(yue==13)
{
yue=0;
nian++;
sfmdisplay(0x05,nian);
}
}
void write_str(uchar addr,uchar *str)//显示字符串
{
write_com(addr);
do
{
write_data(*str);
str++;
}
while(*str!='\0')
;
}
void init()
{
write_com(0x38);//设置显示模式
ri=1;
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
ri=1;
sfmdisplay(0x0a,ri);
write_com(0x80+0x0b);
write_com(0x0f);
delay(1);
lcd_en=0;
}
void write_data(uchar lcddata)//显示字符
{
lcd_rw=0;
lcd_rs=1;
lcd_en=0;
delay(1);
lcd_en=1;
lcd_data=lcddata;
delay(1);
lcd_en=0;
void delay(uint);
void write_com(uchar);
void write_data(uchar);
void write_str(uchar,uchar *str);
void init();
void sfmdisplay(uchar,uchar);
void keyscan();
delay(5);
if(KUP==0)
{
while(!KUP)
;
ri++;
if(yue==2&&ri==29)
ri=1;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==32)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--)
;
}
void write_com(uchar com)//写控制字
{
lcd_rw=0;
lcd_rs=0;
lcd_en=0;
delay(1);
lcd_en=1;
lcd_com=com;
{
delay(5);
if(KUP==0)
{
while(!KUP)
;
fen++;
if(fen==60)
fen=0;
sfmdisplay(0x40+0x06,fen);
write_com(0x80+0X40+0x07);
miao=59;
sfmdisplay(0x40+0x09,miao);
write_com(0x80+0X40+0x0a);
write_com(0x0f);
}
}
}
if(KNUM==2)
{
if(KUP==0)
EA=1;
ET0=1;
TR0=1;
}
void sfmdisplay(uchar addr,uchar date)
{
write_com(0x80+addr);
write_data(date/10+0x30);
write_data(date%10+0x30);
}
void keyscan()
shi=23;
sfmdisplay(0x40+0x03,shi);
write_com(0x80+0X40+0x04);
write_com(0x0f);
}
}
}
if(KNUM==4)
{
if(KUP==0)
{
{
ri=0;
yue++;
if(yue==13)
{
yue=0;
nian++;
}
}
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
shi--;
if(shi==-1)
{
P0=0X0F;
if(KEY==0)
{
delay(5);
if(KEY==0)
{
while(!KEY)
;
KNUM++;
switch(KNUM)
{
case 1:
TR0=0;
write_com(0x80+0X40+0x0a);
}
sfmdisplay(0x40+0x09,miao);
}
}
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
aa++;
}
void delay(uint z)
write_com(0x0f);
break;
case 2:
write_com(0x80+0x40+0x07);
break;
case 3:
write_com(0x80+0x40+0x04);
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
break;
case 4:
write_com(0x80+0x0b);
break;
case 5:
write_com(0x80+0x08);
break;
case 6:
write_com(0x80+0x05);
fen=59;
sfmdisplay(0x40+0x06,fen);
write_com(0x80+0X40+0x07);
write_com(0x0f);
}
}
}
if(KNUM==3)
{
if(KUP==0)
{
delay(5);
if(KUP==0)
{
while(!KUP)
;
miao++;
if(miao==60)
miao=0;
sfmdisplay(0x40+0x09,miao);
write_com(0x80+0X40+0x0a);
write_com(0x0f);
}
}
if(KDOWN==0)
{
delay(5);
if(KDOWN==0)
{
while(!KDOWN)
;
miao--;
if(miao==-1)
void shanping();
void main()
{
init();
write_str(0x80,disp1);
write_str(0x80+0x40,disp2);
while(1)
{
keyscan();
if(aa==20)
{
aa=0;