8*8点阵显示数字出现鬼影现象,求大神帮忙改程序
时间:10-02
整理:3721RD
点击:
本人新手
P1是列,P2是行。求帮忙修改,谢谢!
程序如下:
#include<reg52.h>
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code graph[11][8]={
{0x0,0x8,0x18,0x8,0x8,0x8,0x8,0x8},//1
{0x0,0x18,0x24,0x24,0x8,0x10,0x20,0x3C},//2
{0x0,0x18,0x24,0x4,0x8,0x24,0x24,0x18},//3
{0x0,0x8,0x8,0x18,0x28,0x3C,0x8,0x8},//4
{0x0,0x3C,0x20,0x38,0x4,0x4,0x24,0x18},//5
{0x0,0x18,0x24,0x20,0x38,0x24,0x24,0x18}//6
};
unsigned char DisplayData;
unsigned char count;
unsigned char cnta;
sbit P35=P3^5;//按键开关定义
void Delay()
{
unsigned char a,b;
for(a=5;a>0;a--)
for(b=248;b>0;b--);
}
void main()
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=0;
ET0=1;
EA=1;
while(1)
{
DisplayData=TH0%10;
if(P35==0)
{
while(P35==0);
{
TR0=1;
P2=tab[cnta];
P1=graph[DisplayData][cnta];
Delay();
}
}
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
P2=tab[cnta];
P1=graph[DisplayData][cnta];
cnta++;
if(cnta==8)
{
cnta=0;
}
}
P1是列,P2是行。求帮忙修改,谢谢!
程序如下:
#include<reg52.h>
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code graph[11][8]={
{0x0,0x8,0x18,0x8,0x8,0x8,0x8,0x8},//1
{0x0,0x18,0x24,0x24,0x8,0x10,0x20,0x3C},//2
{0x0,0x18,0x24,0x4,0x8,0x24,0x24,0x18},//3
{0x0,0x8,0x8,0x18,0x28,0x3C,0x8,0x8},//4
{0x0,0x3C,0x20,0x38,0x4,0x4,0x24,0x18},//5
{0x0,0x18,0x24,0x20,0x38,0x24,0x24,0x18}//6
};
unsigned char DisplayData;
unsigned char count;
unsigned char cnta;
sbit P35=P3^5;//按键开关定义
void Delay()
{
unsigned char a,b;
for(a=5;a>0;a--)
for(b=248;b>0;b--);
}
void main()
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=0;
ET0=1;
EA=1;
while(1)
{
DisplayData=TH0%10;
if(P35==0)
{
while(P35==0);
{
TR0=1;
P2=tab[cnta];
P1=graph[DisplayData][cnta];
Delay();
}
}
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
P2=tab[cnta];
P1=graph[DisplayData][cnta];
cnta++;
if(cnta==8)
{
cnta=0;
}
}
可能是延时不够
请问改成多少合适
5MS 左右把 。
我的观点是和延时没有太大关系,主要原因是因为: P2=tab[cnta]; P1=graph[DisplayData][cnta];
当你考虑到第二个周期回来的时候,P1还是上一个状态,但是P2已经发生了改变,这个时候会将LED瞬间点亮一下造成鬼影,解决方法应该是:在P2=tab[cnta]之前先让P1输出无效,比如你P1输出全部高电平就是LED全灭那么可以在前面加上P1=0xFF,反之P1=0;
5楼的方法是对的~~~~~~~~~~~~~~
楼上正解,对于任何LED的使用,在改变输出前需要先消影,然后才是改变输出,否则会有鬼影
谢谢分享啦啊啊啊啊啊啊啊啊啊啊
貌似不怎么懂,看了好长时间
三楼说的正确,
一样的问题我也遇到了,正在解决中。
改一下中断里面的延时
路过,学习学习.....
只要在动态扫描之前将点阵全部关闭就可以了