1 功能:
(1)静态显示:显示一个笑脸;
(2)动态显示:a,移动显示“HELLO!”,b,显示笑脸哭脸的变化;
2 原理
3 框图
4 硬件原理图
5 软件设计
5.1 静态显示源程序
(1)主函数
#include
#include "delay100ms.h"
sbit SER = P3^4; //74HC595的串行数据输入DS
sbit RCK = P3^5; //74HC595的移位寄存器SH_CP
sbit SCK = P3^6; //74HC595的锁存寄存器ST_CP
#define matrixled_col P0
//笑脸的数据,列向取模
unsigned char code disp[]={0x3C,0x42,0xA9,0x85,0x85,0xA9,0x42,0x3C};
/**
* @brief:74HC595写入一个字节
* @param:需要写入的字节
* @retval:无
*/
void hc74595_wrbyte(unsigned char byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
SER = byte & (0x80>>i);
SCK = 1;
SCK = 0;
}
RCK = 1;
RCK = 0;
}
/**
* @brief:LED点阵显示屏显示1列数据
* @param: column 选择要显示的列,范围0-7,0在最左边
* @param: dat 选择列显示的数据,高位在上,1为亮,0为灭
* @retval:无
*/
void matrixled_showcol(unsigned char column,dat)
{
hc74595_wrbyte(dat);
matrixled_col = ~(0x80>>column);
delay100ms(1);
matrixled_col = 0xff;
}
void main()
{
unsigned char i;
SCK = 0;
RCK = 0;
while(1)
{
for(i=0;i<8;i++)
{
matrixled_showcol(i,disp[i]);
}
}
}
(2)延时函数及头文件
#include
#include
void delay100ms(unsigned int x) //@11.0592MHz
{
unsigned char i;
while(x--)
{
_nop_();
i = 43;
while (--i);
}
}
#ifndef _delay100ms_h_
#define _delay100ms_h_
void delay100ms(unsigned int x);
#endif
5.2 动态显示
5.2.1 移动显示HELLO!!
(1)主函数
#include
#include "matrix_8x8led.h"
unsigned char code disp[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //0-7,空白区域
0x00,0x7F,0x08,0x08,0x7F,0x00,0x7F,0x49, //8-39,HELLO!!
0x49,0x49,0x00,0x7F,0x49,0x49,0x49,0x00,
0x7F,0x01,0x01,0x01,0x00,0x7F,0x41,0x41,
0x7F,0x00,0x00,0x7B,0x7B,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //40-47,空白区域
};
void main()
{
unsigned char i;
unsigned char offset=0; //偏移量
unsigned char count=0; //延时计数
matrix_8x8led_init(); //LED点阵初始化
while(1)
{
for(i=0;i<8;i++) //循环8次,显示8列数据,即一帧数据
{
matrix_8x8led_showcol(i,disp[i+offset]);
count++; //计数延时,影响数据移动快慢
if(count>20)
{
count = 0;
offset++;
if(offset>40)
offset=0;
}
}
}
}
(2)LED点阵驱动函数
#include
#include "delay100ms.h"
#define matrixled_col P0
sbit SER = P3^4; //74HC595的串行数据输入DS
sbit RCK = P3^5; //74HC595的移位寄存器SH_CP
sbit SCK = P3^6; //74HC595的锁存寄存器ST_CP
/**
* @brief:74HC595写入一个字节
* @param:需要写入的字节
* @retval:无
*/
void hc74595_wrbyte(unsigned char byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
SER = byte & (0x80>>i);
SCK = 1;
SCK = 0;
}
RCK = 1;
RCK = 0;
}
/**
* @brief: LED点阵显示屏初始化
* @param: 无
* @retval:无
*/
void matrix_8x8led_init()
{
SCK = 0;
RCK = 0;
}
/**
* @brief:LED点阵显示屏显示1列数据
* @param: column 选择要显示的列,范围0-7,0在最左边
* @param: dat 选择列显示的数据,高位在上,1为亮,0为灭
* @retval:无
*/
void matrix_8x8led_showcol(unsigned char column,dat)
{
hc74595_wrbyte(dat);
matrixled_col = ~(0x80>>column);
delay100ms(10);
matrixled_col = 0xff;
}
#ifndef _matrix_8x8led_h_
#define _matrix_8x8led_h_
void matrix_8x8led_init();
void matrix_8x8led_showcol(unsigned char column,dat);
#endif
(3)延时函数:略
5.2.2 笑脸哭脸变化
(1)主函数
#include
#include "matrix_8x8led.h"
unsigned char code disp[]={
0x3C,0x42,0xA9,0x85,0x85,0xA9,0x42,0x3C, //笑脸
0x3C,0x42,0xA1,0x85,0x85,0xA1,0x42,0x3C, //一般
0x3C,0x42,0xA5,0x89,0x89,0xA5,0x42,0x3C //哭脸
};
void main()
{
unsigned char i;
unsigned char offset=0; //偏移量
unsigned char count=0; //延时计数
matrix_8x8led_init(); //LED点阵初始化
while(1)
{
for(i=0;i<8;i++) //循环8次,显示8列数据,即一帧数据
{
matrix_8x8led_showcol(i,disp[i+offset]);
count++; //计数延时,影响数据移动快慢
if(count>20)
{
count = 0;
offset+=8; //偏移+8,切换下一帧画面
if(offset>16)
offset=0;
}
}
}
}