A total of 12 pins of GPIO port PA0~PA11 are used
First, the schematic diagram
Because it is a common anode, 12, 9, 8, and 6 are power inputs, and the other pins are grounded. So for the chip, 12, 9, 8, and 6 are high outputs, and the others can be set to low.
//Set the GPIO port
void GPIO_Num_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
There is one thing to note here. According to the schematic diagram, the digital tube can only output one bit of array at a time, so if it is multi-bit, it must be output in a scanning manner. By shortening the switching interval, a non-flickering effect can be achieved.
//Output package
void DisPlayNum(int n)
{
if (n < 9999)
{ int i;
int s;
s = n;
i=0;
for (i=0;i<4;i++)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_All);
switch (i)
{
case 0:
GPIO_SetBits(GPIOA,GPIO_Pin_5);
break;
case 1:
GPIO_SetBits(GPIOA,GPIO_Pin_7);
break;
case 2:
GPIO_SetBits(GPIOA,GPIO_Pin_8);
break;
case 3:
GPIO_SetBits(GPIOA,GPIO_Pin_11);
break;
}
switch (s % 10)
{
case 0:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_4);
break;
case 1:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_9|GPIO_Pin_10);
break;
case 2:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_9);
break;
case 3:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0|GPIO_Pin_9);
break;
case 4:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_10);
break;
case 5:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0|GPIO_Pin_6);
break;
case 6:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_6);
break;
case 7:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_9);
break;
case 8:
GPIO_SetBits(GPIOA,GPIO_Pin_2);
break;
case 9:
GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_0);
break;
}
s = s / 10;
delay_ms(1);
if (s==0)
break;
}
}
}
Finally, the main test code
int count;
int TimeCheck;
int main(void)
{
GPIO_Num_Init();
count =0;
TimeCheck = 0;
while(1)
{
DisPlayNum(count);
TimeCheck++;
delay_ms(5);
if (TimeCheck > 100){ //+1 every 500 milliseconds
TimeCheck=0;
count++;
}
}
}
Previous article:STM32 uses PWM to control the LED breathing light effect
Next article:ADC multi-channel acquisition program for STM32f103 digital electrical acquisition circuit
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Protecting Your IP Cores - Part 1 Soft IP Cores, Chapter 3: Obfuscation of Hardware Design
- Oscilloscope testing applications in medical equipment
- Review Weekly Report 20220228: The Bear Pai Hongmeng folding development board is here, Qinheng ch582 is now available for testing
- My EEWorld 2018
- 【Android Development Learning Road】Three-- Binder Initial Implementation
- Award-winning live broadcast: ams projection lighting (MLA) enhances the communication between cars and roads
- MSP430F5529 USB Experimenter Board
- pyESP32 Pinout
- Getting Started with I2C on MSP MCUs
- 【AT-START-F425 Review】No.03 Debugging serial port, timer and main system frequency