sec的值不会变的,不知道怎么回事?
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P1^0;
sbit rw=P1^1;
sbit ne=P1^2;
uchar code table[]="0123456789:";
uchar num,sec,tcnt,min,h;
void delay_lcd(uchar a)
{
uchar x,y;
for(x=a;x>0;x--)
for(y=110;y>0;y--)
{}
}
void init_lcd()
{
ne=0;
write_lcdcom(0x38);
write_lcdcom(0x0c);
write_lcdcom(0x06);
write_lcdcom(0x01);
}
void write_lcddata(uchar date)
{
rs=1;
rw=0;
P2=date;
delay_lcd(5);
ne=1;
delay_lcd(5);
ne=0;
}
void write_lcdcom(uchar com)
{
rs=0;
rw=0;
P2=com;
delay_lcd(5);
ne=1;
delay_lcd(5);
ne=0;
}
void tim()
{
uchar h,min,sec;
if(tcnt==20)
{
tcnt=0;
sec++;
if(sec==60)
{
sec=0;
min++ ;
if(min==60)
{
min=0;
h++;
if(h==24)
h=0;
}
}
}
}
void display(uchar shi,ge)
{
write_lcdcom(0x80+0x0a);
write_lcddata(table[ge]);
write_lcdcom(0x80+0x09);
write_lcddata(table[shi]);
}
/*void display(uchar h_ch,uchar h_ge,uchar minsh_a,uchar minge_a,uchar sh_a,uchar ge_a)
{
write_lcdcom(0x80+0x0a);
write_lcddata(table[ge_a]);
write_lcdcom(0x80+0x09);
write_lcddata(table[sh_a]);
write_lcdcom(0x80+0x07);
write_lcddata(table[minge_a]);
write_lcdcom(0x80+0x06);
write_lcddata(table[minsh_a]);
write_lcdcom(0x80+0x04);
write_lcddata(table[h_ge]);
write_lcdcom(0x80+0x03);
write_lcddata(table[h_ch]);
} */
void main()
{
init_lcd();
write_lcdcom(0x80+0x08);
write_lcddata(table[10]);
write_lcdcom(0x80+0x05);
write_lcddata(table[10]);
TMOD=0X01;
TH0=(65535-50000)/255;
TL0=(65535-50000)%255;
ET0=1;
EA=1;
TR0=1;
while(1)
{
// display(h/10,h%10,min/10,min%10,sec/10,sec%10);
tim();
display(sec/10,sec%10);
}
}
void t0()interrupt 1
{
TH0=(65535-50000)/255;
TL0=(65535-50000)%255;
tcnt++;
} |