材料:MAX7219点阵模块 STM32f103c8t6最小系统板
使用CUBEMX配置串行输出(SPI)
?PA1和PA3没有使用到忽略!!这里我是用的是SPI2.
点阵驱动程序:
?
#include "8x8led.h"
#include "spi.h"
uint8_t code_table[]=
{0x00,0x6C,0x92,0x82,0x44,0x28,0x10,0x00};
void Write_Byte(uint8_t DATA)
{
HAL_GPIO_WritePin(GPIOA,PIN_CS,GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2,&DATA,1,0xfff);
}
void Write_Max7219(uint8_t addr,uint8_t dat)
{
Write_Byte(addr);
Write_Byte(dat);
HAL_GPIO_WritePin(GPIOA,PIN_CS,GPIO_PIN_SET);
}
void Init_Max7219(void)
{
Write_Max7219(0x09, 0x00);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x00);
}
main函数里在while(1)前添加下面这段代码即可
/* USER CODE BEGIN 2 */
HAL_Delay(50);
Init_Max7219();
for(i=1;i<9;i++)
{
Write_Max7219(i,code_table[i-1]);
}
/* USER CODE END 2 */
程序压缩包链接:https://pan.baidu.com/s/1gpcoirRwXM3Nl8vShIICzg
提取码:28w8
|