STC89C52单片机74HC595驱动LED8*8点阵
我做过16*16点阵用了4片595 级联 以下有代码 希望能帮助楼主
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit SH_CP=P1^2;
sbit DS=P1^0;
sbit ST_CP=P1^1;
uchar code tab[ ]=
{ 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,/*" ",0*/
0x00,0x01,0x00,0x06,0x1F,0xF8,0x11,0x00,0x11,0x08,0x11,0x04,0x11,0xF8,0x10,0x01,
0x10,0x02,0xFF,0x84,0x10,0x68,0x90,0x18,0x50,0x64,0x13,0x82,0x10,0x1F,0x00,0x00,/*"成",0*/
0x04,0x20,0x24,0x40,0x24,0xFF,0x25,0x92,0xFE,0x92,0x24,0x92,0x2C,0x92,0x14,0xFF,
0x64,0x00,0x04,0x00,0x7F,0xFF,0x40,0x10,0x44,0x08,0x5B,0x10,0x60,0xE0,0x00,0x00,/*"都",1*/
0x20,0x04,0x21,0x06,0x21,0x04,0x3F,0xF8,0x21,0x08,0x21,0x08,0x00,0x02,0x7F,0x22,
0x49,0x22,0x49,0x22,0x7F,0xFE,0x49,0x22,0x49,0x22,0x7F,0x22,0x00,0x02,0x00,0x00,/*"理",2*/
0x00,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x3F,0xFC,
0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x00,0x04,0x00,0x00,/*"工",3*/
0x04,0x01,0x04,0x01,0x04,0x02,0x04,0x04,0x04,0x08,0x04,0x30,0x04,0xC0,0xFF,0x00,
0x04,0xC0,0x04,0x30,0x04,0x08,0x04,0x04,0x04,0x02,0x04,0x01,0x04,0x01,0x00,0x00,/*"大",4*/
0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00,/*"学",5*/
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,/*" ",0*/
};
//列选 因为595的送数据后高低位倒置,所以数组中的数据预先倒置。如:1111 1110 应为 0111 1111
uchar a[ ]={0x7f,0xff,0xbf,0xff,0xdf,0xff,0xef,0xff,0xf7,0xff,0xfb,0xff,0xfd,0xff,0xfe,0xff,
0xff,0x7f,0xff,0xbf,0xff,0xdf,0xff,0xef,0xff,0xf7,0xff,0xfb,0xff,0xfd,0xff,0xfe,};
void delay(uint z)
{
uint x;
for(;z>0;z--)
for(x=11;x>0;x--);
}
void WriteByte(uchar dat)
{
uchar k;
for(k=0;k<8;k++)
{
dat=dat>>1;
DS=CY;
SH_CP=0;
SH_CP=1;
}
}
void main()
{
uint num,temp,n,m;
while(1)
{
for(n=0;n<112;n++)
for(m=0;m<8;m++) //重复显示8次
{
temp=0;// 不加此条,流动飞快
for(num=n;num<16+n;num++)
{
WriteByte(tab[2*num+1]);
WriteByte(tab[2*num+0]);
WriteByte(a[2*temp+1]); //8~15列选
WriteByte(a[2*temp]); //0~7列选
temp++;
if(temp==16)
temp=0;
ST_CP=0;
ST_CP=1;
delay(2);
}
}
}
}
2012-06-27
{
unsigned char I;
for (I = 0;I<8;I++)
{
_74hc595data = (bit)(Byte & 0x80)
_74hc595clk = 0;
_74hc595clk = 1;
}
}