9.LED 点阵屏幕
ILED点阵屏由若干个独立的LED组成,LED以矩阵的形式排列,
以灯珠亮灭来显示文字、图片、视频等。
LED点阵屏广泛应用于各种公共场合,如汽车报站器、广告屏以及公告牌等
LED点阵屏分类
按颜色:单色、双色、全彩
按像素:8x8、16x16等(大规模的LED点阵通常由很多个小点阵拼接而成)
LED点阵屏,需要进行逐行/逐列扫描,才能使所有LED同时显示。
过程快速切换,所有的点阵屏幕就都能独立显示。
逐行扫描:先选中第1行,然后列对应的赋值,让第1行某些灯亮;
再选中第2行,然后列对应的赋值,让第2行某些灯亮;
...
点阵屏,形成对应的图形。
点阵屏,IO口拓展,74HC595芯片移位寄存器。 IO口拓展,串行输入并行输出。
#incude <REGX52.H>
sbit RCK = P3^5; // 第5位重命名。
sbit SCK = P3^6;
sbit SER = P3^4;
void _74HC595_WriteByte(unsigned char Byte){
unsigned char i;
for(i=0; i<8; i++) {
SER = Byte &(0x80 >>i); // 8位数据,放到寄存器中
SCK = 1;
SCK = 0;
}
RCK = 1; // 数据输出。
RCK = 0;
}
void main() {
SCK =0;
RCK =0;
_74HC595_WriteByte(0xF0); // 控制led
while(1) {
}
}
9.1 点阵屏幕显示图形,
#incude <REGX52.H>
sbit RCK = P3^5; // 第5位重命名。
sbit SCK = P3^6; //SRCLK
sbit SER = P3^4;
#define MATRIX_LED_PORT P0
// 芯片 74HC595写入一个字节Byte。
void _74HC595_WriteByte(unsigned char Byte){
unsigned char i;
for(i=0; i<8; i++) {
SER = Byte &(0x80 >>i); // 8位数据,放到寄存器中
SCK = 1;
SCK = 0;
}
RCK = 1; // 数据输出。
RCK = 0;
}
// led点阵屏显示,一列数据:Column列序号(0最左边列~7最右边列);
// Data选择列显示的数据,高位在上面,1亮 0灭。
void MatrixLED_ShowColumn(unsigned char Column, Data) {
_74HC595_WriteByte(Data); // 写数据
MATRIX_LED_PORT = ~(0x80 >> Column);
Delay(1); // 消除重影
MATRIX_LED_PORT =0xFF;
}
void main() {
SCK =0;
RCK =0;
while(1) {
// 0-7列,每列显示不同数据,最终显示笑脸。
MatrixLED_ShowColumn(0, 0x3C); // 第一列显示1010 1010
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);
}
}
9.2 点阵屏幕显示动画。
// 模块化 MatrixLED.h .c
MatrixLED_init();
void MatrixLED_ShowColumn(unsigned char Column, Data);
// 模块化 MatrixLED.c
#incude <REGX52.H>
sbit RCK = P3^5; // 第5位重命名。
sbit SCK = P3^6; //SRCLK
sbit SER = P3^4;
#define MATRIX_LED_PORT P0
// 点阵屏初始化
void MatrixLED_init(){
SCK =0;
RCK =0;
}
// 芯片 74HC595写入一个字节Byte。
void _74HC595_WriteByte(unsigned char Byte){
unsigned char i;
for(i=0; i<8; i++) {
SER = Byte &(0x80 >>i); // 8位数据,放到寄存器中
SCK = 1;
SCK = 0;
}
RCK = 1; // 数据输出。
RCK = 0;
}
// led点阵屏显示,一列数据:Column列序号(0最左边列~7最右边列);
// Data选择列显示的数据,高位在上面,1亮 0灭。
void MatrixLED_ShowColumn(unsigned char Column, Data) {
_74HC595_WriteByte(Data); // 写数据
MATRIX_LED_PORT = ~(0x80 >> Column);
Delay(1); // 消除重影
MATRIX_LED_PORT =0xFF;
}
#incude "MatrixLED.h"
// 存储动画,code不占用内存。
unsigned char code Animation[]{
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
0xFF,0x08,0x08,0x08, 0xFF,0x00,0x0E,0x15,
0x15,0x15,0x08,0x00, 0x7E,0x01,0x02,0x00,
0x7E,0x01,0x02,0x00, 0x0E,0x11,0x11,0x0E,
0x00,0x70,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00
};
void main() {
unsigned char i, Offset, Count=0;
MatrixLED_init();
while(1) {
for(int i=0; i<8; i++) {
MatrixLED_ShowColumn(0, Animation[i+Offset]); // 每列显示
}
Count++;
if(Count>10){
Count=0;
Offset ++;
if(Offset>40) Offset =0;// 撤回到第0帧。
}
}
}












网友评论