proteus8.6和谐版软件 (无需破解)链接:https://pan.baidu.com/s/1i4TyS7b 密码: 游客,本帖隐藏的内容需要积分高于 10 才可浏览,您当前积分为 0
单片机源程序如下:
- #include<reg52.h>
- #include"lcd1602.h"
- #define Null 0
- sbit LED0 = P1^7;
- u8 t0count=0;
- struct MenuItem MainMenu[2];
- struct MenuItem TimeMenu[4];
- void NullSubs(void)
- {
- }
- void TimeSet(void)
- {
- LED0=!LED0;
- WriteCom(0X01);
- if(LED0)DisplayString(4,1,"LED0 OFF");
- else DisplayString(4,1,"LED0 ON");
- t0count=0;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TR0=1;
-
- }
- void DateSet(void)
- {
- }
- void AlertSet(void)
- {
- }
- struct MenuItem{
- u8 MenuCount;
- u8 *title;
- void (*subs)();
- struct MenuItem *ChildMenu;
- struct MenuItem *ParentMenu;
- };
- struct MenuItem MainMenu[2]=
- {
- {2,"1:TimeSet ",NullSubs,TimeMenu,Null},
- {2,"2:Back ",NullSubs,Null,Null}
- };
- struct MenuItem TimeMenu[4]=
- {
- {4,"1:Time_Set ",TimeSet,Null,MainMenu},
- {4,"2:Date_Set ",DateSet,Null,MainMenu},
- {4,"3:Alert_Set",AlertSet,Null,MainMenu},
- {4,"4:Back ",NullSubs,MainMenu,MainMenu},
-
- };
- struct MenuItem (*MenuPoint)=MainMenu;
- u8 DisplayStart=0;
- u8 UserChoose=0;
- u8 DisplayPoint=0;
- u8 MaxItems;
- u8 ShowCount=2;
- void Show_Menu(void)
- {
- u8 n;
- MaxItems=(*MenuPoint).MenuCount;
- //MaxItems=MenuPoint[0].MenuCount;
- DisplayPoint=DisplayStart;
- for(n=0;DisplayPoint<MaxItems&&n<ShowCount;n++)
- {
- if(UserChoose==DisplayPoint)DisplayString(1,n+1,"->");
- else DisplayString(1,n+1," ");
- DisplayString(3,n+1,MenuPoint[DisplayPoint++].title);
- }
- }
- sbit fanhui=P3^4;
- sbit ok=P3^5;
- void KeyScan(void)
- {
- static u8 state=1;
- if(state&&((fanhui==0)||(ok==0)))
- {
- delayms(8);
- state=0;
- if(ok==0)
- {
- if (MenuPoint[UserChoose].subs != NullSubs)
- {
- (*MenuPoint[UserChoose].subs)();
- }
- else if (MenuPoint[UserChoose].ChildMenu != Null)
- {
- MenuPoint = MenuPoint[UserChoose].ChildMenu;
- UserChoose = 0;
- DisplayStart = 0;
- }
- }else if(fanhui==0)
- {
- if (MenuPoint[UserChoose].ParentMenu != Null)
- {
- MenuPoint = MenuPoint[UserChoose].ParentMenu;
- UserChoose = 0;
- DisplayStart = 0;
- }
- }
- }else if((fanhui==1)&&(ok==1)){state=1;}
- }
- void main(void)
- {
- LcdInit();
- IT0=1;
- EX0=1;
- IT1=1;
- EX1=1;
- TMOD=0X01;
- ET0=1;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TR0=0;
- EA=1;
- while(1)
- {
-
- KeyScan();
- if(UserChoose/ShowCount==1)DisplayStart=2;
- else DisplayStart=0;
- WriteCom(0x0c);
- if((t0count>20)||(TR0==0))Show_Menu();
-
-
-
-
-
- }
-
-
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
lcd1602菜单.rar
(84.64 KB, 下载次数: 109)
|