1.前言
LED点阵屏显示图形:
/YLG_lin/article/details/126587462?spm=1001..3001.5501
当我们了解了LED点阵屏显示图形后,就可以尝试用点阵屏来显示动画了,我们可以定义一个数组,把要显示的图形的数据存到数组里,然后逐个移动数据显示就变成了动画了
1.1 实验现象
2.源码
2.1 main.c
#include <REGX52.H>#include "MatrixLED.h"//动画数据unsigned char Date[]={0X00,0X00,0X00,0X00,0X00,0x21,0x3f,0x21,//I0x00,0x18,0x24,0x22,0x11,0x22,0x24,0x18,//爱心0x00,0x3f,0x01,0x01,0x3f, //U0X00,0X00,0X00,0X00,0X00,};void main(){unsigned char i,Offset=0,Count=0;//偏移量OffsetMatrixLED_Init(); //初始化while(1){for(i=0;i<8;i++){MatrixLED_ShowColumn(i,Date[i+Offset]);}Count++;if(Count>40) //计次延时,不要用Delay,最好用定时器{Count=0;Offset+=1;if(Offset>18)//当超过数组的范围时偏移量清零{Offset=0;}}}}
2.2 MatrixLED.c
#include <REGX52.H>#include "Delay.h"sbit RCK=P3^5;//RCLKsbit SCK=P3^6;//SRCLKsbit SER=P3^4;//SER#define MATRIX_LED_PORTP0//延时函数void Delay(unsigned int xms){unsigned char i, j;while(xms--){i = 2;j = 239;do{while (--j);} while (--i);}}void _74HC595_WriteByte(unsigned char Byte){unsigned char i;for(i=0;i<8;i++){SER=Byte&(0x80>>i);SCK=1;//时钟每来一个上升沿,数据就会往下移,//循环8次,把发送来的串行数据全部放到移位寄存器中;SCK=0;//为下次移位做准备}RCK=1;//把移位寄存器的数据搬运到输出缓存器中;RCK=0;}void MatrixLED_Init(){ SCK=0; //单片机上电初始化后,所有I/O口都为高电平,RCK=0; //所以上电后RCLK和SRCLK要置0;}//LED点阵屏显示一列数据,高位在上,1为亮。void MatrixLED_ShowColumn(unsigned char Column,Data){_74HC595_WriteByte(Data);MATRIX_LED_PORT=~(0x80>>Column);Delay(1);MATRIX_LED_PORT=0xFF;}
2.3 MatrixLED.h
#ifndef __MATRIX_LED_H__#define __MATRIX_LED_H__void MatrixLED_Init();void MatrixLED_ShowColumn(unsigned char Column,Data);#endif