求解单片机显示时钟程序为啥只显示六个0,程序错在哪里
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar h2,h1,f2,f1,s2,s1;
uchar pp;
uchar a0,a1,a2,a3,a4,a5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=50;j>0;j--);
}
void display(uchar h2,uchar h1,uchar f2,uchar f1,uchar s2,uchar s1)
{
P0=table[h2];
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
delayms(10);
P0=table[h1]|0x80;
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delayms(10);
P0=table[f2];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delayms(10);
P0=table[f1]|0x80;
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delayms(10);
P0=table[s2];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delayms(10);
P0=table[s1];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delayms(10);
}
void main()
{
uchar m,k,t;
TMOD=0x01;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
EA=1;
ET0=1;
while(1)
{
if(pp==20)
{
pp=0;
m++;
if(m==60)
{
m=0;
k++;
if(k==60)
{
k=0;
t++;
if(t==24)
{
t=0;
}
}
}
}
a5=m%10;
a4=m/10;
a3=k%10;
a2=k/10;
a1=t%10;
a0=t/10;
display(a0,a1,a2,a3,a4,a5);
}
}
void time0() interrupt 1
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
pp++;
}
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar h2,h1,f2,f1,s2,s1;
uchar pp;
uchar a0,a1,a2,a3,a4,a5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=50;j>0;j--);
}
void display(uchar h2,uchar h1,uchar f2,uchar f1,uchar s2,uchar s1)
{
P0=table[h2];
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
delayms(10);
P0=table[h1]|0x80;
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delayms(10);
P0=table[f2];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delayms(10);
P0=table[f1]|0x80;
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delayms(10);
P0=table[s2];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delayms(10);
P0=table[s1];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delayms(10);
}
void main()
{
uchar m,k,t;
TMOD=0x01;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
EA=1;
ET0=1;
while(1)
{
if(pp==20)
{
pp=0;
m++;
if(m==60)
{
m=0;
k++;
if(k==60)
{
k=0;
t++;
if(t==24)
{
t=0;
}
}
}
}
a5=m%10;
a4=m/10;
a3=k%10;
a2=k/10;
a1=t%10;
a0=t/10;
display(a0,a1,a2,a3,a4,a5);
}
}
void time0() interrupt 1
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
pp++;
}
1,dula=1;
dula=0;
wela=1;
wela=0;这4个语句看不懂你要干什么?
2,P0先用于数码管位选和然后用于送段码,这样P0口的状态都改变了,肯定没有显示啦,建议数码管位选和送段码分两个独立IO(比如P0位选和P1送段码)
嗯,谢了,我已经改好了