51单片机-点阵屏-鸡你太美
#include <REGX52.H>
sbit RCK = P3 ^ 5;//RCLK
sbit SCK = P3 ^ 6;//SRCL
sbit SER = P3 ^ 4;//SER
//延时xms
void DelayXms(unsigned int xms)//@11.0592MHz
{
unsigned char i, j;
while (xms) {
i = 2;
j = 199;
do {
while (--j)
;
} while (--i);
xms--;
}
}
void _74HC595_WriteByte(unsigned char Byte)
{
unsigned char i=0;
for(i=0;i<8;i++) //Byte是要写入移动寄存器的数据
{ //这里用到与操作符来获取数据中的某一位
SER=Byte&(0x80>>i); //用SER接受对应的每一位(一位一位地挪进移位寄存器中)从高位到低位
SCK=1; //把数据取到SER内时即可把移位寄存器置1,给到上升沿数据就会在移位寄存器中移动一位
SCK=0; //SCK恢复下降沿,保证下一次循环的移动
}
RCK=1; //循环结束后RCK置高电位即把移位寄存器内的数据并行输出到存储寄存器中
RCK=0; //记得把RCK置零,方便下次移动
}
void MatrixLED_ShowColumn(unsigned char Column,unsigned char Data)
{
_74HC595_WriteByte(Data); //把数据写入存储寄存器中
P0=~(0x80>>Column); //传入的列号通过对0x80的右移实现对P0的列数选定
//下面是消影的操作,避免在后面的动态显示中重影过多
DelayXms(1);
P0=0xFF;
}
void MatrixLED_Init(){
SCK=0;
RCK=0;
}
//显示我鸽鸽的铁山靠
unsigned char code IronMountainAnimation[]={
0x00,0x00,0x1B,0x3C,0xF8,0xFC,0x3B,0x00,0x00,0x1B,0x3C,0xFC,0xFF,0x3A,0x00,0x00,
0x00,0x00,0x0B,0x1C,0x7C,0x7E,0x1B,0x00,0x00,0x1B,0x3C,0xFC,0xFF,0x3A,0x00,0x00,};
//打篮球
unsigned char code BasketballAnimation[]={
0x00,0x0E,0x1B,0x7F,0x7F,0x1B,0x0E,0x00,
0x00,0x04,0x0C,0x18,0x7F,0x7F,0x1B,0x0E,
0x00,0x08,0x0C,0x05,0x7F,0x7F,0x1E,0x0C,
0xC0,0x00,0x41,0x22,0x1A,0x7C,0x7D,0x1A,
0x00,0x60,0x61,0x12,0x0A,0x7E,0x7F,0x08,
0x00,0x06,0x0E,0x08,0x0B,0x3E,0x3E,0x0B,
0x00,0x03,0x0B,0x08,0x0B,0x3E,0x3E,0x0B,
0x00,0x06,0x0E,0x08,0x09,0x3F,0x3E,0x0B,
0x00,0x0E,0x13,0x7E,0x7E,0x1F,0x0E,0x00,
0x08,0x13,0x7E,0x7E,0x12,0x1D,0x0C,0x00,
0x09,0x12,0x7E,0x7F,0x10,0x13,0x03,0x00,
0x09,0x12,0x7E,0x7F,0x10,0x1C,0x0C,0x00,
0x00,0x0C,0x15,0x7E,0x7E,0x17,0x0E,0x00,
0x00,0x30,0x38,0x0D,0x7E,0x7F,0x1D,0x08,
0xC0,0xC0,0x30,0x1B,0x7C,0x7F,0x08,0x00,
0x00,0x00,0x37,0xF8,0xFA,0x34,0x00,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1A,0x01,0x00,
0x00,0x00,0x09,0x1E,0x7C,0x7F,0x18,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1B,0x00,0x00,
0x00,0x00,0x09,0x1E,0x7C,0x7F,0x18,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1B,0x00,0x00,
0x08,0x10,0x16,0x7C,0x7F,0x10,0x08,0x00,
0x00,0x10,0x13,0x7C,0x7E,0x18,0x00,0x00,
0x00,0x08,0x13,0x7C,0x7F,0x10,0x10,0x00,
0x00,0x08,0x12,0xFC,0xFD,0x3A,0x00,0x00,
0x00,0x08,0x12,0xFC,0xFC,0x22,0x10,0x00,
0x00,0x00,0x61,0x12,0x7C,0x7F,0x10,0x60,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,};
//坤坤矩阵
unsigned char code DH[]=
{
0x00,0x0E,0x1B,0x7F,0x7F,0x1B,0x0E,0x00,
0x00,0x04,0x0C,0x18,0x7F,0x7F,0x1B,0x0E,
0x00,0x08,0x0C,0x05,0x7F,0x7F,0x1E,0x0C,
0xC0,0x00,0x41,0x22,0x1A,0x7C,0x7D,0x1A,
0x00,0x60,0x61,0x12,0x0A,0x7E,0x7F,0x08,
0x00,0x06,0x0E,0x08,0x0B,0x3E,0x3E,0x0B,
0x00,0x03,0x0B,0x08,0x0B,0x3E,0x3E,0x0B,
0x00,0x06,0x0E,0x08,0x09,0x3F,0x3E,0x0B,
0x00,0x0E,0x13,0x7E,0x7E,0x1F,0x0E,0x00,
0x08,0x13,0x7E,0x7E,0x12,0x1D,0x0C,0x00,
0x09,0x12,0x7E,0x7F,0x10,0x13,0x03,0x00,
0x09,0x12,0x7E,0x7F,0x10,0x1C,0x0C,0x00,
0x00,0x0C,0x15,0x7E,0x7E,0x17,0x0E,0x00,
0x00,0x30,0x38,0x0D,0x7E,0x7F,0x1D,0x08,
0xC0,0xC0,0x30,0x1B,0x7C,0x7F,0x08,0x00,
0x00,0x00,0x37,0xF8,0xFA,0x34,0x00,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1A,0x01,0x00,
0x00,0x00,0x09,0x1E,0x7C,0x7F,0x18,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1B,0x00,0x00,
0x00,0x00,0x09,0x1E,0x7C,0x7F,0x18,0x00,
0x00,0x00,0x1B,0x7C,0x7C,0x1B,0x00,0x00,
0x08,0x10,0x16,0x7C,0x7F,0x10,0x08,0x00,
0x00,0x10,0x13,0x7C,0x7E,0x18,0x00,0x00,
0x00,0x08,0x13,0x7C,0x7F,0x10,0x10,0x00,
0x00,0x08,0x12,0xFC,0xFD,0x3A,0x00,0x00,
0x00,0x08,0x12,0xFC,0xFC,0x22,0x10,0x00,
0x00,0x00,0x61,0x12,0x7C,0x7F,0x10,0x60,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
0x00,0x00,0x20,0x11,0x12,0x7C,0x7E,0x19,
0x00,0x00,0x00,0x31,0x0A,0x7C,0x7E,0x0D,
};
void main()
{
unsigned char i, offset = 0, Count = 0;
MatrixLED_Init();
while (1)
{
for (i = 0; i < 8; i++)
{
MatrixLED_ShowColumn(i, DH[i + offset]);
}
Count++;
if (Count > 25)
{
Count = 0;
offset += 8;
if (offset > 255) // 动画结束后重置offset
{
offset = 0;
}
}
}
}