#define __menu_h__
#include "head.h"
#include "LCD1602_2.h"
#include "DS18B20.h"
#define Null 0
/***********************
* Function declaration *
***********************/
void ShowMenu(void);
void Menu_Change(volatile KeyNum);
/***********************
* Key function key macro definition *
***********************/
#define up 1
#define down 2
#define back 4
#define ok 5
/**********************
* Directory structure definition *
**********************/
struct MenuItem
{
uchar MenuCount; //Number of nodes in the current layer
uchar *DisplayString; //Menu title
void (*Subs)(); //Node function
struct MenuItem *ChildrenMenus; //child nodes
struct MenuItem *ParentMenus; //parent node
};
/***********************
* Call sub-function area *
***********************/
void NullSubs(void)
{
}
/***********************
* Structure area *
***********************/
struct MenuItem NameMenu[2];
struct MenuItem NumberMenu[2];
struct MenuItem MainMenu[3];
struct MenuItem NameMenu[2]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{2, "WeiMen", NullSubs, Null, MainMenu},
{2, "Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem NumberMenu[2]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{2, "0500320128", NullSubs, Null, MainMenu},
{2, "Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem MainMenu[3]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{3, "1.Show Name ", NullSubs, NameMenu, Null},
{3, "2.Show Number", NullSubs, NumberMenu, Null},
{3, "3.Back", MainMenu, MainMenu},
};
/***********************
* Global variable declaration area *
***********************/
struct MenuItem (*MenuPoint) = MainMenu; //Structure pointer, after pointing to the structure, the internal function pointer points to the function function
uchar DisplayStart = 0; //The first menu item when displayed
uchar UserChoose = 0; //Menu item selected by the user
uchar DisplayPoint = 0; //display pointer
uchar MaxItems; //Maximum number of menus at the same level
uchar ShowCount=2; //Number of menus displayed on the same screen
/***********************
*Show function area*
***********************/
void ShowMenu(void)
{
unsigned char n;
MaxItems = MenuPoint[0].MenuCount;//定义最大同级菜单
DisplayPoint = DisplayStart;
for(n=0;DisplayPoint
LCDDispListChar(0,n,"->");
LCDDispListChar(2,n,MenuPoint[DisplayPoint++].DisplayString);
}
}
void Menu_Change(unsigned char KeyNum)
{
if(KeyNum)
{
switch(KeyNum)
{
case up:
UserChoose --;
if (UserChoose == 255)
{
UserChoose = 0;//Upward limit, if you want to roll back, assign the value to MaxItems-1
}
break;
case down:
UserChoose ++;
if (UserChoose == MaxItems)
{
UserChoose = MaxItems-1;//Downward limit, if you want to roll back, assign the value to 0
}
break;
case back:
if (MenuPoint[UserChoose].ParentMenus != Null)
{
MenuPoint = MenuPoint[UserChoose].ParentMenus;
UserChoose = 0;
DisplayStart = 0;
}
break;
case ok:
if (MenuPoint[UserChoose].Subs != NullSubs)
{
(*MenuPoint[UserChoose].Subs)();
}
else if (MenuPoint[UserChoose].ChildrenMenus != Null)
{
MenuPoint = MenuPoint[UserChoose].ChildrenMenus;
UserChoose = 0;
DisplayStart = 0;
}
break;
default:break;
}
if (UserChoose%ShowCount==0) //Only ShowCount rows can be displayed on one screenDisplayStart
= UserChoose;
else if(UserChoose==1||UserChoose== 3)
DisplayStart = UserChoose-1; //The key to scrolling
LCDWriteCmd(DispClear); //Clear the LCD screen, modify it according to different LCD functions
delay1ms(2); //LCD is a slow device
ShowMenu();
}
}
#endif
Previous article:[C51 code] LCD12864 header file [upper and lower screen]
Next article:74hc164 driver digital tube program
- 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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- 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)
- How to realize 12864 display of 430f149 MCU AD sampling waveform
- Pre-match training FAQ: Detailed explanation of ON Semiconductor's ultra-low power RSL10 Bluetooth SoC development board
- How to start with PCB layout and wiring to avoid noise caused by improper switching power supply layout
- EEWORLD University ---- Type-C end-to-end solution
- Diary of the trouble of building TMS320F28379D project with css6.0
- ESP32-S2 Development Pitfalls (4) -- USB Pitfalls
- Analysis of several components of switching power supply that "seriously affect the cost"!
- Three differential amplifier circuits, available for actual testing
- MSP430__SD card FAT16 reading and writing program based on MSP430 learning and development system
- This week's highlights