A modular design method for multi-level menus in single-chip microcomputers

Publisher:皮球Latest update time:2013-01-09 Source: 电子设计工程 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction
In the design of single-chip microcomputers, it is often necessary to display a multi-level operation menu on the display screen. Each menu level has some menu items and corresponding key operations, as well as subsequent processing programs executed in response to various operations. The reference uses function pointers as structural elements to stretch the entire menu structure into a structure array, which contains all menu items. This method does not separate the menu item data from the function function, but writes the menu item data in the function function. When the menu item data needs to be changed, the function function must be modified, which greatly limits the versatility of the program and is not conducive to program maintenance. The reference slightly improves on the former, adding menu item display text and key reuse identifiers to the original structure, which makes the structure larger, and the text content of the menu item is very fixed and stored in the EEPROM, and the display content and position cannot be flexibly changed. The reference introduces the window and message mechanism under the Windows system to realize the multi-level menu design. This method requires the maintenance of stacks, message queues, window timers, etc., and the design is too complicated.
This paper aims to provide a lightweight single-chip multi-level menu implementation method to complete the menu design with less system resource consumption and a simple and convenient method. Considering that the menu program needs to have three basic elements: one is the content to be displayed in each menu window; the second is the key definition and response corresponding to each window; the third is the switching mechanism between menu items in the window and between windows. Therefore, the menu is divided into two parts: the menu window module and the keyboard processing module, which are designed independently.

1 Menu window module design
The main function of the menu window module is to complete the display control of the window in real time according to the menu window switching mechanism.
1.1 Menu window switching mechanism
The menu window switching mechanism includes two points: one is the realization of the switching effect between different windows; the other is the realization of the scrolling switching effect between the same-level menu items in the window. To achieve the above functions, two structures MenuState and MenuItems are defined. MenuState is defined as follows:

b.JPG



MenuState is a structure array related to window jump and window display, which is used to globally schedule the switching between windows. Among them, CurIndex is the index value of the window, which is used to identify the current window. UpIndex, DnIndex, and BackIndex are used to identify the window to which the program should turn when there is a "previous page", "next page", or "back" button operation. When its value is 255, it means there is no window to turn to, and when it is between 0 and 254, it indicates the window index to turn to. Therefore, this design can support 255 menu windows, which is enough to meet the needs of engineering applications. CurOperate is a function pointer used to point to the window display control program that should be executed when the current window is displayed to realize the display of the window.
MenuItems is a menu item structure that is used to save the display position and content of all menu items in the current window. The content of this structure is updated during the initialization process of the new window as the window is switched. This meets the needs of window switching and reverse scrolling between menu items. Since only menu items related to the current window are saved, the system resource consumption of this structure is very small.

d.JPG


Items contains all the menu items in the current window. Considering that some menu items do not have a redirect window, the value is set to 255 for such menu items. When a window is displayed, Items will be filled with the menu item information of the current window, and the filling is constructed in the order of the menu items. In this way, when there is a "move up" or "move down" key operation, the target line can be quickly found and the line can be reversed.
1.2 Menu window display control
The window display part encapsulates each menu window in the form of an independently named function. The function includes assigning values ​​to Items, displaying the menu items of the current window at the specified position of the display screen, and completing drawing operations such as drawing points, drawing lines, and drawing buttons as needed. These functions are independent of each other and correspond to different menu windows. Only CurOperate is assigned when the window is switched, so it is very suitable for multi-person collaborative development.
It should be noted that the display control of the menu window is based on the display screen. TFT screens or dot matrix LCD screens are commonly used in engineering. When using it, it is necessary to implement the driver of the display screen and perform operations such as initialization, reading, and writing on the screen. Since it is not the focus of this article, this part of the content is omitted.
[page]

2 Keyboard processing module design
The menu operation of the microcontroller is mostly completed in the form of keys. Generally, there are multiple keys corresponding to different functions. In addition, the key reuse problem should also be considered. That is, the keys in the same position may have different function definitions in different windows. Therefore, the key values ​​should be collected and analyzed in the program to respond to the operation correctly. The key processing process is shown in Figure 1.

e.JPG


For example, when the "Previous Page" button is pressed, the program will receive the button, parse the key definition according to the current window, and judge it as "Previous Page"; then obtain the index value of the window to be redirected in the window structure array Menu Index, obtain the pointer of the window display control program according to the index value, and release the menu item structure Items to execute the window display control program. The code is as follows:
f.JPG

[page]

3 Application Examples
In a certain equipment simulation project, the AT89C52 chip is used as the core device, the display part uses the graphic dot matrix LCD display module HG3202405V2-B-LWH-LV, and there are 6 external composite function keys to realize the menu design. Part of the code is as follows:
g.JPG
The main menu window is shown in Figure 2.

a.JPG

Conclusion
The multi-level menu design of single-chip microcomputer is a common problem in project development. This article provides a solution and has been applied in the project. Its characteristics are manifested in two aspects: first, the system overhead is small, and only two structures, MenuState and MenuItems, and several variables are needed to maintain each window and the same-level menu items in the window; second, the functional independence of each part of the module is strong, the display control programs of each menu window are independent of each other and do not affect each other, and the keyboard processing program is also self-contained. Therefore, the solution has a high degree of modularization, a simple and convenient development process, good scalability, strong portability, and is suitable for teamwork development and maintenance.

Reference address:A modular design method for multi-level menus in single-chip microcomputers

Previous article:Working principle of PIC microcontroller human-machine interface 4×4 row keyboard
Next article:Microchip's compact and flexible 8-bit Flash microcontroller solution

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号