/************************************************************************
* 名称:四位8×8点阵LED显示 *
* 功能:在点阵上显示“SC51”四个字符 *
* 说明:用HC595作数显列驱动,74HC138作行线控制。 *
*************************************************************************/
#include
#include
sbit Hc595clk=P2^0; //Hc595的时钟脚
sbit Hc595data=P2^1; //Hc595的数据脚
sbit Hc595en=P2^2; //Hc595的使能脚
#define LineCtrl P1 //P1口作为行线控制
unsigned char code FONT8x8[4][8]={
//{0x24,0x14,0x0C,0x04,0x0C,0x14,0x24,0x00 }, //K
//{0x3E,0x02,0x02,0x3E,0x02,0x02,0x3E,0x00 }, //E
//{0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00 }, //I
//{0x04,0x04,0x04,0x04,0x04,0x04,0x7C,0x00 }, //L
{0x18,0x24,0x04,0x08,0x10,0x24,0x18,0x00 }, //S
{0x78,0x44,0x04,0x04,0x04,0x44,0x78,0x00 }, //C
{0x3C,0x04,0x04,0x3C,0x20,0x20,0x3C,0x00 }, //5
{0x10,0x18,0x10,0x10,0x10,0x10,0x38,0x00 } //1
} ;//横向、逆序取模
//延时子函数
void delayms(unsigned int ms)
{
unsigned int i=100;
while(ms--)
{
while(i--);
i=10;
}
}
//送一个字节
void SendByte(unsigned char dat)
{
unsigned char i;
for(i=0;i {
if(dat&0x80)
Hc595data=1;
else
Hc595data=0;
Hc595clk=0;
Hc595clk=1;
dat=dat }
}
//每次显示四个字的一行,八行显示完成,就显示出四个完整字。
void Display(unsigned char *dat1,unsigned char *dat2,unsigned char *dat3,unsigned char *dat4)
{
unsigned char i;
for(i=0;i {
SendByte(dat1[i]);
SendByte(dat2[i]);
SendByte(dat3[i]);
SendByte(dat4[i]);
Hc595en=0;
LineCtrl=i;
Hc595en=1;
delayms(10);
}
}
//主程序
void main(void)
{
while(1)
Display(FONT8x8[3],FONT8x8[2],FONT8x8[1],FONT8x8[0]);
}