本程序所用的原理图下载:点这里,单片机芯片运用的stc89c52;找到点阵部分的原理图即可.这是一整个单片机开发板的电路图其他的疏忽
以下是程序的源代码:
/****************点阵LED******************/
/**
*功用:点阵LED活动显现5,4,3,2,1后,会一向显现闪烁的矩形
*作者:徐冉
*日期:2013-06-10
*补白:现已经过调试
**/
/*****************AT89C52-RC MCU****************/
/***********************51hei开发板**************/
#include
typedef unsigned int uint;//数据类型声明优于#define
typedef unsigned char uchar;
sbit max7219_din = P2^0;//MAX7219串行数据输入端
sbit max7219_cs = P2^1; //MAX7219片选端
sbit max7219_clk = P2^2;//MAX7219时钟端
//显现取模编码表
uchar codedis[11][8] = {
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
{0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff},
{0,0x7e,0x42,0x42,0x42,0x42,0x7e,0},
{0,0,0x3c,0x24,0x24,0x3c,0,0},
{0,0,0,0×18,0x18,0,0,0,},
{0,0,0,0,0,0,0,0}
};
//毫秒延时程序
void delay(uint xms)
{
uint x, y;
for(x = 0; x < xms; x++)
for(y = 0; y < 110; y++);
}
//写MAX7219字节数据
void write_byte_max7219(uchar dat)
{
uchar i;
max7219_cs = 0;//选通max7219
for(i = 0; i < 8; i++)
{
max7219_clk = 0;
max7219_din = dat & 0x80;
dat <<= 1;
max7219_clk = 1;
}
}
//写数据到MAX7219
void write_max7219(uchar address, uchar dat)
{
max7219_cs = 0;
write_byte_max7219(address);
write_byte_max7219(dat);
max7219_cs = 1;
}
//MAX7219初始化
void max7219_init()
{
//译码形式
write_max7219(0x09, 0x00);
//亮度形式
write_max7219(0x0a, 0x06);//亮度为13/32
//设置掉电形式
write_max7219(0x0c, 0x01);
//扫描形式0~7
write_max7219(0x0b, 0x07);
//显现检测
write_max7219(0x0f, 0x00);
}
//主程序
void main(void)
{
uchar i = 0, j = 0;
delay(50);
max7219_init();
while(1)
{
//活动显现数字
for(i = 0; i < 5; i++)
{
for(j = 0; j < 8; j++)
{ //此处的数据有必要从0x01开端写,不然写不成功;
write_max7219(j+1, dis[j]);
}
delay(500);
}
//矩形闪烁
while(1)
{
for(i = 5; i < 10; i++)
{
for(j = 0; j < 8; j++)
{ //此处的数据有必要从0x01开端写,不然写不成功;
write_max7219(j+1,dis[j]);
}
delay(100);
}
}
}
}