menu.h
# ifndef __MENU_H_
# define __MENU_H_
# define Menu_len 57 //定义结构体数组大小;
/*-------------------------函数声明----------------------*/
void Key_response(void);
/*--------------------------变量------------------------*/
extern unsigned char Index_num; //索引号;
extern void (*Key_function)(void); //按键函数;
# endif
menu.c
# include<msp430f149.h>
# include "lcd12864_application.h"
# include "menu.h"
# include "display.h"
unsigned char Index_num = 0;
void (*Key_function)(void);
struct Menu
{
unsigned char Current_state; //当前状态索引;
unsigned char Up_index; //按上键的状态索引;
unsigned char Down_index; //按下键的状态索引;
unsigned char Left_index; //按左键的状态索引;
unsigned char Right_index; //按右键的状态索引;
unsigned char Enter_index; //按确认键的状态索引;
unsigned char Exit_index; //按返回键的状态索引;
void (*Current_operate)(void); //当前状态所执行的操作;
};
const struct Menu Menu_Index[]=
{
{0, 1, 1, 1, 1, 1, 1, (*Init_interface)}, //开机菜单;
{1, 3, 2, 1, 1, 4, 2, (*First_menu)}, //电机测速 //第一层
{2, 3, 3, 2, 2, 4, 2, (*First_menu)}, //电机正转 //第一层
{3, 2, 2, 3, 3, 4, 2, (*First_menu)}, //电机反转 //第一层
{4, 5, 5, 4, 4, 6, 2, (*Second1_menu)}, //转速设置 //第二层菜单--状态2的子项;
{5, 4, 4, 5, 5, 8, 2, (*Second1_menu)}, //转速显示
{6, 7, 7, 6, 6, 6, 4, (*Second2_menu)}, //设定的转速 //第二层菜单--状态4的子项
{7, 6, 6, 7, 7, 12, 4, (*Second2_menu)}, // (r/s)
{8, 11, 9, 8, 8, 8, 5, (*Second3_menu)}, //转速显示值
{9, 8, 10, 9, 9, 9, 5, (*Second3_menu)}, // (r/s)
{10, 9, 11, 10, 10, 10, 5, (*Second3_menu)}, //转速设置显示 //第二层菜单--状态3的子项
{11, 10, 8, 11, 11, 11, 5, (*Second3_menu)}, // (r/s) //第三层菜单--第二层菜单状态2的子项;
{12, 12, 12, 12, 12, 7, 7, (*Third1_menu)}, // (r/s)
/* {13, 12, 8, 50, 1, (*Second1_menu)}, //
{14, 19, 15, 50, 2, (*Second2_menu)}, //
{15, 14, 16, 50, 2, (*Second2_menu)}, //
{16, 15, 17, 50, 2, (*Second2_menu)}, //
{17, 16, 18, 50, 2, (*Second2_menu)}, //
{18, 17, 19, 50, 2, (*Second2_menu)}, //
{19, 18, 14, 50, 2, (*Second2_menu)}, //第二层菜单--状态2的子项;
{20, 25, 21, 50, 3, (*Second3_menu)},
{21, 20, 22, 50, 3, (*Second3_menu)},
{22, 21, 23, 50, 3, (*Second3_menu)},
{23, 22, 24, 50, 3, (*Second3_menu)},
{24, 23, 25, 50, 3, (*Second3_menu)},
{25, 24, 20, 50, 3, (*Second3_menu)}, //第二层菜单--状态3的子项;
{26, 31, 27, 50, 4, (*Second4_menu)},
{27, 26, 28, 50, 4, (*Second4_menu)},
{28, 27, 29, 50, 4, (*Second4_menu)},
{29, 28, 30, 50, 4, (*Second4_menu)},
{30, 29, 31, 50, 4, (*Second4_menu)},
{31, 30, 26, 50, 4, (*Second4_menu)}, //第二层菜单--状态4的子项;
{32, 37, 33, 50, 5, (*Second5_menu)},
{33, 32, 34, 50, 5, (*Second5_menu)},
{34, 33, 35, 50, 5, (*Second5_menu)},
{35, 34, 36, 50, 5, (*Second5_menu)},
{36, 35, 37, 50, 5, (*Second5_menu)},
{37, 36, 32, 50, 5, (*Second5_menu)}, //第二层菜单--状态5的子项;
{38, 43, 39, 50, 6, (*Second6_menu)},
{39, 38, 40, 50, 6, (*Second6_menu)},
{40, 39, 41, 50, 6, (*Second6_menu)},
{41, 40, 42, 50, 6, (*Second6_menu)},
{42, 41, 43, 50, 6, (*Second6_menu)},
{43, 42, 38, 50, 6, (*Second6_menu)}, //第二层菜单--状态6的子项;
{44, 49, 45, 50, 7, (*Second7_menu)},
{45, 44, 46, 50, 7, (*Second7_menu)},
{46, 45, 47, 50, 7, (*Second7_menu)},
{47, 46, 48, 50, 7, (*Second7_menu)},
{48, 47, 49, 50, 7, (*Second7_menu)},
{49, 48, 44, 50, 7, (*Second7_menu)}, //第二层菜单--状态7的子项;
*/
};
/*------------------------按键响应-----------------------*/
void Key_response(void)
{
switch(Key_value)
{
case Up:
Index_num = Menu_Index[Index_num].Up_index;
break;
case Down:
Index_num = Menu_Index[Index_num].Down_index;
break;
case Left:
Index_num = Menu_Index[Index_num].Left_index;
break;
case Right:
Index_num = Menu_Index[Index_num].Right_index;
break;
case Enter:
Index_num = Menu_Index[Index_num].Enter_index;
break;
case Exit:
Index_num = Menu_Index[Index_num].Exit_index;
break;
default:
return;
break;
}
Key_function = Menu_Index[Index_num].Current_operate;
(*Key_function)();
}