while(MyKey != NOKEY)//有键顺序执行
{
}
/* Initializes the Menu state machine 【】*/
Menu_Init();
MenuItemIndex = 0;
/* Endless loop */
while(1)
{
/* Check which key is pressed 【上下左右+sel】*/
MyKey = Matrx_keyScan();
/* If "UP" pushbutton is pressed 调整显示图标,记录对应菜单项,菜单级别和索引*/
if(MyKey == UP)
{ //【调整序号】
if(MenuItemIndex > 0)
{
MenuItemIndex--;
}
else
{
MenuItemIndex = NumberOfMain_Items - 1;
}
//【根据调整后的索引号,调整显示内容的首尾序号,决定是否刷新】
ItemIndex_Change_refresh(UP_Press);
DisplayMenu(LCD_refresh);
LCD_line_highlight=KEY_UP_highlight(LCD_line_highlight); //【判断按下之后的索引,调整高亮】
}
/* If "DOWN" pushbutton is pressed */
if(MyKey == DOWN)
{ //【调整序号】
/* Test on the MenuItemIndex value before incrementing it */
if(MenuItemIndex == (NumberOfMain_Items - 1))
{
MenuItemIndex = 0;
}
else
{
MenuItemIndex++;
}
//【调整显示索引号,调整显示内容的首尾序号,决定是否刷新】,1表示down,修改LCD_refresh
ItemIndex_Change_refresh(DOWN_Press);
DisplayMenu(LCD_refresh);
LCD_line_highlight=KEY_DOWN_highlight(LCD_line_highlight);//【判断按下down之后的索引,高亮】
}
- 调整序号
- 调整显示索引号,调整显示内容的首尾序号,决定是否刷新,只有特定索引配合按键才能调整显示内容。
- 屏幕显示4行信息
- 判断按下之后的索引,4行循环,高亮处理
菜单有14个选项,设计了16个,为了补足一个屏显示4行。
另,编译完文件之后,在工程目录Debug目录中的List目录中就会生成map文件,可以查看代码大小。
如果编译出现“ has already been declared in the current scope”,试着在h文件中增加相应声明,或者修改定义名称。
多个变量定义完毕,想把中间的一个变量设置为全局变量,拷贝到文件开头,结果后面的结构定义不断报错,说没有定义,反复查看百思不得其解。对有问题的语句大量注释,最后发现那个全局变量声明的时候已经赋值为0了,所以变成了
static uint8_t MyKey = 0,
实际上应该是
static uint8_t MyKey = 0;
粗心,基本功不够硬。