/*
* 立创开发板软硬件资料与相关扩展板软硬件资料官网全部开源
* 开发板官网:www.lckfb.com
* 技术支持常驻论坛,任何技术问题欢迎随时交流学习
* 立创论坛:https://oshwhub.com/forum
* 关注bilibili账号:【立创开发板】,掌握我们的最新动态!
* 不靠卖板赚钱,以培养中国工程师为己任
* Change Logs:
* Date Author Notes
* 2024-03-28 LCKFB-LP first version
*/
#include "bsp_DotMatrix.h"
#include "stdio.h"
#include "board.h"
/******************************************************************
* 函 数 名 称:MAX7219_GPIO_Init
* 函 数 说 明:初始化MAX7219引脚
* 函 数 形 参:无
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void MAX7219_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_MAX7219, ENABLE); // 使能GPIOB时钟
/* 配置GPIO */
GPIO_InitStructure.GPIO_Pin = GPIO_MAX7219_CLK|GPIO_MAX7219_DIN|GPIO_MAX7219_CS;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_MAX7219, &GPIO_InitStructure);
}
/******************************************************************
* 函 数 名 称:Write_Max7219_byte
* 函 数 说 明:向MAX7219写入字节
* 函 数 形 参:dat写入的数据
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void Write_Max7219_byte(uint8_t dat)
{
uint8_t i;
MAX7219_CS(0);
for(i=8;i>=1;i--)
{
MAX7219_CLK(0);
if( dat&0x80 )
{
MAX7219_DIN(1);
}
else
{
MAX7219_DIN(0);
}
dat=dat<<1;
MAX7219_CLK(1);
}
}
/******************************************************************
* 函 数 名 称:Write_Max7219
* 函 数 说 明:向MAX7219写入数据
* 函 数 形 参:address写入地址 dat写入数据
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void Write_Max7219(uint8_t address,uint8_t dat)
{
Write_Max7219_byte(address); //写入地址,即点阵行号1-8
Write_Max7219_byte(dat); //写入数据,即该行显示内容
}
/******************************************************************
* 函 数 名 称:Max7219_Lock
* 函 数 说 明:将更新的数据写入芯片
* 函 数 形 参:无
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void Max7219_Lock(void)
{
MAX7219_CS(1);
MAX7219_CS(0);
}
/******************************************************************
* 函 数 名 称:Max7219_display
* 函 数 说 明:4个点阵显示
* 函 数 形 参:show1第一个点阵显示内容 show2第二个 show3第三个 show4第四个
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void Max7219_display(uint8_t* show1, uint8_t* show2, uint8_t* show3, uint8_t* show4)
{
uint8_t i = 0;
for(i = 1; i < 9; i++ )//1~8行 进行更新
{
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(show1[i-1]); //第一个点阵
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(show2[i-1]); //第二个点阵
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(show3[i-1]); //第三个点阵
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(show4[i-1]); //第四个点阵
Max7219_Lock();//锁存显示数据
}
}
/******************************************************************
* 函 数 名 称:Write_Max7219_AllOff
* 函 数 说 明:控制第一片MAX7219的全部数码管全灭
* 函 数 形 参:address写入地址 dat写入数据
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void Write_Max7219_AllOff(void)
{
int i = 0;
for( i = 1; i < 9; i++ )//1~8行 进行更新
{
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(0x00); //全灭
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(0x00); //全灭
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(0x00); //全灭
Write_Max7219_byte(i); //写入地址,即行编号1-8
Write_Max7219_byte(0x00); //全灭
Max7219_Lock();//更新内容
}
}
/******************************************************************
* 函 数 名 称:MAX7219_Init
* 函 数 说 明:MAX7219初始化
* 函 数 形 参:无
* 函 数 返 回:无
* 作 者:LC
* 备 注:无
******************************************************************/
void MAX7219_Init(void)
{
unsigned int i = 0;
MAX7219_GPIO_Init();//引脚初始化
for( i = 0; i < 4; i++ )//设置4个点阵
{
Write_Max7219(0x09, 0x00); //译码方式:不进行译码
}
Max7219_Lock();//更新设置
for( i = 0; i < 4; i++ )//设置4个点阵
{
Write_Max7219(0x0a, 0x01); //亮度
}
Max7219_Lock();//更新设置
for( i = 0; i < 4; i++ )//设置4个点阵
{
Write_Max7219(0x0b, 0x07); //扫描界限;8个数码管显示
}
Max7219_Lock();//更新设置
for( i = 0; i < 4; i++ )//设置4个点阵
{
Write_Max7219(0x0c, 0x01); //掉电模式:0,普通模式:1
}
Max7219_Lock();//更新设置
for( i = 0; i < 4; i++ )//设置4个点阵
{
Write_Max7219(0x0f, 0x00); //显示测试:1;测试结束,正常显示:0
}
Max7219_Lock();//更新设置
}
/*
* 立创开发板软硬件资料与相关扩展板软硬件资料官网全部开源
* 开发板官网:www.lckfb.com
* 技术支持常驻论坛,任何技术问题欢迎随时交流学习
* 立创论坛:https://oshwhub.com/forum
* 关注bilibili账号:【立创开发板】,掌握我们的最新动态!
* 不靠卖板赚钱,以培养中国工程师为己任
* Change Logs:
* Date Author Notes
* 2024-03-28 LCKFB-LP first version
*/
#ifndef _BSP_DOTMATRIX_H_
#define _BSP_DOTMATRIX_H_
#include "stm32f10x.h"
#define RCC_MAX7219 RCC_APB2Periph_GPIOB
#define PORT_MAX7219 GPIOB
#define GPIO_MAX7219_CLK GPIO_Pin_15
#define GPIO_MAX7219_DIN GPIO_Pin_10
#define GPIO_MAX7219_CS GPIO_Pin_13
#define MAX7219_CLK(X) GPIO_WriteBit(PORT_MAX7219, GPIO_MAX7219_CLK, X?Bit_SET:Bit_RESET)
#define MAX7219_DIN(X) GPIO_WriteBit(PORT_MAX7219, GPIO_MAX7219_DIN, X?Bit_SET:Bit_RESET)
#define MAX7219_CS(X) GPIO_WriteBit(PORT_MAX7219, GPIO_MAX7219_CS, X?Bit_SET:Bit_RESET)
void Write_Max7219(uint8_t address,uint8_t dat);
void Write_Max7219_2(unsigned char address,unsigned char dat);
void Write_Max7219_AllOff(void);
void MAX7219_Init(void);
void Max7219_display(uint8_t* show1, uint8_t* show2, uint8_t* show3, uint8_t* show4);
#endif