芯片开放社区(OCC)面向广大开发者推出应用实战系列内容,通过分享开发者实战开发案例,总结应用开发经验,梳理开发中的常见问题及解决方案,为后续参与的开发者提供更多参考与借鉴。
本文是关于开发者 乘简 基于BL606P-DVK开发板实战开发的系列文章中的一篇,主要介绍了驱动MAX7219点阵模组,后面还会持续更新社区开发者的测评内容,敬请期待!
01 硬件部分
我买了一款MAX7219芯片的点阵模块,8个8x8连在一起的模块,只需要3个GPIO口即可驱动,可以显示两个16x16点阵的汉字
连线图:
GPIO2连入DIN,GPIO3连入CS,GPIO4连入CLK,VCC接5V,GND接GND
main.c的代码:
#include
#include
#include
#include
#include "app_main.h"
#include "max7219.h"
int main(int argc, char *argv[])
{
board_yoc_init();
max7219_Init();
printf("
app start core clock %d........
", soc_get_cur_cpu_freq());
Display();
return 0;
}
max7219.h
#ifndef _MAX7219_H_
#define _MAX7219_H_
#include
#include
#include
#define MODS_7219 8//点阵模块数量
void max7219_Init();
void Display();
#endif
max7219.c
#include "max7219.h"
gpio_dev_t gpio_din = { GPIO_PIN_2, OUTPUT_PUSH_PULL, (void*)0 };
gpio_dev_t gpio_cs= { GPIO_PIN_3, OUTPUT_PUSH_PULL, (void*)0 };
gpio_dev_t gpio_clk = { GPIO_PIN_4, OUTPUT_PUSH_PULL, (void*)0 };
#define din_l() hal_gpio_output_low(&gpio_din)
#define din_h() hal_gpio_output_high(&gpio_din)
#define clk_l() hal_gpio_output_low(&gpio_clk)
#define clk_h() hal_gpio_output_high(&gpio_clk)
#define cs_l() hal_gpio_output_low(&gpio_cs)
#define cs_h() hal_gpio_output_high(&gpio_cs)
uint8_t FONT8[][8]={
{0x38,0x44,0x44,0x44,0x44,0x44,0x44,0x38},/*"0",0*/
{0x10,0x30,0x10,0x10,0x10,0x10,0x10,0x38},/*"1",1*/
{0x38,0x44,0x44,0x08,0x10,0x20,0x40,0x7C},/*"2",2*/
{0x38,0x44,0x04,0x18,0x04,0x04,0x44,0x38},/*"3",3*/
{0x08,0x18,0x18,0x28,0x48,0x7C,0x08,0x1C},/*"4",4*/
{0x7C,0x40,0x40,0x78,0x44,0x04,0x44,0x38},/*"5",5*/
{0x18,0x24,0x40,0x58,0x64,0x44,0x44,0x38},/*"6",6*/
{0x3C,0x04,0x08,0x08,0x10,0x10,0x10,0x10},/*"7",7*/
{0x38,0x44,0x44,0x38,0x44,0x44,0x44,0x38},/*"8",8*/
{0x38,0x44,0x44,0x4C,0x34,0x04,0x48,0x30},/*"9",9*/
};
//写1个字节
void max7219_writebyte(uint8_t dat)
{
uint8_t i;
for(i=0;i<8;i++){
clk_l();
if(dat & 0x80)din_h();else din_l();
dat<<=1;
clk_h();
}
}
//写入配置数据
void max7219_writeset(uint8_t address, uint8_t dat)
{
uint8_t i;
cs_l();
for(i=0;i
02 演示效果
全部0条评论
快来发表一下你的评论吧 !