首页资源分类编程语言C/C++ > C语言 状态机 菜单程序

C语言 状态机 菜单程序

已有 445005个资源

下载专区

上传者其他资源

    文档信息举报收藏

    标    签:状态机C语言

    分    享:

    文档简介

    状态机 C语言 菜单程序 aaa

    文档预览

    #include "menu.h" #include "bsp_ili9341_lcd.h" #include "bsp_matrixkey.h" extern void Lcd_Delay(__IO uint32_t nCount); extern void Delay_us(__IO u32 nTime); //lcd 240*320 // LCD_DispStr(40, 100, (uint8_t *)"count:", RED); // LCD_DisNum(100, 100, n, RED); #define UP 14 #define DOWN 15 #define OK 13 #define RETN 12 #define INPUT 10 #define DEL 11 #define main 1 #define sub1 2 #define sub2 3 //////////////////////////////////////////////////////////////// uint8_t disp[5]; uint8_t n=0; uint8_t key; /////////////////////////////////////////////////////////////// uint8_t menustate=1,menusel=1; uint8_t input_on=0,del_on=0; //int gotosub=0,gotomain=0; //disp sel <------- void Disp_Sel1(void) { LCD_DispStr(50,115,(uint8_t *)"1.sub menu 1 (base)",GREEN); LCD_DispStr(165,115,(uint8_t *)"<------",GREEN); LCD_DispStr(50,125,(uint8_t *)"2.sub menu 2 (ext)",RED); LCD_DispStr(165,125,(uint8_t *)" ",BLACK); } void Disp_Sel2(void) { LCD_DispStr(50,115,(uint8_t *)"1.sub menu 1 (base)",RED); LCD_DispStr(165,115,(uint8_t *)" ",BLACK); LCD_DispStr(50,125,(uint8_t *)"2.sub menu 2 (ext)",GREEN); LCD_DispStr(165,125,(uint8_t *)"<------",GREEN); } void Disp_input_on(void) { LCD_DispStr(95,200,(uint8_t *)"on ",WHITE); } void Disp_input_off(void) { LCD_DispStr(95,200,(uint8_t *)"off",GREY); } void Disp_del_on(void) { LCD_DispStr(180,200,(uint8_t *)"on ",WHITE); } void Disp_del_off(void) { LCD_DispStr(180,200,(uint8_t *)"off",GREY); } void submenu1(void) { // uint8_t i; // uint8_t m1_disp_x=140,m1_disp_y=100; LCD_Clear(0, 0, 240, 320, BACKGROUND); menustate=sub1; LCD_DispStr(70,30,(uint8_t *)"Sub Menu 1",RED); LCD_DispStr(100,100,(uint8_t *)"input: ",BLUE); LCD_DispStr(20,200,(uint8_t *)"input_state:",YELLOW); LCD_DispStr(120,200,(uint8_t *)"del_state:",YELLOW); if(input_on==1) { Disp_input_on(); } else { Disp_input_off(); } if(del_on==1) { Disp_del_on(); } else { Disp_del_off(); } while(input_on==1) { key=GetMatrixKey(); if( (key==0) || (key==1)|| (key==2)|| (key==3)|| (key==4) || (key==5)|| (key==6)|| (key==7)|| (key==8)|| (key==9)) { input_on=0; } } menuwork(); LCD_DisNum(140,100,key,GREEN); // Lcd_Delay(100000); Lcd_Delay(900000); } void submenu2(void) { LCD_Clear(0, 0, 240, 320, BACKGROUND); menustate=sub2; LCD_DispStr(70,30,(uint8_t *)"Sub Menu 2",RED); Lcd_Delay(50); } void mainmenu(void) { //////////////////////////// ////////////////////// LCD_Clear(0, 0, 240, 320, BACKGROUND); menustate=main; menusel=sub1; LCD_DispStr(60,50,(uint8_t *)"welcome to use...",RED); LCD_DispStr(80,100,(uint8_t *)"main menu",BLUE); Disp_Sel1(); Lcd_Delay(50); } void menuwork(void) { switch(menustate) { case main: if(GetMatrixKey()==DOWN) { Disp_Sel2(); menusel=sub2; } else if(GetMatrixKey()==UP) { Disp_Sel1(); menusel=sub1; } break; case sub1: if(GetMatrixKey()==RETN) { mainmenu(); } if(GetMatrixKey()==INPUT) { if(input_on==0) { input_on=1; Disp_input_on(); } else if(input_on==1) { input_on=0; Disp_input_off(); } } else if(GetMatrixKey()==DEL) { if(del_on==0) { del_on=1; Disp_del_on(); } else if(del_on==1) { del_on=0; Disp_del_off(); } } break; case sub2: if(GetMatrixKey()==RETN) { mainmenu(); } break; default: break; } if((GetMatrixKey()==OK)) { switch(menusel) { case sub1: submenu1(); break; case sub2: submenu2(); break; default: break; } } }

    Top_arrow
    回到顶部
    EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高员外,我们会尽快处理。