本程序所用的原理图下载: 点这里 ,单片机芯片使用的stc89c52;找到点阵部分的原理图即可.这是一整个单片机开发板的电路图其他的忽略
以下是程序源码:
/**
*功能:矩形收缩闪烁
*作者:徐冉
*日期:2013-06-26-22:13
*备注:程序调试成功
**/
/********AT89C52-RC MCU****************/
/*************51hei开发板**************/
#include <reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;
sbit din = P2^0;
sbit cs = P2^1;
sbit clk = P2^2;
uchar code dis[][8] ={
{0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0xFF},
{0x00,0x7E,0x42,0x42,0x42,0x42,0x7E,0x00},
{0x00,0x00,0x3C,0x24,0x24,0x3C,0x00,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00}
};
//延时xms
void delay(uint xms)
{
uint x, y;
for(x = xms; x > 0; x--)
for(y = 110; y > 0; y--);
}
//写一个字节
void write_byte(uchar date)
{
uchar i, temp;
temp = date;
cs = 0; //选通MAX7219
for(i = 0; i < 8; i++)
{
clk = 0;
din = temp & 0x80;
temp <<= 1;
clk = 1; //时钟上升沿脉冲
}
}
//写MAX7219
void write_max7219(uchar address, uchar date)
{
cs = 0;//选通MAX7219
write_byte(address);
write_byte(date);
cs = 1;
}
//MAX7219初始化
void max7219_init()
{
write_max7219(0x0c, 0x01);
write_max7219(0x09, 0x00);
write_max7219(0x0a, 0x05);
write_max7219(0x0b, 0x07);
write_max7219(0x0f, 0x00);
}
//主程序
void main(void)
{
uchar i, j;
delay(50);//稍作延时
max7219_init();
while(1)
{
for(i = 0; i < 4; i++)
{
for(j = 0; j < 8; j++)
{
write_max7219(j+1, dis[i][j]);//写入MAX7219数据
}
delay(100); //延时100ms
}
}
}