单片机控制点阵LED一秒刷新显示I心形U
下面是程序源码:
/******点阵LED刷新显示I LVOE U**************/
/**
*功能:点阵LED一秒刷新显示I 心形 U(I LOVE YOU)
*作者:徐冉
*日期:2013-06-14-22:44
*备注:程序已调试成功
**/
/*************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 table[5][8] = {
{0x00,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00}, //I
{0x00,0x66,0xFF,0xFF,0xFF,0x7E,0x3C,0x18}, //心
{0x00,0x66,0x66,0x66,0x66,0x7E,0x3C,0x00}, //U
};
uchar i, j;
uint counter;
//写字节
void write_byte(uchar date)
{
uchar i;
cs = 0;
for(i = 0; i < 8; i++)
{
clk = 0;
din = date & 0x80;
date <= 1;
clk = 1;
}
}
//写MAX7219
void write_max7219(uchar add, uchar date)
{
cs = 0;
write_byte(add);
write_byte(date);
cs = 1;
}
//MAX7219初始化
void max7219_init()
{
write_max7219(0x0c, 0x01);//正常模式
write_max7219(0x09, 0x00);//译码模式
write_max7219(0x0a, 0x08);//亮度控制
write_max7219(0x0b, 0x07);//扫描模式
write_max7219(0x0f, 0x00);//显示检测
}
//定时器T0初始化
void timer0_init()
{
TMOD = 0x01;
TH0 = 0x94; //定时30ms
TL0 = 0x00;
TR0 = 1;
EA = 1;
ET0 = 1;
}
//主程序
void main(void)
{
max7219_init();
timer0_init();
while(1)
{
if(i >= 8)
{
i = 0;
}
if(counter == 40)
{
counter = 0;
j++;
if(j >= 3)
{
j = 0;
}
}
write_max7219(i+1, table[j][i]);
}
}
//中断服务程序
void timer0_int() interrupt 1
{
TH0 = 0x94;
TL0 = 0x00;
i++;
counter++;
}
单片机控制点阵LEDstc89c5 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)