第一步喝口汤
个人理解:首先,这个LED点阵屏类似于数码的段选操作,这个LED点阵屏第一步就是利用595芯片来扩充IO,单片595就是能够把一个字节数据通过串行输入(一个IO输入),并行输出(8个IO输出),将我们想要的断码(2位16进制)一次性输入到点阵LED的高电平输入端,简单的说就是595通过把我们需要的列/行置为1,然后再通过我们单片机P0口,给出相对应的低电平,就会把某行中的某列点亮,更简单的说就是,就是利用行列式的下标来锁定对应的LED,只不过595需要一次性给出一行或一列的高电平(我们可以取反看需求硬件电路),给出高电平之后,只要检测到对应的行或列出现低电平,就会将该行列定位的坐标的LED点亮,可以说是控制变量法思想
静态显示(一个笑脸)
需要点亮有一的地方
main.c
#include <REGX52.H>
#include "Delay.h"
sbit SER = P3^4; //不能使用P3_4
sbit RCK = P3^5;
sbit SCK = P3^6;
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i ;
SCK = 0; //移位寄存器的起始信号
RCK = 0; //数据从移位寄存器转存到存储寄存器的起始信号
for(i=0; i<8; i++)
{
SER = Byte&(0X80>>i); //数据放到移位寄存器SER,每来一个上升沿SCK=1,就会把数据移送到移位寄存器中
SCK = 1;
SCK = 0;
}
//把数据送到QA-QH,RCK高电平移送
RCK = 1;
RCK = 0;
}
void MatrixLED_ShowColumn(unsigned char Column,Date)
{
_74HC595_WriteByte(Date);
P0 = ~(0X80>>Column); //P0低电平点亮
Delay1ms(1);
P0 = 0XFF;
}
void main(void)
{
while(1)
{
MatrixLED_ShowColumn(0,0X3C); //显示对应的灯
MatrixLED_ShowColumn(1,0X42);
MatrixLED_ShowColumn(2,0XA9);
MatrixLED_ShowColumn(3,0X85);
MatrixLED_ShowColumn(4,0X85);
MatrixLED_ShowColumn(5,0XA9);
MatrixLED_ShowColumn(6,0X42);
MatrixLED_ShowColumn(7,0X3C);
}
}
动态显示(Whappy)
main.c
#include <REGX52.H>
#include "Delay.h"
#include "MatrixLED.h"
unsigned char Animation[] = {
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0xFC,0x02,0x01,0x02,0x04,0x02,0x01,0x02,
0xFC,0x00,0xFF,0x10,0x1F,0x00,0x3F,0x48,
0x3F,0x00,0x3F,0x48,0x3F,0x81,0x42,0x24,
0x18,0x10,0x20,0x40,0x80,0x00,0x00,0x00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
void main(void)
{
unsigned char i,Offset=0,Count=0;
while(1)
{
for(i=0; i<8; i++)
{
MatrixLED_ShowColumn(i,Animation[i + Offset]);
}
Count++;
if(Count>10)
{
Count = 0;
Offset++;
if(Offset++>40)
Offset = 0;
}
}
}
MatrixLED.c //矩阵显示
#include <REGX52.H>
#include "Delay.h"
sbit SER = P3^4; //不能使用P3_4
sbit RCK = P3^5;
sbit SCK = P3^6;
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i ;
//初始化
SCK = 0; //移位寄存器的起始信号
RCK = 0; //数据从移位寄存器转存到存储寄存器的起始信号
//输入串行数据
for(i=0; i<8; i++)
{
SER = Byte&(0X80>>i); //数据放到移位寄存器SER,每来一个上升沿SCK=1,就会把数据移送到移位寄存器中
SCK = 1;
SCK = 0;
}
//把数据送到QA-QH,RCK高电平移送
RCK = 1;
RCK = 0;
}
void MatrixLED_ShowColumn(unsigned char Column,Date)
{
_74HC595_WriteByte(Date);
P0 = ~(0X80>>Column);
Delay1ms(1);
P0 = 0XFF;
}
MatrixLED.h
#ifndef __MatrixLED_H__
#define __MatrixLED_H__
void _74HC595_WriteByte(unsigned char Byte); //595写断码
void MatrixLED_ShowColumn(unsigned char Column,Date); //位选
#endif
笑脸
#include <REGX52.H>
#include "Delay.h"
#include "MatrixLED.h"
unsigned char Animation[] = {
0x3C,0x42,0xA9,0x85,0x85,0xA9,0x42,0x3C,
0x3C,0x42,0xA1,0x85,0x85,0xA1,0x42,0x3C,
0x3C,0x42,0xA5,0x89,0x89,0xA5,0x42,0x3C,
0x3C,0x42,0xB5,0x89,0x89,0xB5,0x42,0x3C,
0x3C,0x42,0xB1,0x85,0x85,0xB1,0x42,0x3C,
0x3C,0x42,0xA1,0x85,0x85,0xA1,0x42,0x3C,
};
void main(void)
{
unsigned char i,Offset=0,Count=0;
while(1)
{
for(i=0; i<8; i++)
{
MatrixLED_ShowColumn(i,Animation[i + Offset]);
}
Count++;
if(Count>10)
{
Count = 0;
Offset+=7;
if(Offset++>48)
Offset = 0;
}
}
}