用2个74HC595联级做点阵静态图显示,74HC595做列扫描,51单片机P2口做行扫描,为什么仿真出来的点阵不是一个静态图?而是逐行点亮,甚至夸行点亮?请大神赐教?
以下是源程序和原理图:
源程序:#include<reg52.h>
#include <intrins.h>
sbit DS=P0^0;
sbit SH=P0^1;
sbit ST=P0^2;
unsigned char code LED2[]={0x00,0x82,0xC5,0xF9,0x01,0x02,0x04,0xF8};
unsigned char code LED1[]={0x00,0x41,0xA3,0x9F,0x80,0x40,0x20,0x1F};
void delay1µs()
{
_nop_();
}
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;
delay1µs();
SH=1;
delay1µs();
}
}
void hc595_out()
{
ST=0;
delay1µs();
ST=1;
}
void main()
{
EA=1;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
ET0=1;
TR0=1;
while(1);
}
void interrupttimer0() interrupt 1
{
static unsigned char i=0;
TH0=0xFC;
TL0=0x67;
switch(i)
{
case 0: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0x7F;i++;break;
case 1: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xBF;i++;break;
case 2: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xDF;i++;break;
case 3: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xEF;i++;break;
case 4: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xF7;i++;break;
case 5: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xFB;i++;break;
case 6: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xFD;i++;break;
case 7: hc595_in (LED2); hc595_in (LED1); delay1µs(); hc595_out();P2=0xFE;i=0;break;
default:break;
}
}
|