新闻中心

EEPW首页>嵌入式系统>设计应用> 利用51的定时器和1602的一个时钟程序

利用51的定时器和1602的一个时钟程序

作者: 时间:2016-11-26 来源:网络 收藏
#include

#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^0;
sbit lcden=P3^1;
sbit s1=P3^6;
sbit s2=P3^7;
uchar count,shi,fen,miao,num;
uchar code table[]="2011-02-25";
uchar code table1[]="00:00:00";
void reflesh(uchar add,uchar date);
void delay(uchar z)
{
uint x,y;
for(x=0;x for(y=0;y<110;y++);
}
void write_ins(uchar add)
{
rs=0;
delay(5);
P1=add;
lcden=1;

delay(5);
lcden=0;
delay(5);
}
void write_date(uchar add)
{
rs=1;
delay(5);
P1=add;
lcden=1;

delay(5);
lcden=0;
delay(5);
}
void init()
{
uchar i;
lcden=0;
shi=0;
fen=0;
miao=0;
write_ins(0x38);
write_ins(0x0c);
write_ins(0x06);
write_ins(0x01);
write_ins(0x80);
for(i=0;i<14;i++)
{
write_date(table[i]);
delay(5);
}
write_ins(0x80+0x40);
for(i=0;i<13;i++)
{
write_date(table1[i]);
delay(5);
}

TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{

本文引用地址: //m.amcfsurvey.com/article/201611/321662.htm

if(num==""||num==0)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
TR0=0;
write_ins(0x80+0x40+11);
write_ins(0x0c);
num=1;
}
}
if(num==1)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x80+0x40+8);
write_ins(0x0c);
num=2;
}
}
if(num==2)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x80+0x40+5);
write_ins(0x0c);
num=3;
}
}
if(num==3)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x0c);
TR0=1;
num=0;
}
}






if(num!=0)
{
if(num==1)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
miao++;
if(miao==60)
miao=0;
reflesh(0x80+0x40+10,miao);
}
}
if(num==2)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
fen++;
if(fen==60)
miao=0;
reflesh(0x80+0x40+7,fen);
}
}
if(num==3)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
shi++;
if(shi==24)
shi=0;
reflesh(0x80+0x40+4,shi);
}
}
}
}
void main()
{
init();

while(1)
{
keyscan();
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
}
reflesh(0x80+0x40+4,shi);
}
reflesh(0x80+0x40+7,fen);
}
reflesh(0x80+0x40+10,miao);


}

}

void timer0()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
count++;
}
void reflesh(uchar add,uchar date)
{
uchar ten,ge;
write_ins(add);
ten=date/10;
ge=date;
write_date(0x30+ten);
write_date(0x30+ge);


}



关键词:51定时器160

评论


技术专区

关闭