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

时间:2024-04-18 09:03:51

#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]);
	}
}