(求汇编orC程序)将51单片机TO计数器的值传输到1602LCD显示,程序怎么编写

2024-11-30 05:00:27
推荐回答(2个)
回答(1):

flag++;
if(flag==20)
{ miao++;
flag=0;
write_sfm(10,miao);
if(miao==60)
{ fen++;
miao=0;
write_sfm(10,miao);
write_sfm(7,fen);
if(fen==60)
{ shi++;
fen=0;
write_sfm(7,fen);
write_sfm(4,shi);
if(shi==24)
{ shi=0;
write_sfm(4,shi);}
}
}
}
}
这是我使用郭天祥的TX-1c开发板写的,你值要求从定时器读到液晶,这个我没有,我把我写的液晶显示时间的程序给你,也使用了定时器来跑时间,做个参考吧,也只有C程序了。
希望我的回答能帮助到你。

回答(2):

#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit en=P3^4;
sbit rs=P3^5;
sbit beep=P2^3;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit rd=P3^7;
char flag;
char shi=0;
char fen=0;
char miao=0;
uchar key1num;
uchar code WEEK[]="2013/01/16 Tue";
void delay(uint x)
{ uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);}
void di()
{ beep=0;
delay(25);
beep=1;
delay(25);
}
void write_com(uchar x)
{ rs=0;
P0=x;
delay(5);
en=1;
delay(5);
en=0;
delay(5);}
void write_date(uchar x)
{ rs=1;
P0=x;
delay(5);
en=1;
delay(5);
en=0;
delay(5);}
void write_sfm(uchar add,uchar x)
{ uchar shi,ge;
shi=x/10;
ge=x%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void key()
{
rd=0;
if(key1==0)
{
delay(5);
if(key1==0)
{ key1num++;
di();
while(!key1);
if(key1num==1)
{
TR0=0;
write_com(0x80+0x40+10);
write_com(0x0f);
}
}
if(key1num==2)
{
write_com(0x80+0x40+7);
}
if(key1num==3)
{
write_com(0x80+0x40+4);
}
if(key1num==4)
{
key1num=0;
write_com(0x0c);
TR0=1;
}

}
if(key1num!=0)
{
if(key2==0)
{
delay(5);
if(key2==0)
{ di();
while(!key2);
if(key1num==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(10,miao);
write_com(0x80+0x40+10);

}
if(key1num==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(key1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
}
}
if(key3==0)
{
delay(5);
if(key3==0)
{ di();
while(!key3);
if(key1num==1)
{
if(miao==0)
{
miao=59;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
if(key1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(key1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
}
}
}
}
void init()
{ write_com(0x38);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
wela=1;
P0=0xff;
wela=0;
dula=1;
P0=0xff;
dula=0;
write_com(0x80+0x40+6);
write_date(':');
write_com(0x80+0x40+9);
write_date(':');
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{ uchar i;
init();
write_com(0x80);
for(i=0;i<14;i++)
write_date(WEEK[i]);
write_sfm(4,shi);
write_sfm(7,fen);
write_sfm(10,miao);
while(1)
key();
}
void Timer0()interrupt 1
{ TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
flag++;
if(flag==20)
{ miao++;
flag=0;
write_sfm(10,miao);
if(miao==60)
{ fen++;
miao=0;
write_sfm(10,miao);
write_sfm(7,fen);
if(fen==60)
{ shi++;
fen=0;
write_sfm(7,fen);
write_sfm(4,shi);
if(shi==24)
{ shi=0;
write_sfm(4,shi);}
}
}
}
}
这是我使用郭天祥的TX-1c开发板写的,你值要求从定时器读到液晶,这个我没有,我把我写的液晶显示时间的程序给你,也使用了定时器来跑时间,做个参考吧,也只有C程序了。
希望我的回答能帮助到你。