一.LED点阵屏
二.74HC595
三.相应代码
#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
/**
* @brief 74HC595写入一个字节
* @param Byte 要写入的字节
* @retval 无
*/
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i;
for(i=0;i<8;i++);
{
SER=Byte&(0x80>>i);//i=0 ser=1000 0000(若ser给高电平 则起始位=1 若给低电平 则起始位=0)
//i=1 ser右移一位 以此类推
SCK=1;//给高电平开始移位
SCK=0;//移位后清零 为下次移位做准备
}
RCK=1;
RCK=0;
}
/**
* @brief LED点阵屏显示一列数据
* @param Column 要选择的列,范围:0~7,0在最左边
* @param Data 选择列显示的数据,高位在上,1为亮,0为灭
* @retval 无
*/
void MatrixLED_ShowColumn(unsigned char Column,Data)
{
_74HC595_WriteByte(Data);
MATRIX_LED_PORT=~(0x80>>Column);//第一列=1000 0000 取反后=0111 1111 此时第一列亮
//再由上面的函数顺推指定第一列哪个灯亮 每一列都取反
//此后向右移动
Delay(1); //消影 先延时后清零
MATRIX_LED_PORT=0xFF;
}
void main()
{
SCK=0;//上电全为高电平 所以赋为0
RCK=0;
while(1)
{
MatrixLED_ShowColumn(0,0x3C);//第一列输出0011 1100
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);
}
}
附加sfr和sbit解释