The stm32f103 series development board controls the digital tube to display the custom time (self-learning)

First understand the coding method of the digital tube: the LED digital tube is connected to the single-chip microcomputer, and generally the pen end pins a, b..., g, dp of the digital tube are connected to a parallel I/O port corresponding to the configuration of the single-chip microcomputer in a certain order. , when the I/O port is configured with a certain value, the LED digital tube can display fixed characters.

It is divided into common cathode and common anode according to the connection mode of the common terminal. The following are eight-segment coding tubes for common cathode and common anode respectively:

The digital tube display methods include static display and dynamic scanning. We use dynamic scanning, that is, connect a, b... of each digital tube together, a total of eight segments, controlled by an eight-bit I/O port, and each The public end of one bit is controlled by an I/O port outside Ning.

Then there is a code selection for controlling the digital tube~

The configuration of the bit selection code needs to be configured according to the circuit schematic diagram~

Nixie tube driver function

1. Nixie tube display initialization

       void smgInit()

{

   GPIO_InitTypeDef  GPIO_InitStructure;
           RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG, ENABLE);//使能GPIOF时钟
           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15|GPIO_Pin_14|GPIO_Pin_13|GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_10|GPIO_Pin_8|GPIO_Pin_9;

//Corresponding to the stm32f103zet6 development board, the eighth bit of the PE port has other functions, such as setting external interrupts, so do not open all I/O ports GPIO_InitStructure.GPIO_Speed 
           ​​= GPIO_Speed_10MHz; //speed 50MHz    
           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Speed ​​50MHz
            GPIO_Init(GPIOE, &GPIO_InitStructure);//Initialization

           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; 
           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;    //速度50MHz    
           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    //速度50MHz
            GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化

}

2. Nixie tube display function

void smgShow()

{     while(1)     {         GPIO_Write(GPIOE,0x7FFF);//Select the first digital tube         GPIO_Write(GPIOC,0xc0);//Send the segment code of the first number         delay_ms(1000);//Delay for a while         GPIO_Write (GPIOE,0xBFFF);//Select the second digital tube         GPIO_Write(GPIOC,0xf9);//Send the segment code of the second number         delay_ms(1000);//Delay for a while         GPIO_Write(GPIOE,0xDFFF);/ /Select the third digital tube         GPIO_Write(GPIOC,0xa4);//Send the segment code of the third number         delay_ms(1000);//Delay for a while         GPIO_Write(GPIOE,0xEFFF);//Select the fourth digital tube         GPIO_Write(GPIOC,0xb0);//Send the segment code of the fourth number         delay_ms(1000);//Delay for a while         GPIO_Write(GPIOE,0xF7FF);//Select the fifth digital tube         GPIO_Write(GPIOC,0x99); //Send the segment code of the fifth number         delay_ms(1000);//Delay for a while





        



    



        



        



        
        GPIO_Write(GPIOE,0xFBFF);//Select the sixth digital tube
        GPIO_Write(GPIOC,0x92);//Send the segment code of the sixth number
        delay_ms(1000);//Delay for a period of time
    
    }
}

Defined in the nixie tube file


extern u8 hour,minute,second;//global variables

u8 smgduan[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90};

u16 smgwei[6]={0x7fff,0xbfff,0xdfff,0xefff,0xf7ff,0xfbff};

In the digital tube display function, we can launch

A function to display time (considering that the time has two digits, we can use the remainder method to separate)

        GPIO_Write(GPIOE,smgwei[0]);//Select the first digital tube
        GPIO_Write(GPIOC,smgduan[hour/10]);//Send the segment code of the fifth number
        delay_ms(1000);//Delay for a period time

        GPIO_Write(GPIOE,smgwei[1]);//Select the second digital tube
        GPIO_Write(GPIOC,smgduan[hour%10]);//Send the segment code of the fifth number
        delay_ms(1000);//Delay for a period time

In this way, the number corresponding to the hour can be displayed, and the minutes and seconds are similarly displayed.

 

Guess you like

Origin blog.csdn.net/qq_60043905/article/details/124644006