STM32 oled multi-level menu display

Preface

      As long as there is a display screen, the display of multi-level menus must be used. In the eyes of many beginners, it is difficult to display multi-level menus. Today I finished this small project, and I will share my experience. OELD adopts Zhongjingyuan 0.78 inch resolution 128*80.

First of all, it is certain that as long as you clarify your thinking, you are not afraid of the difficulty of multi-level menu display. First take a few photos to see my display.

                               A menu

 

                             Secondary menu

  

 

                             Three-level menu

 

                                Four-level menu

  1. Hardware device: STM32F103C8T6+0.78 inch OLED IIC connection mode two independent buttons
  2. Schematic and PCB drawings: https://gitee.com/zhu_yu_yang/stm32_-oled_-board_-v2.1

Program realization

The multi-level menu display I learned is a jump from multiple interfaces, which is more suitable for beginners. There are two buttons on my hardware, one is mainly used to switch options , and the other is used to confirm options . So we temporarily call him the next key and the enter key. First define a structure. There are four variables in the structure, which represent the current index number, next key, enter key, and currently executing function . I only have two buttons here, so I defined it like this. If you have three buttons, you treat the other button as an upward movement. If you have four buttons, two additional buttons representing up and returned . So you have up, down, back and confirm four function keys. Then you need to add member variables when defining your structure. Take two buttons as an example here, which represent downward action and confirm action respectively . The structure is as follows:

typedef struct
{     uint8_t current;//Current state index number     uint8_t next; //Next     uint8_t enter; //Determine     void (*current_operation)(void); //The operation that should be performed in the current state } Menu_table;




Here is the core idea, that is to press the key to determine the current index number, and continue to define an array:

Menu_table table[13]=
{     {0,0,1,(*fun0)},//Level 1 interface Clock interface     {1,2,6,(*fun1)},//Level 1 interface CAN Mode     {2,3,7,(*fun2)},//The second line of the secondary interface 485 Mode     {3,4,8,(*fun3)},//The third line of the secondary interface UART Mode     {4,2 ,0,(*fun4)),//The fourth line of the secondary interface BACK





    {5,6,4,(*fun5)},//The first line of the three-level interface back

    {6,7,x,(*fun6)},//The second line of the third-level interface //x,y,z represent the index number of the fourth-level interface, which is not listed in detail in this article.

    {7,8,y,(*fun7)},//The third line of the three-level interface 

    {8,5,z,(*fun8)},//The fourth line of the third level interface 
};

uint8_t  func_index = 0;//The index value of the interface where the main program is at this time
 

Here is an explanation of the {0,0,1,(*fun0)},//level 1 interface clock interface in this array . Since we defined the Menu_table structure earlier , the structure member variables are the current index number, next, enter and void (*current_operation)(void) , the first 0 represents the current index number, the second 0 represents the index number returned by pressing the next button , and the third 1 represents the index number returned by pressing the enter button. The third (*fun0) represents the function to be executed when the index number is 0 . One-to-one correspondence. Combined with the button press screen, it is more logical.

Then there is the function that needs to be processed when the button is pressed

void  Menu_key_set(void)
{
  Get_key_next = get_button(button1);
  Get_key_enter = get_button(button2);
  if(Get_key_next == 1)
  {   
    func_index=table[func_index].next;//按键next按下后的索引号
    OLED_Clear();
  }
  if(Get_key_enter == 1)
  {
    func_index=table[func_index].enter;
    OLED_Clear();
  }

  current_operation_index=table[func_index].current_operation;//Execute the function corresponding to the current index number.
  (*current_operation_index)();//Execute the current operation function
}
 

Here is an explanation. For example, in the secondary menu, they are:

1.CAN Mode

2.485 Mode

3.UART mode

4.BACK

Then, when the first-level menu jumps to the second-level menu, the cursor should be in 1.CAN Mode. At this time, if the button is pressed next, the cursor will move to 2.485 Mode, and if the button enter is pressed, it will jump. Go to the first line in the three-level menu. Therefore, pressing the next button will return to the index number in front of 2.485 Mode. The program executes the corresponding cursor to the program according to the index number, causing the cursor to move from the first line to the second line. When the cursor is on 4.BACK, press next to jump to 1.CAN Mode, as long as the index number returned by pressing the next key at this time is the index number of CAN Mode. Then execute the function that the cursor moves to in the function corresponding to the index number. The same principle applies to multiple keys.

 

The above is my understanding of the multi-level menu, and many of them are only half-understood. If there is any mistake, please correct me.

The PCB schematic and PCB drawings I drew by myself: https://gitee.com/zhu_yu_yang/stm32_-oled_-board_-v2.1

Also refer to: https://blog.csdn.net/calmuse/article/details/79346742

If reprinted, please indicate the source.

 

Guess you like

Origin blog.csdn.net/weixin_42618564/article/details/114402298