51单片机STC89C52RC——8.2 8*8 LED点阵模块(动态图像)

目的/效果

在《51单片机STC89C52RC------8.1 8*8 LED点阵模块(点亮一个LED)》我们点亮一个LED,接下来我们将在8*8的矩阵中展示动态的图像。

1:单列展示:

2:单行展示

3:笑脸

4:右移箭头

一,STC单片机模块

二,8*8 点阵

在 《51单片机STC89C52RC------8.1 8*8 LED点阵模块(点亮一个LED)》,我们了解了如何点亮点阵的LED。

在《51单片机STC89C52RC------3.2 数码管动态展示(多位动态)_stc89c52单只数码管显示0到f电路图-CSDN博客中我们要多个LED展示需要 动态显示轮流显示各个字符。利用人眼视觉暂留的特点,循环顺序变更位码,同时数据线上发送相应的显示内容。

2.1 一列一列 亮

cpp 复制代码
#include <REGX52.H>  
#include "74HC595.h"
#include "Delay.h"
/**
 * 函    数:主函数
 * 参    数:无
 * 返 回 值:无
 */
void main()
{	 	 
	while(1)
	{
		_74HC595_Show(0,0xff); //第一列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(1,0xff); //第二列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(2,0xff); //第三列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(3,0xff); //第四列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(4,0xff); //第五列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(5,0xff); //第六列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(6,0xff); //第七列
		Delay_ms(500);//延时500毫秒
		_74HC595_Show(7,0xff); //第八列
		Delay_ms(500);//延时500毫秒
	}
} 

2.2 一行一行 亮

cpp 复制代码
#include <REGX52.H>  
#include "74HC595.h"
#include "Delay.h"
/**
 * 函    数:主函数
 * 参    数:无
 * 返 回 值:无
 */
void main()
{	 	 
	P0=0x00;//先全部置高电平
	while(1)
	{
		_74HC595_WriteByte(0x80);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x40);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x20);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x10);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x08);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x04);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x02);
		Delay_ms(500);//延时500毫秒
		_74HC595_WriteByte(0x01);
		Delay_ms(500);//延时500毫秒		
	}
} 

2.3 笑脸

cpp 复制代码
#include <REGX52.H>  
#include "74HC595.h"
#include "Delay.h"
/**
 * 函    数:主函数
 * 参    数:无
 * 返 回 值:无
 */
void main()
{	 	 
	P0=0x00;//先全部置高电平
	while(1)
	{
		//笑脸
		_74HC595_Show(0,0x3C);
		_74HC595_Show(1,0x42);
		_74HC595_Show(2,0xA9);
		_74HC595_Show(3,0x85);
		_74HC595_Show(4,0x85);
		_74HC595_Show(5,0xA9);
		_74HC595_Show(6,0x42);
		_74HC595_Show(7,0x3C);
	}
} 

2.4 右移箭头

cpp 复制代码
#include <REGX52.H>  
#include "74HC595.h"
#include "Delay.h"
 
/**
 * 函    数:动态展示向右的箭头
 * 参    数:无
 * 返 回 值:无
 */
