|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-5-17 13:32:12
|
显示全部楼层
已经搞定,是程序的问题,这样写就好了:
#include <reg51.h>
#define uchar unsigned char
uchar i=0,s,m,h;
uchar code shuzi[]={"0123456789"};
uchar code zifu[]={"00-00-00"};
sbit rs=P2^0;
sbit en=P2^1;
sbit kb=P2^2;
void delay5ms(void)
{
unsigned char a,b;
for(b=185;b>0;b--)
for(a=12;a>0;a--);
}
void xiezhiling(uchar zhiling)
{
en=1;
rs=0;
P0=zhiling;
delay5ms();
en=0;
}
void xieshuju(uchar shuju)
{
en=1;
rs=1;
P0=shuju;
delay5ms();
en=0;
}
void hangliezi(uchar hang,uchar lie,uchar num)
{
if(hang==1)
{
xiezhiling(lie+0x7f);
xieshuju(shuzi[num]);
}
else if(hang==2)
{
xiezhiling(lie+0xbf);
xieshuju(shuzi[num]);
}
}
main()
{
uchar m;
xiezhiling(0x38);
xiezhiling(0x0d);
xiezhiling(0x06);
xiezhiling(0x01);
xiezhiling(0x80);
for(m=0;m<8;m++)
{
xieshuju(zifu[m]);
}
TMOD=0x01;
EA=1;
ET0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(1)
{
if(i==20)
{
i=0;
s++;
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
h=0;
hangliezi(1,1,h/10);
hangliezi(1,2,h%10);
}
hangliezi(1,4,m/10);
hangliezi(1,5,m%10);
}
hangliezi(1,7,s/10);
hangliezi(1,8,s%10);
}
}
}
void timer0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
}
|
|