单片机中建立菜单的一种方法

 时间:2026-02-13 17:25:44

1、新建一个结构体,需要什么按键,加入对应内容。

typedef struct

{

    unsigned char current;

    unsigned char up;

    unsigned char down;

    unsigned char enter;

    ussigned char back;

    void (*current_operation)();

} key_table;

2、定义。菜单的按键连接。

key_table const table[7]=

{

   {0,1,1,1,1,(*fun0)},

   {1,(*fun1)},

   {2,(*fun2)},

   {3,(*fun3)}, 

   {4,(*fun4)},

   {5,(*fun5)},   

   {6,(*fun6)},     

};

3、定义变量

INT8U  func_index=0;

void (*current_operation_index)();

4、主菜单中的

while(1)

{

        key_temp=keyscan(key());   

        switch(key_temp)

        {

            case 10:func_index=table[func_index].enter;break;

            case 11:showtime();func_index=table[func_index].back;break;   

            default:func_index=table[func_index].current;break;

        }  

current_operation_index=table[func_index].current_operation;

(*current_operation_index)();

}

5、注意:

在CVAVR或某些编译器中:不需要星号。如下。

key_table const table[7]=

{

   {0,1,1,1,6,(fun0)},

   {1,1,2,2,0,(fun1)},

   {2,1,3,3,1,(fun2)},

   {3,1,4,4,2,(fun3)}, 

   {4,1,5,5,3,(fun4)},

   {5,1,6,6,4,(fun5)},   

   {6,1,0,0,5,(fun6)},     

};

  • Altium\AD16如何设定文件原点和测量
  • 【protel99】怎样使菜单汉化
  • 如何安装IAR软件?
  • 如何查看protues的版本号?
  • 实例讲解 Altium Designer 创建多子件元件
  • 热门搜索
    10万个为什么 乳腺增生怎么治最好 平方怎么算 麦粒肿怎么治疗 张钧甯怎么读读音 罩杯abcd怎么分大小 为什么女生会出水 老是咳嗽是怎么回事 双胞胎是怎么形成的 大熊猫为什么是国宝