基于51单片机控制的简易时钟(内部定时器)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
write_comd(0x0c);
write_comd(0x06);
write_comd(0x01);
}
void write_sfm()
{
write_comd(0x80+0x44);
write_date(0x30+shi/10);
write_comd(0x80+0x45);
write_date(0x30+shi%10);
write_comd(0x80+0x01);
write_date('T');
write_comd(0x80+0x02);
write_date('Z');
write_comd(0x80+0x03);
write_date('X');
write_comd(0x80+0x04);
write_date(0x3A);
sbit k1=P1^0;
sbit k2=P1^2;
sbit k3=P1^5;
sbit k4=P1^6;
sbit k5=P1^7;
void keyscan();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_comd(uchar com)
TH0=(655356-50000)/256;
TL0=(655356-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{yue=6;
ri=29;
shi=23;
fen=59;
start();
miao=0;
init_time0();
while(1)
{
keyscan();
write_sfm();
write_comd(0x80+0x05);
write_date(0x30+0x02);
write_comd(0x80+0x06);
write_date(0x30+0x00);
write_comd(0x80+0x07);
write_date(0x30+0x01);
write_comd(0x80+0x08);
write_nyr();
}
}
void t0() interrupt 1
{
TH0=(655356-50000)/256;
TL0=(655356-50000)%256;
a++;
if(a==20)
{
a=0;
miBaidu Nhomakorabeao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
{
delay(1);
if(k4==0)
{
while(!k4);
shi++;
if(shi==24)
shi=0;
}
}
if(k5==0)
{
delay(1);
if(k5==0)
{
while(!k5);
shi--;
if(shi==0)
shi=23;
}
}
}
}
shi++;
if(shi==24)
shi=0;
ri++;
if(ri==30)
{
ri=1;
yue++;
if(yue==12)
yue=1;
}
}
}
}
}
void keyscan()
{
uchar flag;
if(k1==0)
{
delay(1);
if(k1==0)
{
while(!k1);
TR0=~TR0;
flag=~flag;
write_date(0x30+0x08);
write_comd(0x80+0x09);
write_date(0X2d);
write_comd(0x80+0x0a);
write_date(0x30+yue/10);
write_comd(0x80+0x0b);
write_date(0x30+yue%10);
write_comd(0x80+0x46);
write_date(0x3A);
write_comd(0x80+0x47);
write_date(0x30+fen/10);
write_comd(0x80+0x48);
write_date(0x30+fen%10);
write_comd(0x80+0x49);
}
}
if(flag)
{
if(k2==0)
{
delay(1);
if(k2==0)
{
while(!k2);
fen++;
if(fen==60)
{
fen=0;
shi++;
}
}
}
if(k3==0)
{
delay(1);
if(k3==0)
{
while(!k3);
fen--;
if(fen==0)
fen=59;
}
}
if(k4==0)
write_date(0x3A);
write_comd(0x80+0x4a);
write_date(0x30+miao/10);
write_comd(0x80+0x4b);
write_date(0x30+miao%10);
}
void write_nyr()
{
write_comd(0x80);
write_date('M');
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date (uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void start()
{
write_comd(0x38);
write_comd(0x80+0x0c);
write_date(0x2d);
write_comd(0x80+0x0d);
write_date(0x30+ri/10);
write_comd(0x80+0x0e);
write_date(0x30+ri%10);
}
void init_time0()
{
TMOD=0X01;
若需要仿真图+程序(Q:409975690)
附程序:#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar n,fen,miao,shi,ri ,yue;
uint a;
sbit lcden=P2^1;
sbit lcdrs=P2^0;
write_comd(0x06);
write_comd(0x01);
}
void write_sfm()
{
write_comd(0x80+0x44);
write_date(0x30+shi/10);
write_comd(0x80+0x45);
write_date(0x30+shi%10);
write_comd(0x80+0x01);
write_date('T');
write_comd(0x80+0x02);
write_date('Z');
write_comd(0x80+0x03);
write_date('X');
write_comd(0x80+0x04);
write_date(0x3A);
sbit k1=P1^0;
sbit k2=P1^2;
sbit k3=P1^5;
sbit k4=P1^6;
sbit k5=P1^7;
void keyscan();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_comd(uchar com)
TH0=(655356-50000)/256;
TL0=(655356-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{yue=6;
ri=29;
shi=23;
fen=59;
start();
miao=0;
init_time0();
while(1)
{
keyscan();
write_sfm();
write_comd(0x80+0x05);
write_date(0x30+0x02);
write_comd(0x80+0x06);
write_date(0x30+0x00);
write_comd(0x80+0x07);
write_date(0x30+0x01);
write_comd(0x80+0x08);
write_nyr();
}
}
void t0() interrupt 1
{
TH0=(655356-50000)/256;
TL0=(655356-50000)%256;
a++;
if(a==20)
{
a=0;
miBaidu Nhomakorabeao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
{
delay(1);
if(k4==0)
{
while(!k4);
shi++;
if(shi==24)
shi=0;
}
}
if(k5==0)
{
delay(1);
if(k5==0)
{
while(!k5);
shi--;
if(shi==0)
shi=23;
}
}
}
}
shi++;
if(shi==24)
shi=0;
ri++;
if(ri==30)
{
ri=1;
yue++;
if(yue==12)
yue=1;
}
}
}
}
}
void keyscan()
{
uchar flag;
if(k1==0)
{
delay(1);
if(k1==0)
{
while(!k1);
TR0=~TR0;
flag=~flag;
write_date(0x30+0x08);
write_comd(0x80+0x09);
write_date(0X2d);
write_comd(0x80+0x0a);
write_date(0x30+yue/10);
write_comd(0x80+0x0b);
write_date(0x30+yue%10);
write_comd(0x80+0x46);
write_date(0x3A);
write_comd(0x80+0x47);
write_date(0x30+fen/10);
write_comd(0x80+0x48);
write_date(0x30+fen%10);
write_comd(0x80+0x49);
}
}
if(flag)
{
if(k2==0)
{
delay(1);
if(k2==0)
{
while(!k2);
fen++;
if(fen==60)
{
fen=0;
shi++;
}
}
}
if(k3==0)
{
delay(1);
if(k3==0)
{
while(!k3);
fen--;
if(fen==0)
fen=59;
}
}
if(k4==0)
write_date(0x3A);
write_comd(0x80+0x4a);
write_date(0x30+miao/10);
write_comd(0x80+0x4b);
write_date(0x30+miao%10);
}
void write_nyr()
{
write_comd(0x80);
write_date('M');
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date (uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void start()
{
write_comd(0x38);
write_comd(0x80+0x0c);
write_date(0x2d);
write_comd(0x80+0x0d);
write_date(0x30+ri/10);
write_comd(0x80+0x0e);
write_date(0x30+ri%10);
}
void init_time0()
{
TMOD=0X01;
若需要仿真图+程序(Q:409975690)
附程序:#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar n,fen,miao,shi,ri ,yue;
uint a;
sbit lcden=P2^1;
sbit lcdrs=P2^0;