建议采用你的方式,但也不完全和你的一样。就是阻塞在每个调用函数里面,这样问题比较容易处理,特别是没有os的系统。
对应菜单这里有一个我自己写的,可以参考
void SuperMenu(unsigned char ucMenuItemNum, // menu total num unsigned char ucStartLineNo, // first menu item row pos 1 unsigned char ucEndLineNo, // last menu item row pos 3 unsigned long ulWaitKeyTimeOut, // wait key timeout unsigned char ucKeySoundOpen, // key beep switch unsigned char ucDectectCard, // return from menu if card present char *pMenuTitle, // menu main title char *MenuText[], // menu item content void (*function[])(void)) // menu item function { unsigned char ucItemNumPerScr; // menu item num per screen unsigned char i,j,ucRnt, // ucLastScrLineNum, // menu item num in last screen ucScrNum, // menu screen num ucCurScr, // current screen ucCurLine; // current row unsigned long ulDelay; unsigned char ucShowMargin;
ucItemNumPerScr = ucEndLineNo - ucStartLineNo + 1;
UpdateFace();
lcd_disp(0, 0, "", LCD_CLS); ucCurLine = 0; ucCurScr = 0; ulDelay = ulWaitKeyTimeOut; ucShowMargin = 1; ucScrNum = ucMenuItemNum / ucItemNumPerScr; ucLastScrLineNum = ucMenuItemNum % ucItemNumPerScr; if(ucLastScrLineNum) ucScrNum ++; else ucLastScrLineNum = ucItemNumPerScr; // while(1) { if(ucShowMargin) { lcd_disp(0, 0, (char *)pMenuTitle, NULL); ucShowMargin = 0; } // disp a screen info for(i=0; i<ucItemNumPerScr; i++) { j = ucCurScr*ucItemNumPerScr+i; if( j>(ucMenuItemNum-1) ) { lcd_disp((ucStartLineNo+i) * 2 , 0, " ", NULL); continue; } if(i == ucCurLine) lcd_disp((ucStartLineNo+i)*2, 0, MenuText[j], LCD_REVERT); else lcd_disp((ucStartLineNo+i)*2, 0, MenuText[j], 0); } // wait for menu select while(1) { ucRnt = get_key(TRUE); if(ucRnt != NULL) break; ulDelay --; if(ulDelay == 0) return; #if 0 if(ucDectectCard) { if(profile(0) != ST_ERROR) return; } #endif OSTimeDlyHMSM(0, 0, 0, 40); } #if 0 if(ucKeySoundOpen) Beep(1, 100, 50); #endif ulDelay = ulWaitKeyTimeOut; //按键处理 switch(ucRnt) { case KEY_DOWN: if(ucCurScr == (ucScrNum-1)) { if(ucCurLine == (ucLastScrLineNum-1)) { ucCurLine = 0; ucCurScr = 0; break; } } ucCurLine ++; if(ucCurLine < ucItemNumPerScr) break; ucCurLine = 0; ucCurScr ++; if(ucCurScr < ucScrNum) break; ucCurScr = 0; break; case KEY_UP: if(ucCurLine == 0) { if(ucCurScr == 0) { ucCurScr = ucScrNum-1; if(ucCurScr == 0) ucCurLine = ucLastScrLineNum-1; } else ucCurScr --; } else ucCurLine --; break; case KEY_CANCEL: return; case KEY_ENTER: lcd_disp(0, 0, "", LCD_CLS); function[ucCurScr*ucItemNumPerScr + ucCurLine] (); ucShowMargin = 1; break; default: break; } } }
|