本帖最后由 cheney03 于 2021-1-5 19:48 編輯
程序是網上的例程,已實現多級菜單顯示。現在有個問題:當進入函數fun1中,fun1函數中也有按鍵需要處理(通過up down鍵對變量temp實現加 減),這樣按鍵有沖突,要怎么實現不沖突呢?按鍵為4*4矩陣按鍵,通過行列掃描獲取鍵值判斷哪個鍵按下。
#include <reg52.h> #include "fun.h" #include "lcd12864.h" #include "delay.h" #define uchar unsigned char uchar func_index=0; void (*current_operation_index)(); typedef struct { uchar current; uchar up;//向上翻索引號 uchar down;//向下翻索引號 uchar enter;//確認索引號 void (*current_operation)(); } key_table; key_table code table[3]= { {0,3,1,3,(*fun1)}, {1,0,2,2,(*fun2)}, {2,1,3,1,(*fun3)} , {3,2,0,0,(*fun3)} }
void main() { init_lcd(); //初始化LCD模塊 while(1) { Key_scan(); if(KeyState) { KeyState=0; if(KEY==KEY_OK) { func_index=table[func_index].enter; } if(KEY==KEY_DOWN) { func_index=table[func_index].down; } if(KEY==KEY_UP) { func_index=table[func_index].up; } current_operation_index=table[func_index].current_operation; (*current_operation_index)();//執行當前操作函數 // flag=0; } } } |