数码管动态扫描
时间:10-02
整理:3721RD
点击:
昨天用定时器做了个动态扫描,让数码管从0加到9999,有做消隐设计,前300的显示很稳定,没抖动,其他没选中的数码管一直保持熄灭状态,但是300以后 ,点亮了的数码管有时会抖动,显示不均匀,计数保持正常。求解为什么300以后会抖动。谢谢,下面附上源码.
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f
};
uchar s1,s2,s3,s4,number; //定义四位对应的数,a是初始数,number是定时器
uint a,flag,flag1; //flag作为定时器计数标记
void initialization();
void display();
void main()
{
initialization();
while(1)
{
if(100==flag)
{
flag=0;
a++;
}
s1=a/1000;
s2=a/100%10;
s3=a/10%10;
s4=a%10;
display(); //因为定义的是全局变量,所以不需要实参
}
}
void initialization()
{
EA=1;
TMOD=0X11;
ET1=1;
TR1=1;
ET0=1;
TR0=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
a=0;
number=0;
flag=0;
}
void display() //因为定义的是全局变量,所以不需要实参
{
switch(number)
{
case 0:
{
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
// P0=0x00;
dula=1;
P0=table[s1];
dula=0;
};
break;
case 1:
{
P0=0xff; //消隐
wela=1;
P0=0xfd;
wela=0;
// P0=0x00;
dula=1;
P0=table[s2];
dula=0;
};
break;
case 2:
{
P0=0xff; //消隐
wela=1;
P0=0xfb;
wela=0;
// P0=0x00;
dula=1;
P0=table[s3];
dula=0;
};
break;
case 3:
{
P0=0xff; //消隐
wela=1;
P0=0xf7;
wela=0;
// P0=0x00; //段选消隐
dula=1;
P0=table[s4];
dula=0;
};
break;
}
}
void timer0()interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
number++;
flag++;
if(4==number)
{
number=0;
}
}
void timer1()interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
flag1++;
if(10==flag1)
{
flag1=0;
P1=~P1; //LED灯1秒亮灭
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f
};
uchar s1,s2,s3,s4,number; //定义四位对应的数,a是初始数,number是定时器
uint a,flag,flag1; //flag作为定时器计数标记
void initialization();
void display();
void main()
{
initialization();
while(1)
{
if(100==flag)
{
flag=0;
a++;
}
s1=a/1000;
s2=a/100%10;
s3=a/10%10;
s4=a%10;
display(); //因为定义的是全局变量,所以不需要实参
}
}
void initialization()
{
EA=1;
TMOD=0X11;
ET1=1;
TR1=1;
ET0=1;
TR0=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
a=0;
number=0;
flag=0;
}
void display() //因为定义的是全局变量,所以不需要实参
{
switch(number)
{
case 0:
{
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
// P0=0x00;
dula=1;
P0=table[s1];
dula=0;
};
break;
case 1:
{
P0=0xff; //消隐
wela=1;
P0=0xfd;
wela=0;
// P0=0x00;
dula=1;
P0=table[s2];
dula=0;
};
break;
case 2:
{
P0=0xff; //消隐
wela=1;
P0=0xfb;
wela=0;
// P0=0x00;
dula=1;
P0=table[s3];
dula=0;
};
break;
case 3:
{
P0=0xff; //消隐
wela=1;
P0=0xf7;
wela=0;
// P0=0x00; //段选消隐
dula=1;
P0=table[s4];
dula=0;
};
break;
}
}
void timer0()interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
number++;
flag++;
if(4==number)
{
number=0;
}
}
void timer1()interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
flag1++;
if(10==flag1)
{
flag1=0;
P1=~P1; //LED灯1秒亮灭
}
}
坐等大神指导
问一下,抖动?是什么意思?
你是用硬件测试的还是仿真软件?
你电路图有吗,结合电路分析才好,我看了你的程序,你应该是用了什么驱动器件了,位选和段选都是用P0口!