[AT32F421 Review] + Digital tube module and automatic counting display
[Copy link]
This post was last edited by jinglixixi on 2021-4-17 11:59
Digital tubes are often used to display data in industrial sites. The main reason is that they have high display brightness, low cost and are relatively durable.
Usually for ease of use, you can directly purchase the functional modules of the digital tube. Such modules can be divided into two categories, one is a parallel data transmission method, and the other is a serial data transmission method.
Here we introduce a digital tube module with parallel transmission mode, as shown in Figure 1. This module has been configured with current limiting resistors and drivers for each display bit, so when using it, it can be directly connected to the relevant pins of the development board.
What is more interesting is that the module only provides a power supply VCC pin, but no GND pin. Among them, D1~D4 are position control pins, and A~DP are segment control pins.
Figure 1 Digital tube module
Taking the automatic counting display of a 2-digit value as an example, the display effect is shown in Figure 2.
Figure 2 Counting display effect
Since the module transmits data in parallel and the pin arrangement of the development board is scattered, the traditional data output method of occupying a certain port is not adopted when driving the digital tube display. Instead, it is implemented directly in a bit control manner according to the connection relationship of the pins.
The correspondence between the module pins and the MCU is as follows:
A---PA5
B---PA6
C---PA7
D---PA15
E---PB7
F---PA9
G---PB10
DP---PA8
D1---PB3
D2---PB4
D3—-NC
D4---NC
The statements that define the high and low levels of the related pin outputs are:
#define SMG_A_L GPIOA->BRE = GPIO_Pins_5
#define SMG_A_H GPIOA->BSRE = GPIO_Pins_5
#define SMG_B_L GPIOA->BRE = GPIO_Pins_6
#define SMG_B_H GPIOA->BSRE = GPIO_Pins_6
#define SMG_C_L GPIOA->BRE = GPIO_Pins_7
#define SMG_C_H GPIOA->BSRE = GPIO_Pins_7
#define SMG_D_L GPIOA->BRE = GPIO_Pins_15
#define SMG_D_H GPIOA->BSRE = GPIO_Pins_15
#define SMG_E_L GPIOB->BRE = GPIO_Pins_7
#define SMG_E_H GPIOB->BSRE = GPIO_Pins_7
#define SMG_F_L GPIOA->BRE = GPIO_Pins_9
#define SMG_F_H GPIOA->BSRE = GPIO_Pins_9
#define SMG_G_L GPIOB->BRE = GPIO_Pins_10
#define SMG_G_H GPIOB->BSRE = GPIO_Pins_10
#define SMG_P_L GPIOA->BRE = GPIO_Pins_8
#define SMG_P_H GPIOA->BSRE = GPIO_Pins_8
#define SMG_1L GPIOB->BRE = GPIO_Pins_3
#define SMG_1H GPIOB->BSRE = GPIO_Pins_3
#define SMG_2L GPIOB->BRE = GPIO_Pins_4
#define SMG_2H GPIOB->BSRE = GPIO_Pins_4
The function to display the value 0~9 is:
void smg_disp(char n)
{
if(n==0)
{
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_L;
SMG_E_L;
SMG_F_L;
SMG_G_H;
SMG_P_H;
}
if(n==1)
{
SMG_A_H;
SMG_B_L;
SMG_C_L;
SMG_D_H;
SMG_E_H;
SMG_F_H;
SMG_G_H;
SMG_P_H;
}
if(n==2)
{
SMG_A_L;
SMG_B_L;
SMG_C_H;
SMG_D_L;
SMG_E_L;
SMG_F_H;
SMG_G_L;
SMG_P_H;
}
if(n==3)
{
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_L;
SMG_E_H;
SMG_F_H;
SMG_G_L;
SMG_P_H;
}
if(n==4)
{
SMG_A_H;
SMG_B_L;
SMG_C_L;
SMG_D_H;
SMG_E_H;
SMG_F_L;
SMG_G_L;
SMG_P_H;
}
if(n==5)
{
SMG_A_L;
SMG_B_H;
SMG_C_L;
SMG_D_L;
SMG_E_H;
SMG_F_L;
SMG_G_L;
SMG_P_H;
}
if(n==6)
{
SMG_A_L;
SMG_B_H;
SMG_C_L;
SMG_D_L;
SMG_E_L;
SMG_F_L;
SMG_G_L;
SMG_P_H;
}
if(n==7)
{
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_H;
SMG_E_H;
SMG_F_H;
SMG_G_H;
SMG_P_H;
}
if(n==8)
{
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_L;
SMG_E_L;
SMG_F_L;
SMG_G_L;
SMG_P_H;
}
if(n==9)
{
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_L;
SMG_E_H;
SMG_F_L;
SMG_G_L;
SMG_P_H;
}
}
The main program to realize 2-digit automatic counting display is:
int main(void)
{
char i;
int j;
AT32_Board_Init();
smg_Init();
SMG_A_L;
SMG_B_L;
SMG_C_L;
SMG_D_L;
SMG_E_L;
SMG_F_L;
SMG_G_L;
SMG_P_L;
for(;;)
{
for(j=0;j<500;j++)
{
if(i<10)
{
SMG_1L;
SMG_2H;
smg_disp(i);
Delay_ms(2);
}
else
{
SMG_1L;
SMG_2H;
smg_disp(i%10);
Delay_ms(1);
SMG_1H;
SMG_2L;
smg_disp(i/10);
Delay_ms(1);
}
}
}
i++;
if(i>99) i=0;
}
|