2020-01-20 19:05发布
lswhome 发表于 2014-5-28 08:46 呃,难道这个问题太简单了??竟然没有人回答???
lswhome 发表于 2014-5-28 10:38 比如这个也算是个菜单,可以调整一些参数,界面也不难看。
最多设置5个标签!
可以先研究架构
再研究结构体啊
http://www.amobbs.com/forum.php? ... p;extra=#pid7570190
- static void System_Set(void)//环境设置子菜单
- {
- UINT8 xdata Select=0;
- UINT8 xdata Last_Select=0;
- bit RePaint=1;//是否重画整个菜单项
- while(1)
- {
- if(RePaint==1)
- {
- ST7565_Paint_RectangleFill(0,0,64,128,0);//清屏
- ST7565_Paint_Rectangle(0,10,64,108,1);
- ST7565_Paint_HLine(13,10,108,1);//横线
- ST7565_Paint_MixStr(1,40,"环境设定",0);
- }
- if(Select==0 || Last_Select==0 || RePaint==1)
- {
- ST7565_Paint_MixStr(19,40,"系统时间",(Select==0)?1:0);
- }
- if(Select==1 || Last_Select==1 || RePaint==1)
- {
- ST7565_Paint_MixStr(32,40,"屏幕设定",(Select==1)?1:0);
- }
- if(Select==2 || Last_Select==2 || RePaint==1)
- {
- ST7565_Paint_MixStr(45,40,"重启模式",(Select==2)?1:0);
- }
- RePaint=0;
- Last_Select=Select;//保存上次的选择
- ST7565_Paint_Push_Data();//刷新显示
- //键盘
- Key_Scan();//扫描键盘
- while(Key_Trg==0)//等待按一个键
- {
- Key_Scan();//扫描键盘
- }
- if(Key_Trg & Key_Cancel)//Key_Cancel
- {
- break;
- }
- if(Key_Trg & Key_plus)//Key_+
- {
- (Select>1)?(Select=0):(Select++);
- }
- if(Key_Trg & Key_Minus)//Key_-
- {
- (Select<1)?(Select=2):(Select--);
- }
-
- if(Key_Trg & Key_Ok)//Key_Ok
- {
- if(Select==0)
- {
- Menu_Time_Set();//时间设定
- }
- if(Select==1)
- {
- Menu_Screen_Set();//屏幕设定
- }
-
- if(Select==2)
- {
- Menu_Boot_Operating();//重启后操作
- }
- ST7565_Paint_RectangleFill(0,0,64,128,0);//清屏
- RePaint=1;
- }
- }
- }
复制代码一个菜单一个函数,都是类似这样的,这样的好处就是节省内存,什么样的奇葩菜单都能做的出来(包括那种可以编辑的,可以调整数字之类的),缺点就是浪费大量的代码空间。。。感觉不好
- static void Menu_Screen_Set(void)//屏幕设定
- {
- UINT8 xdata Select=0;
- UINT8 xdata Last_Select=0;
- bit RePaint_Menu=1;
-
- UINT8 xdata str[4];
- UINT8 xdata tmp1=Roms[0];
- UINT8 xdata tmp2=Roms[1];
- UINT8 xdata tmp3=Roms[31];
- bit RePaint=1;//是否重画整个菜单项
- while(1)
- {
- if(RePaint==1)
- {
- ST7565_Paint_RectangleFill(0,0,64,128,0);//清屏
- ST7565_Paint_Rectangle(0,8,64,112,1);//边框
- ST7565_Paint_HLine(13,8,112,1);//横线
- ST7565_Paint_MixStr(1,40,"屏幕设定",0);
- ST7565_Paint_MixStr(18,28,"屏幕对比度",0);
- ST7565_Paint_MixStr(32,19,"关闭时间 时 分",0);
- ST7565_Paint_MixStr(46,22,"数码管对比度",0);
- ST7565_Paint_HLine(30,88,12,1);//
- ST7565_Paint_HLine(44,67,6,1);//
- ST7565_Paint_HLine(44,85,12,1);//
- ST7565_Paint_HLine(58,94,12,1);//
- }
- if(Select==0 || Last_Select==0 || RePaint_Menu==1)//选择了第1项
- {
- sprintf(str,"%02d", (UINT16)tmp1);//对比度
- ST7565_Paint_MixStr(18,88,str,(Select==0)?1:0);
- }
-
- if(Select==1 || Last_Select==1 || RePaint_Menu==1)//选择了第1项
- {
- sprintf(str,"%01d", (UINT16)(tmp2/60));//
- ST7565_Paint_MixStr(32,67,str,(Select==1)?1:0);//时
- sprintf(str,"%02d", (UINT16)(tmp2%60));//
- ST7565_Paint_MixStr(32,85,str,(Select==1)?1:0);//分
- }
-
- if(Select==2 || Last_Select==2 || RePaint_Menu==1)//选择了第1项
- {
- sprintf(str,"%02d", (UINT16)(tmp3));//
- ST7565_Paint_MixStr(46,94,str,(Select==2)?1:0);//数码管对比度
- }
-
- RePaint=0;
- Last_Select=Select;//保存上次的选择
- ST7565_Paint_Push_Data();//刷新显示
- //键盘
- Key_Scan();//扫描键盘
- while(Key_Trg==0)//等待按一个键
- {
- Key_Scan();//扫描键盘
- }
- if(Key_Trg & Key_Cancel) break;
- if(Key_Trg & Key_Select)
- {
- Select>1?Select=0:Select++;
- }
- if(Key_Trg & Key_plus)
- {
- if(Select==0) (tmp1>51)?(tmp1=25):(tmp1++);//对比度
- if(Select==1) (tmp2>254)?(tmp2=1):(tmp2++);//关屏时间
- if(Select==2) (tmp3>6)?(tmp3=0):(tmp3++);
- }
- if(Key_Trg & Key_Minus)
- {
- if(Select==0) (tmp1<26)?(tmp1=52):(tmp1--);//对比度
- if(Select==1) (tmp2<2)?(tmp2=255):(tmp2--);//关屏时间
- if(Select==2) (tmp3<1)?(tmp3=7):(tmp3--);
- }
- if(Key_Trg & Key_Ok)
- {
- Roms[0]=tmp1;//对比度的值
- Roms[1]=tmp2;//关屏时间的值
- Roms[31]=tmp3;
- SaveOfSetting();//保存设置
- break;
- }
- ST7565_Set_Contrast(tmp1);//即时做出对比度的设定
- TM1638_SetContrast(tmp3);//立即更改TM1638的对比度
- }
- }
复制代码这个函数,里面有while循环,你要是不按键让其跳出,单片机不就在死等了?
一周热门 更多>