【Proteus】LED点阵屏显示动画&图像

复制代码
#include <REGX51.H>
sbit RCLK=P3^5;
sbit SRCLK=P3^3;
sbit SER=P3^4;
void delay(unsigned char n)
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<120;j++);
	}
}
void _74HC595_writebyte(unsigned char byte)
{
	unsigned char i;
	for(i=0;i<8;i++)
	{
		SER=byte&(0x80>>i); //1000 0000->0100 0000->0010 0000
		SRCLK=1;
		SRCLK=0;
	}
	RCLK=1;
	RCLK=0;
}
void matrixled_show(unsigned char column,unsigned char Data)
{
	_74HC595_writebyte(Data);	
	P2=~(0x80>>column);//1000 0000
	delay(1);
	P2=0xff;//位清0
}
void main()
{
	SRCLK=0;
	RCLK=0;
	//_74HC595_writebyte(0xf0);//由实验现象可知,高位是1,低位是0
	while(1)
	{
		matrixled_show(0,0x80);//放在while外,不亮,因为delay很短,且位清零
		matrixled_show(1,0x40);	
		matrixled_show(2,0x20);
		matrixled_show(3,0x10);	
		matrixled_show(4,0x10);
		matrixled_show(5,0x10);
		matrixled_show(6,0x10);
		matrixled_show(7,0x10);
	}
}
复制代码
#include <REGX51.H>
sbit RCLK=P3^5;
sbit SRCLK=P3^3;
sbit SER=P3^4;
unsigned char  animation[]={
0xFF, 0x08, 0x08, 0x08, 0xFF, 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,
};
void delay(unsigned char n)
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<120;j++);
	}
}
void _74HC595_writebyte(unsigned char byte)
{
	unsigned char i;
	for(i=0;i<8;i++)
	{
		SER=byte&(0x80>>i); //1000 0000->0100 0000->0010 0000
		SRCLK=1;
		SRCLK=0;
	}
	RCLK=1;
	RCLK=0;
}
void matrixled_init()//点阵屏初始化
{
	SRCLK=0;
	RCLK=0;
}
void matrixled_show(unsigned char column,unsigned char Data)
{
	_74HC595_writebyte(Data);	
	P2=~(0x80>>column);//1000 0000
	delay(1);
	P2=0xff;//位清0
}
void main()
{
	unsigned char i,Offset=0,count=0;
	matrixled_init();
	//_74HC595_writebyte(0xf0);//由实验现象可知,高位是1,低位是0
	while(1)
	{
		for(i=0;i<8;i++)
		{
			matrixled_show(i,animation[i+Offset]);//放在while外,不亮,因为delay很短,且位清零
		}
		count++;
		if(count>10)  //相当于延时
		{
			count=0;
			Offset++;
			if(Offset>24)//32-8
			{
				Offset=0;
			}
		}
//		matrixled_show(0,animation[0]);//放在while外,不亮,因为delay很短,且位清零
//		matrixled_show(1,animation[1]);	
//		matrixled_show(2,animation[2]);
//		matrixled_show(3,animation[3]);	
//		matrixled_show(4,animation[4]);
//		matrixled_show(5,animation[5]);
//		matrixled_show(6,animation[6]);
//		matrixled_show(7,animation[7]);
	}
}
相关推荐
欢乐熊嵌入式编程11 分钟前
智能手表固件升级 OTA 策略文档初稿
嵌入式硬件·学习·智能手表
欢乐熊嵌入式编程18 分钟前
智能手表 MCU 任务调度图
单片机·嵌入式硬件·智能手表
【云轩】32 分钟前
电机密集型工厂环境下的无线通信技术选型与优化策略
经验分享·嵌入式硬件
sword devil9001 小时前
将arduino开发的Marlin部署到stm32(3D打印机驱动)
stm32·单片机·嵌入式硬件
GodKK老神灭1 小时前
STM32 变量存储
stm32·单片机·嵌入式硬件
木宁kk2 小时前
51单片机引脚功能概述
单片机·嵌入式硬件
JANYI20182 小时前
嵌入式MCU和Linux开发哪个好?
linux·单片机·嵌入式硬件
sword devil9003 小时前
Arduino快速入门
stm32·单片机·嵌入式硬件
GodKK老神灭4 小时前
STM32实现循环队列
stm32·单片机·嵌入式硬件
不脱发的程序猿6 小时前
从MCU到SoC的开发思维转变
单片机·嵌入式硬件