51单片机—LED点阵屏(静态&动态)

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;
}

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

绝迹刻本

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值