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

 时间: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 创建多子件元件
  • 热门搜索
    北京旅游年票网 浙江天台山旅游攻略 额济纳旗旅游攻略 乐亭旅游攻略 花莲旅游攻略 涠洲岛旅游网 顺德旅游景点大全 漳州火山岛旅游攻略 北戴河旅游路线 兰州旅游公司