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博客

相关推荐
欢乐熊嵌入式编程1 小时前
智能手表固件升级 OTA 策略文档初稿
嵌入式硬件·学习·智能手表
欢乐熊嵌入式编程1 小时前
智能手表 MCU 任务调度图
单片机·嵌入式硬件·智能手表
【云轩】1 小时前
电机密集型工厂环境下的无线通信技术选型与优化策略
经验分享·嵌入式硬件
sword devil9002 小时前
将arduino开发的Marlin部署到stm32(3D打印机驱动)
stm32·单片机·嵌入式硬件
GodKK老神灭2 小时前
STM32 变量存储
stm32·单片机·嵌入式硬件
木宁kk2 小时前
51单片机引脚功能概述
单片机·嵌入式硬件
JANYI20183 小时前
嵌入式MCU和Linux开发哪个好?
linux·单片机·嵌入式硬件
sword devil9004 小时前
Arduino快速入门
stm32·单片机·嵌入式硬件
GodKK老神灭4 小时前
STM32实现循环队列
stm32·单片机·嵌入式硬件
不脱发的程序猿6 小时前
从MCU到SoC的开发思维转变
单片机·嵌入式硬件