1、lcd的多屏多层菜单程序#include #include #include #define INPUTSET256; #define DEBUG 0 /0:运行,1:调试 #define ENABLE_INTERRUPT 1/1:中断允许,0:中断禁止 /定义8155地址 #define I8155A0x7000 #define I8155B0x7200 #definePA1 #define PB2 #define PC3 /定义25045地址 #define OUTNUMBER 0x01a1 #define INNUMBER 0x01a2 #define PASSWORD_ADDR 0x0
2、1a3 #define HIDE_PASSWORD_ADDR 0x01af /定义键盘扫描码 #defineBUTTON_START0x28 #define BUTTON_STOP0x48 #define BUTTON_SET0x84 #define BUTTON_OK0x88 #define BUTTON_SLAVE0x81 /0,1,2,3,4,5,6,7,8,9 unsigned char code keyscancode=0x82,0x11,0x12,0x14,0x21,0x22,0x24,0x41,0x42,0x44; #include #include /new var unsig
3、ned char bdata bitvar; sbit keypush=bitvar0; sbit rrtime_flag=bitvar1;/读取运行参数标志 sbit showflag=bitvar2; unsigned char keycode,tempkey,i,j; unsigned char menuitem=0x00; unsigned int runtime32; unsigned int xdata starttime36; unsigned int xdata stoptime32; unsigned int xdata betweentime32; unsigned cha
4、r xdata runno136; unsigned char xdata linkrun4; unsigned char xdata linkrunno14; unsigned char xdata submenuitem=0; unsigned long xdata i8155out; unsigned char xdata main_temp,outputnumber,inputnumber; unsigned int xdata tempvar9; char xdata showstr5= ; /new var end /定义DS12887地址 #define P12887SEC 0x
5、7f00/12887秒地址 #define P12887SEC_ALM 0x7f01/12887秒报警地址 #define P12887MIN 0x7f02/12887分地址 #define P12887MIN_ALM 0x7f03/12887分报警地址 #define P12887HOUR 0x7f04/12887时地址 #define P12887HOUR_ALM 0x7f05/12887时报警地址 #define P12887WEEK 0x7f06/12887星期地址 #define P12887DAY 0x7f07/12887日期地址 #define P12887MONTH 0x7f0
6、8/12887月地址 #define P12887YEAR 0x7f09/12887年地址 #define P12887MCA 0x7f0a/寄存器a地址 #define P12887MCB 0x7f0b/寄存器a地址 #define P12887MCC 0x7f0c/寄存器a地址 #define P12887MCD 0x7f0d/寄存器a地址 #define P12887RAM 0x7f0e/12887不掉电RAM起始地址 void init_12887(); /DS12887初始化程序 void gettime_12887(); /取DS12887时间子程序(年月日时分) void set
7、time_12887(); /设置DS12887时间子程序 void i8155_init(unsigned int memaddress,unsigned char command); /intel 8155 端口输出 /memaddress:8155基址; /portnum:端口号(1:PA、2:PB、3:PC) /portstatu:端口输出字 void i8155_outport(unsigned int memaddress,unsigned char portnum,unsigned char portstatu); /intel 8155 端口输入 /memaddress:815
8、5基址; /portnum:端口号(1:PA、2:PB、3:PC) /返回值:端口状态 unsigned char i8155_inport(unsigned int memaddress,unsigned char portnum); void showinitscreen(); void init(); void timer0() interrupt 1 using 1 unsigned char temp; /晶振为 11.0592MHZ 时计数 9216(0xdb00) 次为 10ms TH0=0xd8; TL0=0x00; temp=(XBYTE0x7e00&0x0f);/有键按下时
9、 !=0x0f if(temp!=0x0f)/是否有键按下 if(keypush=1) keycode=temp; if(XBYTE0x7ee0&0x0f)!=0x0f) keycode=keycode&0x1f; else if(XBYTE0x7ed0&0x0f)!=0x0f) keycode=keycode&0x2f; else if(XBYTE0x7eb0&0x0f)!=0x0f) keycode=keycode&0x4f; else if(XBYTE0x7e30&0x0f)!=0x0f) keycode=keycode&0x8f; else keypush=1; keycode=0;
10、else keypush=0; void ds12887_int1() interrupt 2 using 2 rrtime_flag=0; ACC=XBYTEP12887MCC; /读寄存器C 清除中断请求标志IRQF /* / /主程序 / /* void main() i8155out=0x00; x25045_disable(); outputnumber=x25045_readbyte(OUTNUMBER); for(i=0;ioutputnumber;i+) runtime=(int)0x00; runno1=0x00; starttime=x25045_readword(i*7)
11、; stoptime=x25045_readword(i*7+2); betweentime=x25045_readword(i*7+4); x25045_init(); init(); TH0=0xd8; TL0=0x00; /初始化变量 while(1) init_12887(); /* #if DEBUG x25045_disable(); #else x25045_init(); #endif /* TMOD=0x01; ET0=1; TR0=1; #if ENABLE_INTERRUPT EX1=1; PX1=1; PT0=0; #endif EA=1; /* /加入限时运行功能 i
12、f(x25045_readbyte(0x01bb)=1)&(menuitem!=0x20)&(menuitem!=0x1b) tempkey=0; gettime_12887(); for(i=0;i3;i+) if(tempvar=x25045_readbyte(0x01b5-3+i) tempkey+; else break; if(tempkey3) if(menuitem!=0x20) showflag=0; menuitem=0x20; else menuitem=0; tempkey=0x50; i=0; /* /主循环开始 tm12864_reset(); x25045_rese
13、twatchdog(); /键盘处理程序 if(keycode!=0)&(keypush=0) i=0; while(i10) if(keycode=keyscancode) tempkey=i; break; else tempkey=keycode; i+; else tempkey=0x50; keycode=0; /屏幕显示处理 switch(menuitem) case 0x00:/自动运行状态 tm12864_reset(); if(showflag=0) tm12864_fillscreen(0x00); showflag=1; showinitscreen(); tm12864
14、_writestr(0,0, ,0); tm12864_writestr(12,0, ,0); tm12864_writestr(0,4, ,0); tm12864_writestr(0,6, ,0); tm12864_writehz(4,6,zzyx,0); tm12864_writestr(12,6, ,0); if(tempkey=BUTTON_STOP)/进入“设置确认”菜单 j=0; menuitem=0x01; showflag=0; tempkey=0x50; break; case 0x01:/设置确认菜单 tm12864_reset(); if(showflag=0) tm1
15、2864_fillscreen(0x00); tm12864_writestr(4,6, ,1); tm12864_writehz(0,6,mm,0); showflag=1; showinitscreen(); if(j6)&(tempkey0x0a) tm12864_writehz(0,6,mm,0); tm12864_writestr(j+4),6,*,1); tempvarj=tempkey; j+; if(j=6) for(j=0;j6;j+) if(tempvarj!=x25045_readbyte(PASSWORD_ADDR+j) j=0; showflag=0; menuite
16、m=0x00; break; tm12864_writestr(0,6, ,0); tm12864_writestr(6,6, ,0); tm12864_writehz(2,6,set,1); tm12864_writehz(10,6,yunxing,0); if(tempkey=BUTTON_OK) menuitem=0x03; j=0; submenuitem=0; showflag=0; tempvar0=1; submenuitem=0; if(tempkey=BUTTON_START) menuitem=0x00; showflag=0; tempkey=0x50; break; c
17、ase 0x02:/运行确认菜单 tm12864_reset(); if(showflag=0) tm12864_fillscreen(0x00); showflag=1; showinitscreen(); switch(submenuitem) case 0x00: tm12864_writehz(2,6,set,0); tm12864_writehz(10,6,yunxing,1); switch(tempkey) case BUTTON_OK: menuitem=0x00; showflag=0; while(1); break; case BUTTON_STOP: case BUTT
18、ON_SLAVE: submenuitem=0x01; showflag=0; break; break; case 0x01: tm12864_writehz(2,6,set,1); tm12864_writehz(10,6,yunxing,0); switch(tempkey) case BUTTON_OK: menuitem=0x03; showflag=0; submenuitem=0x00; break; case BUTTON_START: case BUTTON_SLAVE: submenuitem=0; showflag=0; break; break; tempkey=0x5
19、0; break; case 0x03:/设置菜单 tm12864_reset(); if(showflag=0) tm12864_fillscreen(0x00); showflag=1; j=0; x25045_writestatu(0x00); / * /加入隐蔽菜单功能 if(j6)&(tempkey0x0a) tempvarj=tempkey; j+; showstr0=j+0x30; showstr1=0; tm12864_writestr(15,7,showstr,0); tempkey=0x50; if(j=6) for(j=0;j6;j+) #if DEBUG tempvar
20、j=x25045_readbyte(0x01a9+j); #else if(tempvarj!=x25045_readbyte(0x01a9+j) j=0; break; #endif if(tempkey=BUTTON_SET) menuitem=0x1b; j=0; submenuitem=0; showflag=0; tempvar0=1; / * switch(submenuitem) case 0x00: tm12864_writestr(0,0,1 ,1); tm12864_writehz(2,0,scsd,1); tm12864_writestr(0,2,2 ,0); tm128
21、64_writehz(2,2,srsd,0); tm12864_writestr(0,4,3 ,0); tm12864_writehz(2,4,lssd,0); tm12864_writestr(0,6,4 ,0); tm12864_writehz(2,6,xtcs,0); break; case 0x01: tm12864_writestr(0,0,1 ,0); tm12864_writehz(2,0,scsd,0); tm12864_writestr(0,2,2 ,1); tm12864_writehz(2,2,srsd,1); tm12864_writestr(0,4,3 ,0); tm
22、12864_writehz(2,4,lssd,0); tm12864_writestr(0,6,4 ,0); tm12864_writehz(2,6,xtcs,0); break; case 0x02: tm12864_writestr(0,0,1 ,0); tm12864_writehz(2,0,scsd,0); tm12864_writestr(0,2,2 ,0); tm12864_writehz(2,2,srsd,0); tm12864_writestr(0,4,3 ,1); tm12864_writehz(2,4,lssd,1); tm12864_writestr(0,6,4 ,0);
23、 tm12864_writehz(2,6,xtcs,0); break; case 0x03: tm12864_writestr(0,0,1 ,0); tm12864_writehz(2,0,scsd,0); tm12864_writestr(0,2,2 ,0); tm12864_writehz(2,2,srsd,0); tm12864_writestr(0,4,3 ,0); tm12864_writehz(2,4,lssd,0); tm12864_writestr(0,6,4 ,1); tm12864_writehz(2,6,xtcs,1); break; switch(tempkey) c
24、ase BUTTON_START: menuitem=0x02; submenuitem=0; showflag=0; break; case BUTTON_SLAVE: if(submenuitem0x03) submenuitem+; else submenuitem=0x00; break; case BUTTON_OK: menuitem=0x04+submenuitem; /如果密码与隐蔽选单密码相符则进入隐蔽选单 /* if(check_password(HIDEMENU) menuitem=0x20; */ submenuitem=0x00; tempvar0=0x00; showflag=0; break; tempkey=0x50; break; case 0x04:/输出设定菜单 tm12864_reset(); if(showflag=0) tm12864_fillscreen(0x00);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1