lcd1602做时间,为什么显示时时间没有走动啊,谢谢
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcdrs = P1^0;
sbit lcdrw = P1^1;
sbit lcden = P2^5;
sbit dula = P2^6;
sbit wela = P2^7;
uchar a,t,sec,min,h;
void delay(uint z)//延迟函数
{
uchar x, y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time() //时间
{
if(t == 20)//定时器定时50ms,20次就是1秒
{
t = 0;
sec++;
}
if(sec > 59)
{
sec = 0;
min++;
}
if(min > 59)
{
min = 0;
h++;
}
if(h > 23)
{
h = 0;
}
}
void write_com(uchar com)
{
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 write_hms()
{
write_com(0xc0+3); //在第二行第四位
write_date(0x30+h/10); //小时
write_date(0x30+h%10);
write_date(0x3a); //冒号
write_date(0x30+min/10);
write_date(0x30+min%10);
write_date(0x3a); //冒号
write_date(0x30+sec/10);
write_date(0x30+sec%10);
}
void init()
{
lcdrw = 0;
dula = 0;
wela = 0;
lcden = 0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void dingshi() //定时器初始化
{
TMOD = 0x01;
TH0 = (65535-46080)/256;
TL0 = (65535-46080)%256;
ET0 = 1;
TR0 = 1;
EA = 1;
}
void zhongduan() interrupt 1
{
TH0 = (65535-46080)/256;
TL0 = (65535-46080)%256;
t++;
}
void main()
{
init();
dingshi();
time();
write_hms();
while(1);
}
#define uchar unsigned char
#define uint unsigned int
sbit lcdrs = P1^0;
sbit lcdrw = P1^1;
sbit lcden = P2^5;
sbit dula = P2^6;
sbit wela = P2^7;
uchar a,t,sec,min,h;
void delay(uint z)//延迟函数
{
uchar x, y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time() //时间
{
if(t == 20)//定时器定时50ms,20次就是1秒
{
t = 0;
sec++;
}
if(sec > 59)
{
sec = 0;
min++;
}
if(min > 59)
{
min = 0;
h++;
}
if(h > 23)
{
h = 0;
}
}
void write_com(uchar com)
{
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 write_hms()
{
write_com(0xc0+3); //在第二行第四位
write_date(0x30+h/10); //小时
write_date(0x30+h%10);
write_date(0x3a); //冒号
write_date(0x30+min/10);
write_date(0x30+min%10);
write_date(0x3a); //冒号
write_date(0x30+sec/10);
write_date(0x30+sec%10);
}
void init()
{
lcdrw = 0;
dula = 0;
wela = 0;
lcden = 0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void dingshi() //定时器初始化
{
TMOD = 0x01;
TH0 = (65535-46080)/256;
TL0 = (65535-46080)%256;
ET0 = 1;
TR0 = 1;
EA = 1;
}
void zhongduan() interrupt 1
{
TH0 = (65535-46080)/256;
TL0 = (65535-46080)%256;
t++;
}
void main()
{
init();
dingshi();
time();
write_hms();
while(1);
}
就是这样,瞄
是不是都没有动态更新数据呀
void time() //时间
{
if(t == 20)//定时器定时50ms,20次就是1秒
{
t = 0;
sec++;
}
if(sec > 59)
{
sec = 0;
min++;
}
if(min > 59)
{
min = 0;
h++;
}
if(h > 23)
{
h = 0;
}
我想问题应该出现在这里,后里的if语句应该在第一个if的套内。
我也是初学者,说得不对请不要见笑。
是呀 没走动啊