1.LED点阵屏的介绍
本单片机使用的是单色点阵
显示原理
想要点亮点阵屏,要先进行行选择和列选择
需要利用74H595来操作点阵屏,也需要用到上图的三个接口SER,SERCLK,RCLK
sfr和sbit
应用一:静态图形
#include <REGX52.H>
#include "Delay.H"
sbit RCK=P3^5; //RCLK
sbit SCK=P3^6; //SRCLK
sbit SER=P3^4; //SER
#define MATRIX_LED_PORT P0
//74hc595写入一个字节
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{//取出最高位
SER=Byte&(0x80>>i);
SCK=1;
SCK=0;
}
RCK=1;
RCK=0;
}
//LED点阵屏显示一列数据
//Column选择列 范围:0~7,0在最左边
//Data 选择列显示的数据,高位在上,1为亮,0为灭
void MatrixLED_ShowColumn(unsigned char Column,Data)
{
_74HC595_WriteByte(Data);
MATRIX_LED_PORT =~(0x80>>Column);
Delay(1);
MATRIX_LED_PORT =0xFE;
}
void main()
{
SCK=0;
RCK=0;
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);
}
}
应用二:实现Hello!的滚动动画效果
#include <REGX52.H>
#include "Delay.H"
#include "MatrixLED.H"
unsigned char a[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEE, 0x08, 0x08, 0x08, 0xFE, 0x00, 0x0E, 0x15,
0x15, 0x15, 0x08, 0x00, 0x7E, 0x01, 0x02, 0x00,
0x7E, 0x01, 0x02, 0x00, 0x0E, 0x11, 0x11, 0x0E,
0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void main()
{
unsigned char i, Offset = 1; // 更正变量名
int Count = 0; // 添加 Count 变量声明
MatrixLED_Init(); // 移到 while 循环之前
while(1) // 去掉多余的分号
{
for(i = 0; i < 8; i++)
{
MatrixLED_ShowColumn(0, a[i + Offset]);
}
Count++;
if(Count > 10)
{
Count = 0;
Offset++;
if(Offset > 40)
{
Offset = 0;
}
}
}
}
------------------------------------------------------------------------
#include <REGX52.H>
#include "Delay.H"
sbit RCK=P3^5; //RCLK
sbit SCK=P3^6; //SRCLK
sbit SER=P3^4; //SER
#define MATRIX_LED_PORT P0
//74hc595写入一个字节
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{//取出最高位
SER=Byte&(0x80>>i);
SCK=1;
SCK=0;
}
RCK=1;
RCK=0;
}
//点阵屏初始化
void MatrixLED_Init()
{
SCK=0;
RCK=0;
}
//LED点阵屏显示一列数据
//Column选择列 范围:0~7,0在最左边
//Data 选择列显示的数据,高位在上,1为亮,0为灭
void MatrixLED_ShowColumn(unsigned char Column,Data)
{
_74HC595_WriteByte(Data);
MATRIX_LED_PORT =~(0x80>>Column);
Delay(1);
MATRIX_LED_PORT =0xFE;
}