一、硬件介绍
如下图所示,此点阵屏为16x24分辨率,通过5个74HC595进行驱动,74HC595可以级联,控制引脚为3个,分别为SH、ST和DS,通过三个引脚即可驱动整个点阵屏。
硬件原理图:
二、开发板和点阵屏引脚连接
引脚连接如下:
ST----PD13
SH----PD14
DS----PD15
#define _74HC595_SH_RCC RCU_GPIOD
#define _74HC595_SH_PORT GPIOD
#define _74HC595_SH_PIN GPIO_PIN_14
#define _74HC595_ST_RCC RCU_GPIOD
#define _74HC595_ST_PORT GPIOD
#define _74HC595_ST_PIN GPIO_PIN_13
#define _74HC595_DS_RCC RCU_GPIOD
#define _74HC595_DS_PORT GPIOD
#define _74HC595_DS_PIN GPIO_PIN_15
三、软件实现
1. 595发送一个字节
通过这个函数可以给595发送一个字节的数据
/********************************************
@功能: 74HC595初始化
@日期:2022-11-25 20:51
@作者:lengyuefeng
@说明:
@参数: byte:要发送的字节
@返回值: 无
*********************************************/
static void _74HC595_sendByte(uint8_t mode,uint8_t byte)
{
uint8_t i;
for(i = 0; i < 8; i++)
{
_74HC595_SH_WRITE(0); // 移位
if(mode == 1)
{
/* 先发高位 */
if(byte & 0x80)
_74HC595_DS_WRITE(1);
else
_74HC595_DS_WRITE(0);
byte <<= 1;
}else
{
// 1111 1101
/* 先发高位 */
if(byte & 0x01)
_74HC595_DS_WRITE(1);
else
_74HC595_DS_WRITE(0);
byte >>= 1;
}
_74HC595_DELAY_US(2);
_74HC595_SH_WRITE(1); //移位 时钟上升沿拷贝
_74HC595_DELAY_US(2);
}
}
2. 刷新点阵
通过这个函数去刷新点阵,每当需要改变点阵屏内容时,需要调用一下。
void _74HC595_refresh(void)
{
static uint8_t step = 0;
_74HC595_sendByte(0,0xff);
_74HC595_sendByte(0,0xff);
_74HC595_sendByte(0,latticeBuf[step][2]);
_74HC595_sendByte(0,latticeBuf[step][1]);
_74HC595_sendByte(0,latticeBuf[step][0]);
_74HC595_sendByte(1,rowSelectBuf[step] & 0xff);
_74HC595_sendByte(1,((rowSelectBuf[step]&0xff00) >> 8));
_74HC595_ST_WRITE(1);
_74HC595_DELAY_US(2);
_74HC595_ST_WRITE(0);
step ++;
if(step == 16)
{
step = 0;
}
}
3. 滚动显示汉字
通过这个函数可以实现滚动显示汉字,滚动显示字数可控制。
void _74HC595_draw16X16Chinese(void)
{
static uint8_t flag = 0;
static uint8_t step = 0;
static uint8_t aaa = 0;
static uint8_t bbb =0 ;
static uint8_t temp[16][2] = {0};
static uint8_t num = 1;
if(flag == 0)
{
flag = 1;
for(uint8_t i = 0; i < 16; i++)
{
latticeBuf[i][0] = 0xff;
latticeBuf[i][1] = codebuf[0][i][0];
latticeBuf[i][2] = codebuf[0][i][1];
temp[i][0] = codebuf[1][i][0];
temp[i][1] = codebuf[1][i][1];
}
}else
{
if(bbb < 8)
{
aaa = (temp[step][0] >> 7);
temp[step][0] <<= 1;
}
else
{
aaa = temp[step][1] >> 7;
temp[step][1] <<= 1;
}
if(step >= 16)
{
}else
{
latticeBuf[step][0] = (latticeBuf[step][0] << 1) | ((latticeBuf[step][1] >> 7));
latticeBuf[step][1] = (latticeBuf[step][1] << 1) | ((latticeBuf[step][2] >> 7));
latticeBuf[step][2] = (latticeBuf[step][2] << 1) | aaa;
}
}
if(++step >= 16)
{
delay_ms(1);
step = 0;
bbb++;
if(bbb >= 16)
{
bbb = 0;
num ++;
if(num == 9)
num = 0;
for(uint8_t i = 0; i < 16; i++)
{
temp[i][0] = codebuf[num][i][0];
temp[i][1] = codebuf[num][i][1];
}
}
}
}
原作者:兆易创新GD32 MCU 卢阿涛
|