用4个点阵做成的16X16点阵,显示一个汉字向上移动时会有重影,请问如何解决?
以下为代码及原理图
#include<reg52.h>
sbit DS=P0^0;
sbit SH=P0^1;
sbit ST=P0^2;
unsigned char code LED1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x37,0x10,0x80,0x60,0x20,0x0B,0x10,0x20,0xE0,0x20,0x20,0x20,0x2F,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
unsigned char code LED2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xFC,0x40,0x40,0x40,0x48,0xFC,0x40,0x40,0x40,0x40,0x40,0x44,0xFE,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
unsigned char code LED3[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x37,0x10,0x80,0x60,0x20,0x0B,0x10,0x20,0xE0,0x20,0x20,0x20,0x2F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code LED4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xFC,0x40,0x40,0x40,0x48,0xFC,0x40,0x40,0x40,0x40,0x40,0x44,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#define Timer 2500
void hc595_in(unsigned char dat)
{
unsigned char z;
for(z=0;z<8;z++)
{
if((dat&0x80)==0x80)
{
DS=1;
}
else
{
DS=0;
}
dat=dat<<1;
SH=0;
SH=1;
}
}
void hc595_out()
{
ST=0;
ST=1;
}
void main()
{
TMOD=0x01;
TH0=(65536-Timer)/256;
TL0=(65536-Timer)%256;
ET0=1;
TR0=1;
EA=1;
P2 = 0xFF;
while(1);
}
void interrupttimer0() interrupt 1
{
static unsigned char numhang=0;
static unsigned char cnt=0;
static unsigned char t=0;
TH0=(65536-Timer)/256;
TL0=(65536-Timer)%256;
P2 = 0xFF;
switch(numhang)
{
case 0:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0x7F;
numhang++;
break;
case 1:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xBF;
numhang++;
break;
case 2:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xDF;
numhang++;;
break;
case 3:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xEF;
numhang++;
break;
case 4:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xF7;
numhang++;
break;
case 5:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xFB;
numhang++;
break;
case 6:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xFD;
numhang++;;
break;
case 7:
hc595_in(LED4[numhang+cnt]);
hc595_in(LED3[numhang+cnt]);
hc595_in(LED2[numhang+cnt]);
hc595_in(LED1[numhang+cnt]);
hc595_out();
P2=0xFE;
numhang=0;
break;
default:
break;
}
t++;
if(t>=20)
{
t=0;
cnt++;
if(cnt>=32)
{
cnt=0;
}
}
}
|