新闻中心

EEPW首页>嵌入式系统>设计应用> 单片机c语言中菜单系统源码分析

单片机c语言中菜单系统源码分析

作者: 时间:2016-11-27 来源:网络 收藏
最近在学习单片机菜单系统时,发现有这么一些代码,定义了4个按键,确认键,返回键,上键,下键,先贴出来在vc里边建的,先定义一个结构体KbdTabStruct,在用结构体定义一个const型的数组KBD[],那么数组的每一个成员对应的原本结构体的数则是它的初始化值,并且这个值初始化后就成立,以后不再改变。比如说KBD[0].KeyCurrentIndex所对应的则是数组table中成员0 的值,这些值就是它的初始化值,相当于KBD[0].KeyCurrentIndex=0,但如果这样写N层的菜单,如此定义肯定麻烦,所以用这样的数组实现。

int main()
{
typedef struct
{
u8 KeyCurrentIndex;//当前状态索引号
u8 KeyEnterState;//按下【enter】键时转向的索引号
u8 KeyCancelState;//按下【cancel】键时转向的索引号
u8 KeyUpState;//按下【up】键时转向的索引号
u8 KeyDownState;//按下【down】键时转向的索引号
void (*CurrentOperate)(); //当前状态下执行的功能操作
}KbdTabStruct;

本文引用地址://m.amcfsurvey.com/article/201611/322301.htm

const KbdTabStruct KBD[]=
{
{0,1,2,3,4,(*main)},
{6,7,8,9,10,(*main)},
{0,1,2,3,4,,(*main)},
{0,1,2,3,4,(*main)},
};
printf("%d",KBD[0].KeyCurrentIndex);
printf("%d",KBD[0].KeyEnterState);
printf("%d",KBD[0].KeyCancelState);
printf("%d",KBD[0].KeyUpState);
printf("%d",KBD[0].KeyDownState);
printf("%d",KBD[1].KeyCurrentIndex);
printf("%d",KBD[1].KeyEnterState);
printf("%d",KBD[1].KeyCancelState);
printf("%d",KBD[1].KeyUpState);
printf("%d",KBD[1].KeyDownState);
printf("%5s",KBD[0].CurrentOperate);

}



评论


技术专区

关闭