[AT32F421 review] + Display driver for digital tube module
[Copy link]
This post was last edited by jinglixixi on 2021-4-30 08:42
Last time we introduced a digital tube display module with parallel transmission. This time we will introduce another digital tube display module that transmits data in serial mode, as shown in Figure 1.
In addition to the power pin, the module has 3 pins, namely the DIN data pin, the CLK clock pin and the CS selection pin.
Figure 1 Digital tube module
The display effect of the digital tube is shown in Figure 2. If the pin connection relationship is modified, the digital tube module can be directly connected to the Arduino interface for use.
Figure 2 Digital tube module
The relevant procedures are as follows:
#include <stdio.h>
#include "at32f4xx.h"
#include "at32_board.h"
#define SMG_CLK_Set() GPIOB->BSRE = GPIO_Pins_9
#define SMG_CLK_Clr() GPIOB->BRE = GPIO_Pins_9
#define SMG_DIN_Set() GPIOB->BSRE = GPIO_Pins_8
#define SMG_DIN_Clr() GPIOB->BRE = GPIO_Pins_8
#define SMG_CS_Set() GPIOB->BSRE = GPIO_Pins_10
#define SMG_CS_Clr() GPIOB->BRE = GPIO_Pins_10
void AT_eval_smg_init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_10|GPIO_Pins_8|GPIO_Pins_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
SMG_CLK_Set();
SMG_DIN_Set();
SMG_CS_Set();
}
void Write_Max7219_byte(uint8_t DATA)
{
uint8_t i;
SMG_CS_Clr();
for(i=8;i>=1;i--)
{
SMG_CLK_Clr();
if(DATA&0x80)
{
SMG_DIN_Set();
}
else
{
SMG_DIN_Clr();
}
DATA=DATA<<1;
SMG_CLK_Set();
}
}
void Init_MAX7219(void)
{
Write_Max7219(0x09, 0xff);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x01);
}
int main(void)
{
AT32_Board_Init();
AT_eval_smg_init();
Init_MAX7219();
Delay_ms(2000);
Write_Max7219(0x0f,0x00);
Write_Max7219(1,8);
Write_Max7219(2,7);
Write_Max7219(3,6);
Write_Max7219(4,5);
Write_Max7219(5,4);
Write_Max7219(6,3);
Write_Max7219(7,2);
Write_Max7219(8,1);
for(;;)
{
AT32_LEDn_Toggle(LED2);
Delay_ms(200);
AT32_LEDn_Toggle(LED3);
Delay_ms(200);
AT32_LEDn_Toggle(LED4);
Delay_ms(200);
}
}
Figure 3 Digital tube module
The pin connections and high and low level output settings to achieve the effect of Figure 3 are as follows:
DIN--- PA5
CS---PA6
CLK---PA7
#define SMG_CLK_Set() GPIOA->BSRE = GPIO_Pins_7
#define SMG_CLK_Clr() GPIOA->BRE = GPIO_Pins_7
#define SMG_DIN_Set() GPIOA->BSRE = GPIO_Pins_5
#define SMG_DIN_Clr() GPIOA->BRE = GPIO_Pins_5
#define SMG_CS_Set() GPIOA->BSRE = GPIO_Pins_6
#define SMG_CS_Clr() GPIOA->BRE = GPIO_Pins_6
|