|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-9-9 09:09:04
|
显示全部楼层
研究了下深入浅出AVR上面栈的介绍,倒是理解了可惜自己还是不知道怎么好应用到程序里去,用笨方法修改了点程序基本实现了我想要的情况,菜单可以随按键上下移动,3级菜单也可以记录下父菜单的状态,就是感觉程序有点不稳妥,大虾有时间的帮看下有什么问题。附修改的部分程序:
/**********************
* 目录结构体定义(增加一个菜单ID索引) *
**********************/
struct MenuItem
{
short MenuCount; //菜单项数
short MenuID; //菜单的ID, 菜单的索引号
char *DisplayString; //菜单显示内容
void (*Subs)(); //执行函数
struct MenuItem *ChildrenMenus; // 子菜单
struct MenuItem *ParentMenus; // 父菜单
}Null;
short Rvmenu1,Rvmenu2; //记录恢复菜单ID索引
主程序修改的部分:
while(1)
{
if(key_stime_ok) //10ms定时检测
{
time_100us_ok = 0;
KeyNum = read_key(); //读取按键
/***************************************
* [°´¼ü˵Ã÷] *
* ----------------------------------- *
* [K1] 1 UP(ÏòÉÏ) *
* [K2] 2 Down(ÏòÏÂ) *
* [K3] 4 Esc(ºóÍË) *
* [K4] 3 Enter(È•¶¨) *
* [K5] 5 Reset(¸´Î») *
***************************************/
if (KeyNum != 0xff)
{
// ShowMenu();
switch(KeyNum)
{
case Up:
LCD_clear();
UserChoose --;
if (UserChoose < 0)
{
UserChoose = MaxItems-1;
}
DisplayStart = UserChoose;
break;
case Down:
LCD_clear();
UserChoose ++;
if (UserChoose == MaxItems)
{
UserChoose = 0;
}
DisplayStart = UserChoose;
break;
case Enter:
LCD_clear();
if (MenuPoint[0].MenuID ==1)
{
Rvmenu1=UserChoose; //记录1级菜单ID
}
if (MenuPoint[0].MenuID ==2)
{
Rvmenu2=UserChoose; //记录2级菜单ID
}
if (MenuPoint[UserChoose].Subs != NullSubs)
{
(*MenuPoint[UserChoose].Subs)();
}
else if (MenuPoint[UserChoose].ChildrenMenus != &Null)
{
MenuPoint = MenuPoint[UserChoose].ChildrenMenus;
UserChoose = 0;
DisplayStart = 0;
}
break;
case Esc:
LCD_clear();
if (MenuPoint[0].MenuID ==2)
{ DisplayStart = Rvmenu1;
UserChoose=Rvmenu1; }
if (MenuPoint[0].MenuID ==3)
{ DisplayStart = Rvmenu2;
UserChoose=Rvmenu2; }
if (MenuPoint[0].ParentMenus != &Null)
{
MenuPoint = MenuPoint[0].ParentMenus;
// UserChoose = 0;
// DisplayStart = 0;
} |
|