一下是程序源码:
/******点阵LED显示I LVOE U**************/
/**
*功能:点阵LED延时一秒显示I 心形 U(I LOVE YOU)
*作者:徐冉
*日期:2013-06-12
*备注:程序顺利调试成功
**/
/*************AT89C52-RC MCU*******************/
/**************51hei开发板********************/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
sbit din = P2^0;//数据输入端
sbit cs = P2^1;//片选端
sbit clk = P2^2; //时钟信号端
//字模取模编码
uchar code dis[][8] = {
{0x00,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00},// I
{0x00,0x6C,0xFE,0xFE,0x7C,0x38,0x10,0x00}, // 心形
{0x00,0xC3,0xC3,0xC3,0xC3,0xC3,0x7E,0x3C} // U
};
//delay:xms
void delay(uint xms)
{
uint x, y;
for(x = 0; x < xms; x++)
for(y = 0; y < 110; y++);
}
//写MAX7219字节
void write_byte(uchar dat)
{
uchar i = 0;
cs = 0;
for(i = 0; i < 8; i++)
{
clk = 0;
din = (dat & 0x80);
dat <<= 1;
clk = 1;
}
}
//写入MAX7219数据
void write_max7219(uchar address, uchar date)
{
cs = 0;
write_byte(address);//写地址
write_byte(date); //写入数据
cs = 1;
}
//MAX7219初始化
void max7219_init()
{
write_max7219(0x0c, 0x01);
write_max7219(0x09, 0x00);
write_max7219(0x0a, 0x04);
write_max7219(0x0b, 0x07);
write_max7219(0x0f, 0x00);
}
//主程序
void main(void)
{
uchar i, j;
max7219_init();
while(1)
{
for(j = 0; j < 3; j++)
{
for(i = 0; i < 8; i++)
{
write_max7219(i+1, dis[j][i]);
delay(1);
}
delay(1000);
}
}