告诉我的程序错在哪里了:
题目:用动态扫描方法和定时器1在数码管的前三位显示出秒表,
精确到1%秒,即最后一位显示1%秒,一直循环下去
设时钟频率为12M
我写得成的程序:
#include<reg52.h>
#define uchar unsigned char
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar num1,num2,num3;
sbit dula=P2^6;
sbit wela=P2^7;
void init()
{
TMOD=0X01;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
ET1=1;
TR1=1;
}
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar z)
{
uchar ge;
ge=z;
dula=1;
P0=table[num1];
dula=0;
P0=0xff;
wela=1;
P0=0Xfe;
wela=0;
delay(1);
if(num1==10)
{
num1=0;
num2++;
dula=1;
P0=table[num2];
dula=0;
P0=0xff;
wela=1;
P0=0Xfd;
wela=0;
delay(1);
if(num2==10)
{
num2=0;
num3++;
dula=1;
P0=table[num3];
dula=0;
P0=0xff;
wela=1;
P0=0Xfb;
wela=0;
delay(1);
}
}
}
void main()
{
init();
while(1)
{
display(num1);
}
}
void timer1() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
num1++;
}
出现的现象:百位一直显示8,个位十位不断乱闪
希望前辈们能指点指点,不胜感激 |