void Show_RightArrow()
{
  int i=0,j=0,temp;
  unsigned char  rightArrow_colData[8]= {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //箭头列数据
  unsigned char  rightArrow_rowData[10]= {0x10,0x10,0x10,0x10,0x92,0x54,0x38,0x10,0x00,0x00}; //箭头行数据
  while(1)
    {

		//交换行数据
		temp=rightArrow_rowData[9];
		for(j=9; j>0; j--)
		{
			rightArrow_rowData[j]=rightArrow_rowData[j-1];
		}
		rightArrow_rowData[0]=temp;
		for(j=0; j<50; j++)
		{
			rightArrow_rowData[0]=temp;
			for(i=0; i<8; i++) //循环8次扫描8行、列
			{
				P0=rightArrow_colData[i];//传送列选数据
				_74HC595_WriteByte(rightArrow_rowData[i]);//传送行选数据
				Delay_10us(10);//延时一段时间,等待显示稳定
				_74HC595_WriteByte(0x00);//消影
			} 
		}
    }
}
/**
 * 函    数:主函数
 * 参    数:无
 * 返 回 值:无
 */
void main()
{	 
	Show_RightArrow();	
} 

三,创建Keil项目

详细参考:51单片机STC89C52RC------创建Keil项目-CSDN博客

四,代码

main.c

cpp 复制代码
#include <REGX52.H>  
#include "74HC595.h"
#include "Delay.h"
 
/**
 * 函    数:动态展示向右的箭头
 * 参    数:无
 * 返 回 值:无
 */
void Show_RightArrow()
{
  int i=0,j=0,temp;
  unsigned char  rightArrow_colData[8]= {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //箭头列数据
  unsigned char  rightArrow_rowData[10]= {0x10,0x10,0x10,0x10,0x92,0x54,0x38,0x10,0x00,0x00}; //箭头行数据
  while(1)
    {

		//交换行数据
		temp=rightArrow_rowData[9];
		for(j=9; j>0; j--)
		{
			rightArrow_rowData[j]=rightArrow_rowData[j-1];
		}
		rightArrow_rowData[0]=temp;
		for(j=0; j<50; j++)
		{
			rightArrow_rowData[0]=temp;
			for(i=0; i<8; i++) //循环8次扫描8行、列
			{
				P0=rightArrow_colData[i];//传送列选数据
				_74HC595_WriteByte(rightArrow_rowData[i]);//传送行选数据
				Delay_10us(10);//延时一段时间,等待显示稳定
				_74HC595_WriteByte(0x00);//消影
			} 
		}
    }
}
/**
 * 函    数:主函数
 * 参    数:无
 * 返 回 值:无
 */
void main()
{	 
	Show_RightArrow();	
//	P0=0x00;//先全部置高电平
//	while(1)
//	{
//		//笑脸
//		_74HC595_Show(0,0x3C);
//		_74HC595_Show(1,0x42);
//		_74HC595_Show(2,0xA9);
//		_74HC595_Show(3,0x85);
//		_74HC595_Show(4,0x85);
//		_74HC595_Show(5,0xA9);
//		_74HC595_Show(6,0x42);
//		_74HC595_Show(7,0x3C);
		
		//一行行显示
//		_74HC595_WriteByte(0x80);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x40);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x20);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x10);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x08);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x04);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x02);
//		Delay_ms(500);//延时500毫秒
//		_74HC595_WriteByte(0x01);
//		Delay_ms(500);//延时500毫秒
		
		
		//一列列显示
//		_74HC595_Show(0,0xff); //第一列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(1,0xff); //第二列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(2,0xff); //第三列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(3,0xff); //第四列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(4,0xff); //第五列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(5,0xff); //第六列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(6,0xff); //第七列
//		Delay_ms(500);//延时500毫秒
//		_74HC595_Show(7,0xff); //第八列
//		Delay_ms(500);//延时500毫秒
		
//	}
} 

Delay.c

cpp 复制代码
/**
 * 函    数:延时函数 毫秒
 * 参    数:ms 延时多少毫秒
 * 返 回 值:无
 */
void Delay_ms(int ms)	//@12.000MHz
{
	unsigned char data i, j;
	while(ms--)
	{ 
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
	}
}
/**
 * 函    数:延时函数 毫秒
 * 参    数:ms 延时多少毫秒
 * 返 回 值:无
 */
void Delay_us(int ms)	//@12.000MHz
{
	unsigned char data i, j;
	while(ms--)
	{ 
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
	}
}
/**
 * 函    数:延时函数  10微秒
 * 参    数:无
 * 返 回 值:无
 */
void Delay_10us(int _10us)	//@11.0592MHz
{
	unsigned char data i;
	while(_10us--)
	{
		i = 2;
		while (--i);
	}
}

Delay.h

cpp 复制代码
#ifndef __DELAY_H_
#defind __DELAY_H_ 
void Delay_ms(int ms);
void Delay_10us(int _10us);
#endif

74HC595.c

cpp 复制代码
#include <REGX52.H>
#include "Delay.h"

//定义74HC595控制管脚
sbit _SRCLK=P3^6;	//移位寄存器时钟输入
sbit _RCLK=P3^5;	//存储寄存器时钟输入 注意:在 REGX52.H 中已经申明了RCLK
sbit _SER=P3^4; 	//串行数据输入 

/**
 * 函    数:74HC595写入一个字节
 * 参    数:Byte 要写入的字节
 * 返 回 值:无
 */
void _74HC595_WriteByte(unsigned int Byte)
{	
	unsigned char i;
	for(i=0;i<8;i++)
	{
		_SER=Byte&(0x80>>i);		//将1000 0000 右移i位后 & Byte
		_SRCLK=0;				//移位寄存器置搞电平
		Delay_10us(1);
		_SRCLK=1;				//移位寄存器置低电平
		/*这里有需要可以延时10微秒*/
		Delay_10us(1);
	}
	_RCLK=1;	//存储寄存器置低电平
	Delay_10us(1);
	_RCLK=0;	//存储寄存器置搞电平 
}
/**
 * 函    数:LED点阵屏显示一列数据
 * 参    数:Column 要选择的列,范围:0~7,0在最左边,
			 Data 选择列显示的数据,高位在上,1为亮,0为灭
 * 返 回 值:无
 */
void _74HC595_Show(unsigned char Column,Byte)
{
	_74HC595_WriteByte(Byte);	//向行写入数据
	P0=~(0x80>>Column);			//向列写入数据
	Delay_10us(1);				//等待显示稳定 
}

74HC595.h

cpp 复制代码
#ifndef __74HC595_H_
#defind __74HC595_H_
void _74HC595_WriteByte(unsigned int Byte);
void _74HC595_Show(unsigned char Column,Byte);
#endif

五,代码编译、下载到51单片机

代码编译请参考

51单片机STC89C52RC------代码编译-CSDN博客

代码下载请参考

《51单片机STC89C52RC------STCAI-ISP代码下载-CSDN博客

相关推荐
人才程序员19 分钟前
【Rust入门】猜数游戏
开发语言·c++·后端·单片机·游戏·rust·c
人才程序员27 分钟前
【Rust入门】生成随机数
开发语言·数据库·后端·单片机·rust
飞凌嵌入式3 小时前
预告 | 飞凌嵌入式即将亮相2024慕尼黑上海电子展
嵌入式硬件·飞凌嵌入式
调光IC小雅3 小时前
【大功率汽车大灯升压方案】LED恒流驱动芯片FP7208升压车灯调光应用,PWM内部转模拟,调光深度1%,无频闪顾虑,低亮无抖动
单片机·汽车·智能家居
小小怪下士的编程小屋4 小时前
stm32中断
c语言·stm32·单片机·嵌入式硬件
m0_747124535 小时前
将QT移植到IMX6ULL开发板
linux·单片机·qt·imx6ull
ooolmf6 小时前
蓝牙模块的使用01,OOOLMF蓝牙模块HC05调试使用01AT设置从机,手机用软件对接
stm32·单片机·51单片机
岁月磨吾少年志8 小时前
【STM32】温湿度采集与OLED显示
stm32·单片机·嵌入式硬件
XD7429716368 小时前
【TB作品】atmega16 超声波倒车雷达,ATMEGA16单片机,Proteus仿真
单片机·proteus·超声波雷达
m0_749372178 小时前
7.1作业6
单片机