?? lcd_menu.c
字號(hào):
///////////菜單顯示,鍵盤(pán)輸入例程////////////////
///////////lcd_menu.c////////////////////////////
#include "lcd.h"
#include "stdio.h"
#define SUB_MENU_NUM 3
#define MAIN_MENU_NUM 5
code uchar mainmenu[MAIN_MENU_NUM][16] ={"target1","sub_menu_demo","get int from key","get float key","show key data"};
code uchar submenu0[SUB_MENU_NUM][16]={"submenu1","submenu2","submenu3"};
extern bit isline0;
xdata int intnumber;
xdata float floatnumber;
void get_int_number();
void showkeydata();
void target1();
void sub_target1();
void sub_target1();
void sub_target3();
void sub_menu_demo();
void config (void) ;
void get_int_number(){//從鍵盤(pán)獲取int型數(shù)據(jù),并將之存入intnumber全局變量中
showline("entry",0);//利用筆者自定義函數(shù)實(shí)現(xiàn)顯示
while(scankey()==2);
intnumber=getint();//獲取int型數(shù)據(jù)
showline("number has saved",0);
while(scankey()==2);
}
void get_float_number(){//從鍵盤(pán)獲取float型數(shù)據(jù),并將之存入floatnumber全局變量中
showline("entry",0);
while(scankey()==2);
floatnumber=getfloat();//獲取float型數(shù)據(jù)
showline("number has saved",0);
while(scankey()==2);
}
void showkeydata(){//顯示intnumber數(shù)據(jù)
showline("entry",0);
while(scankey()==2);
isline0=1;//將顯示行控制到第一行
printf("\nkey_int=%d",intnumber);//顯示于第一行,利用庫(kù)函數(shù)實(shí)現(xiàn)顯示
printf("\nfloat=%.4f",floatnumber);//顯示于第二行
delay1ms(3000);
}
void target1(){//任務(wù)1,顯示浮點(diǎn)數(shù),事實(shí)上是顯示長(zhǎng)整型數(shù),并將小數(shù)點(diǎn)移位
showline("entry",0);
while(scankey()==2);
showpage("show float",0);
showf(intnumber,3,1);//小數(shù)點(diǎn)左移3位,即顯示數(shù)據(jù)帶3位小數(shù)
delay1ms(3000);
}
void sub_target1(){//子任務(wù)1,調(diào)用showpage函數(shù)一次性顯示兩行內(nèi)容
showpage("sub_target1 start...","^_^");
delay1ms(2000);
}
void sub_target2(){//子任務(wù)2,調(diào)用showline函數(shù)單行顯示
showline("sub_target2 start...",0);//在第一行顯示內(nèi)容
showline("hello world",1);//在第二行顯示內(nèi)容
delay1ms(2000);
}
void sub_target3(){//子任務(wù)3
int t=-346;
showline("sub_target3 start...",0);//第一行顯示字符串
showint(t,1);//第二行顯示int型數(shù)據(jù)(負(fù)數(shù))
delay1ms(2000);
}
void sub_menu_demo(){//二級(jí)菜單
xdata uchar submenu;
showline("entry",0);
while(scankey()==2);
while(1){
submenu=menu_sec("SUB_MENU ",submenu0,SUB_MENU_NUM);
if(submenu==0){
showline("entry_M1",0);
while(scankey()==2);
sub_target1();
goto sub_end;
}
if(submenu==1){
showline("entry_M2",0);
while(scankey()==2);
sub_target2();
goto sub_end;
}
if(submenu==2){
showline("entry_M3",0);
while(scankey()==2);
sub_target3();
goto sub_end;
}
}
sub_end:;
}
void config (void) {
//看門(mén)狗禁止
WDTCN = 0x07;
WDTCN = 0xDE;
WDTCN = 0xAD;
SFRPAGE = 0x0F;
XBR0 = 0x00;
XBR1 = 0x00;
XBR2 = 0x40; //交叉開(kāi)關(guān)使能,使得P0-P3口能輸出
XBR3 = 0x00;
SFRPAGE = 0x0F;
P0MDOUT = 0x00; //端口配置,P0-P3,P6-P7口為開(kāi)漏輸出
P1MDOUT = 0x00;
P2MDOUT = 0x00;
P3MDOUT = 0x00;
P4MDOUT = 0x00; //P4口為開(kāi)漏,也可推挽
P5MDOUT = 0x07;
P6MDOUT = 0x00;
P7MDOUT = 0x00;
P1MDIN = 0xFF; //所有端口為數(shù)字輸入,沒(méi)有模擬輸入端口
P2MDIN = 0xFF;
P3MDIN = 0xFF;
SFRPAGE = 0x0F;
CLKSEL = 0x00;
OSCXCN = 0x00;
OSCICN = 0x84;
//采用內(nèi)部晶振,為24.5MHZ8分頻
}
main(){
xdata uchar menuval;
config();
dispini();
for(;;){//按左右翻頁(yè)鍵選擇菜單,按確認(rèn)鍵進(jìn)入菜單調(diào)用相應(yīng)函數(shù)
menuval=menu_sec("MAIN_MENU ",mainmenu,MAIN_MENU_NUM);//主菜單
if(menuval==0){
target1();
}
if(menuval==1){
sub_menu_demo();//進(jìn)入二級(jí)菜單
}
if(menuval==2){
get_int_number();//從鍵盤(pán)輸入數(shù)據(jù)
}
if(menuval==3){
get_float_number();//從鍵盤(pán)輸入數(shù)據(jù)
}
if(menuval==4){
showkeydata();//顯示鍵盤(pán)所輸入的數(shù)據(jù)
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -