//这是我参照网上教程写的基于51单片机的MAX72198*8点阵模块程序,楼主可以参考一下(显示的图像是一个行走的人)
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit max7219_pindin=P0^0;
sbit max7219_pincs=P0^1;
sbit max7219_pinclk=P0^2;
uchar code disp[]={ 0x00,0x00,0x0C,0x44,0x3F,0x24,0x26,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x24,0x4C,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x64,0x0C,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x44,0x0C,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x64,0x0C,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x24,0x4C,0x00,
0x00,0x00,0x0C,0x44,0x3F,0x24,0x26,0x00};
void delay(uint z)
{
uint y,x;
for(y=z;y>0;y--)
for(x=114;x>0;x--);
}
void write_max7219_byte(uchar dat)
{
uchar i;
for(i=8;i>0;i--)
{
max7219_pinclk=0;
max7219_pindin=dat&0x80;
dat=dat<<1;
max7219_pinclk=1;
}
}
void write_max7219(uchar address,uchar dat)
{
max7219_pincs=0;
write_max7219_byte(address);
write_max7219_byte(dat);
max7219_pincs=1;
}
void max7219_init()
{
write_max7219(0x09,0x00);
write_max7219(0x0a,0x03);
write_max7219(0x0b,0x07);
write_max7219(0x0c,0x01);
write_max7219(0x0f,0x00);
}
void main()
{
uchar i,j=1;
max7219_init();
while(1)
{
for(i=0;i<9;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=8;i<17;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=16;i<25;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=24;i<33;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=32;i<41;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=40;i<49;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
delay(1000);
for(i=48;i<57;i++)
{
write_max7219(j,disp[i]);
j++;
if(j==9)
j=0;
}
}
} |