stc89c52 单片机,想弄一个16x48的点阵,用6片74hc595级联扫描48列,2片74hc595扫描16行,程序如下,用 proteus仿真有明显的闪烁,如果是实际 电路会有闪烁吗?请问是不是程序的问题?应该怎么改?或者是硬件不可以这样连接?谁能给我个用595驱动16x48点阵的方案??谢谢。。
#include
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
***it sh1=P1^0;
***it ds1=P1^1;
***it st1=P1^2;
***it sh2=P1^3;
***it ds2=P1^4;
***it st2=P1^5;
void delay()
{
unsigned int x;
for(x=30;x>0;x--) ;
}
code uint8 graph1[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x14,0x12,0x91,0x70,0x11,0x1E,0x10,0x10,0x00,0x1F,0x00,0x00,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
code uint8 graph2[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x04,0x08,0x90,0x60,0x98,0x06,0x00,0x00,0x00,0xF0,0x02,0x01,0xFE,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
uint8 i= 0,counter = 0;
void timer1_init()
{
TMOD |= 0x10;
TMOD &= 0xdf;
TH1 = 0xfc;
TL1 = 0x67;
TR1 = 1;}
void int_init()
{
ET1 = 1;EA = 1;
}
void hang(unsigned char da)
{
unsigned char k;
for(k=0;k<8;k++)
{
sh1=0;
if((da&0x80)==0x80)
ds1=1;
else
ds1=0;
sh1=1;
da<<=1;
}
}
void lie(unsigned char dat)
{
unsigned char k;
for(k=0;k<8;k++)
{
sh2=0;
if((dat&0x80)==0x80)
ds2=1;
else
ds2=0;
sh2=1;
dat<<=1;
}
}
void refresh_led()
{
static uint8 j = 0;
switch(j)
{
case 0: lie(0x7f);lie(0xff);lie(0xff);lie(0xff);lie(0xff);lie(0xff);st2=0;st2=1;st2=0;break;
case 1: lie(0xbf);lie(0xff);lie(0xff);lie(0xff);lie(0xff);lie(0xff);st2=0;st2=1;st2=0;break;
case 2: lie(0xdf);lie(0xff);lie(0xff);lie(0xff);lie(0xff);lie(0xff);st2=0;st2=1;st2=0;break;
case 3: lie(0xef);lie(0xff);lie(0xff);lie(0xff);lie(0xff);lie(0xff);st2=0;st2=1;st2=0;break;
case 4: lie(0xf7),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 5: lie(0xfb),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 6: lie(0xfd),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 7: lie(0xfe),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 8: lie(0xff),lie(0x7f),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 9: lie(0xff),lie(0xbf),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 10: lie(0xff),lie(0xdf),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 11: lie(0xff),lie(0xef),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 12: lie(0xff),lie(0xf7),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 13: lie(0xff),lie(0xfb),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 14: lie(0xff),lie(0xfd),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 15: lie(0xff),lie(0xfe),lie(0xff),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 16: lie(0xff),lie(0xff),lie(0x7f),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 17: lie(0xff),lie(0xff),lie(0xbf),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 18: lie(0xff),lie(0xff),lie(0xdf),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 19: lie(0xff),lie(0xff),lie(0xef),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 20: lie(0xff),lie(0xff),lie(0xf7),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 21: lie(0xff),lie(0xff),lie(0xfb),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 22: lie(0xff),lie(0xff),lie(0xfd),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 23: lie(0xff),lie(0xff),lie(0xfe),lie(0xff),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 24: lie(0xff),lie(0xff),lie(0xff),lie(0x7f),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 25: lie(0xff),lie(0xff),lie(0xff),lie(0xbf),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 26: lie(0xff),lie(0xff),lie(0xff),lie(0xdf),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 27: lie(0xff),lie(0xff),lie(0xff),lie(0xef),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 28: lie(0xff),lie(0xff),lie(0xff),lie(0xf7),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 29: lie(0xff),lie(0xff),lie(0xff),lie(0xfb),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 30: lie(0xff),lie(0xff),lie(0xff),lie(0xfd),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 31: lie(0xff),lie(0xff),lie(0xff),lie(0xfe),lie(0xff),lie(0xff);st2=0;st2=1;st2=0;break;
case 32: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0x7f),lie(0xff);st2=0;st2=1;st2=0;break;
case 33: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xbf),lie(0xff);st2=0;st2=1;st2=0;break;
case 34: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xdf),lie(0xff);st2=0;st2=1;st2=0;break;
case 35: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xef),lie(0xff);st2=0;st2=1;st2=0;break;
case 36: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xf7),lie(0xff);st2=0;st2=1;st2=0;break;
case 37: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfb),lie(0xff);st2=0;st2=1;st2=0;break;
case 38: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfd),lie(0xff);st2=0;st2=1;st2=0;break;
case 39: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfe),lie(0xff);st2=0;st2=1;st2=0;break;
case 40: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0x7f);st2=0;st2=1;st2=0;break;
case 41: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xbf);st2=0;st2=1;st2=0;break;
case 42: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xdf);st2=0;st2=1;st2=0;break;
case 43: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xef);st2=0;st2=1;st2=0;break;
case 44: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xf7);st2=0;st2=1;st2=0;break;
case 45: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfb);st2=0;st2=1;st2=0;break;
case 46: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfd);st2=0;st2=1;st2=0;break;
case 47: lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xff),lie(0xfe);st2=0;st2=1;st2=0;break;
default: break;
}
hang(graph1[i+j]);
hang(graph2[i+j]);
st1=0;st1=1;st1=0;
if(47 == j++) j = 0;
delay();
}
main()
{
timer1_init();
int_init();
while(1);
}
void interrupt_timer1() interrupt 3
{
TH1 = 0xfc;
TL1 = 0x67;
counter++;
if(counter == 100)
{
counter = 0;
i++;
if(i>=64){i=0;}
}
refresh_led();
}
|