【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]);
	}
}
相关推荐
晶振厂家-晶发电子3 天前
晶振在5G时代的角色:高精度时钟的核心支撑
单片机·嵌入式硬件·5g·晶振·电子元器件·晶振知识
F137298015573 天前
WD5030A 芯片,12V降5V,输出电流12A,电路设计
stm32·单片机·嵌入式硬件·汽车·51单片机
小莞尔3 天前
【51单片机】【protues仿真】基于51单片机的篮球计时计分器系统
c语言·stm32·单片机·嵌入式硬件·51单片机
三佛科技-187366133973 天前
分享机械键盘MCU解决方案
单片机·嵌入式硬件·计算机外设
李永奉3 天前
51单片机-使用IIC通信协议实现EEPROM模块教程
单片机·嵌入式硬件·51单片机
工大一只猿3 天前
51单片机学习
嵌入式硬件·学习·51单片机
小莞尔3 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
风_峰3 天前
Ubuntu Linux SD卡分区操作
嵌入式硬件·ubuntu·fpga开发
bing_feilong3 天前
STM32精准控制水流
单片机·嵌入式硬件
Hello_Embed3 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件