#include <reg51.h> #include <intrins.h> #include <absacc.h> // typedef struct { unsigned int KeyTab_MenuIndex; //当前状态索引号 unsigned int KeyTab_MaxItems; //本级菜单最大条目数 unsigned int KeyTab_PressOk; //按下"回车"键时转向的状态索引号 unsigned int KeyTab_PressEsc; //按下"返回"键时转向的状态索引号 unsigned int KeyTab_PressDown; //按下"向下"键时转向的状态索引号 unsigned int KeyTab_PressUp; //按下"向上"键时转向的状态索引号 void (*CurrentOperate)(); //当前状态应该执行的功能操作 }KeyTabStruct; void (*KeyFuncPtr)(); //按键功能指针 // #define S_S 0x80 //上 =1000,0000=0x80, #define S_X 0x40 //下 =0100,0000=0x40, #define S_Z 0x20 //左 =0010,0000=0x20, #define S_Y 0x10 //右 =0001,0000=0x10, #define S_ZS 0xa0 //左上 =1010,0000=0xa0, #define S_ZX 0x60 //左下 =0110,0000=0x60, #define S_YS 0x90 //右上 =1001,0000=0x90, #define S_YX 0x50 //右下 =0101,0000=0x50, #define S_SXZY 0xf0 //上下左右=1111,0000=0xf0 // #define KEY_OK 0x11 #define KEY_UP 0x12 #define KEY_ESC 0x13 // #define KEY_LEFT 0x21 #define KEY_DOWN 0x22 #define KEY_RIGHT 0x23 // #define KEY_1 0x31 #define KEY_2 0x32 #define KEY_3 0x33 // #define KEY_4 0x41 #define KEY_5 0x42 #define KEY_6 0x43 // #define KEY_7 0x51 #define KEY_8 0x52 #define KEY_9 0x53 // #define KEY_XING 0x61 #define KEY_0 0x62 #define KEY_JING 0x63 // #define KEY_POWER 0x71 #define KEY_NULL 0x00 // // #define MAX_KEYTABSTRUCT_NUM 19 #define MENU_FACE 0 #define MENU_ROOT 1 #define MENU_VIEW 2 #define MENU_VIEW_ABOUTRECORDE 3 #define MENU_VIEW_HANDSETCLOCK 4 #define MENU_OPERATION 5 #define MENU_OPERATION_SETPOSITION 6 #define MENU_OPERATION_READZJTOFLASH 7 #define MENU_OPERATION_RDZJTORAM 8 #define MENU_OPERATION_DELGIVENZL 9 #define MENU_OPERATION_DELALLZJ 10 #define MENU_TEST 11 #define MENU_TEST_RAMTEST 12 #define MENU_TEST_FLASHTEST 13 #define MENU_SYSTEMSET 14 #define MENU_SYSTEMSET_DEBUG 15 #define MENU_SYSTEMSET_DEBUG_PASSWORD 16 #define MENU_SYSTEMSET_DEBUG_SEEPICTURE 17 #define MENU_SYSTEMSET_SETHANDCLK 18 // #define Addr_Key 0xc000 //1100,0000,0000,0000 #define Addr_XRamBegin1 0x0000 //0000,0000,0000,0000 //共32K #define Addr_XRamEnd1 0x3fff //0011,1111,1111,1111 #define Addr_XRamBegin2 0x4000 //0100,0000,0000,0000 #define Addr_XRamEnd2 0x7fff //0111,1111,1111,1111 #define Addr_XFlashBegin 0x9000//1000,0000,0000,0000 16K/每自然扇区 #define Addr_XFlashEnd 0xbfff//1011,1111,1111,1111 #define Addr_XFlashSector 0xc001//1100,0000,0000,0001 4个自然扇区(把FLASH的地址线移到这个口内容的低位) //Flash可用容量=4*16K=64K //自然扇区的内容字节范围(0->3)(0000,0000~0000,0011)共4块=64K,硬件上把A18,A17,A16锁住了,不能写) //能读不能写的扇区号为4-31为(0000,0100~0001,1111)共28块=448K,可以作为菜单位置 //#define Addr_XFlashBegin 0x9000//1000,0000,0000,0000 16K/每自然扇区 //#define Addr_XFlashEnd 0xbfff//1011,1111,1111,1111 //能读能写的FLASH的连续地址如下: //#define Addr_XFlashBegin 0x0000//共64K //#define Addr_XFlashEnd 0xffff // //操作FLASH地址时, //1.算出页地址 //2. 对扇区解锁(读扇区不用解锁):(0x5555)=0xaa,(0x2aaa)=0x55,(0x5555)=0xa0; //3。把高2位移入[Addr_XFlashSector]=0的低2位, //4。把原来的高2位置0,再或上10B //5. 然后整个扇区读/写256字节 //片外数组0x0000~0x1fff; unsigned char xdata Rev232Buffer[256] _at_ 0x0000; //->0x00ff unsigned char xdata Send232Buffer[256] _at_ 0x0100; //->0x1ff #define Addr_FlashWriteBuffer1 0x0200 //->0x2ff #define Addr_FlashWriteBuffer2 0x0300 //->0x3ff #define Addr_FlashReadBuffer1 0x0400 //->0x4ff #define Addr_FlashReadBuffer2 0x0500 //->0x5ff #define Addr_ZjWrRdBuffer 0x0800 //->0xfff unsigned char xdata clock[12]_at_ 0x1000; //->0x100b // unsigned char xdata cGraphByte[8]_at_ 0x100e; //->0x1015 unsigned char xdata * xdata cpGraph _at_ 0x1016; //->0x1017 signed char xdata cMenuHLight[0x10]_at_ 0x1018; KeyTabStruct xdata KeyTab[MAX_KEYTABSTRUCT_NUM] _at_ 0x1028; unsigned char xdata CxTestByte1 _at_ 0x1145; //片外单变量0x2000~0x2fff; //通讯专用 unsigned char xdata cUartTemp1 _at_ 0x2000; unsigned char xdata cUartTemp2 _at_ 0x2001; unsigned char xdata cUartTemp3 _at_ 0x2002; unsigned char xdata cUartFunSn _at_ 0x2003; unsigned char xdata cUartDataLenght _at_ 0x2004; unsigned char xdata cUartAddSum _at_ 0x2005; unsigned char xdata cUartXorSum _at_ 0x2006; unsigned char xdata iUartTemp1 _at_ 0x2007; unsigned char xdata iUartTemp2 _at_ 0x2008; unsigned char xdata iUartTemp3 _at_ 0x2009; //Flash专用 unsigned char xdata cPageAddr _at_ 0x2010; unsigned int xdata iSectorAddr _at_ 0x2011; unsigned int xdata iFlashToRamAddr _at_ 0x2013; unsigned int xdata iRamToFlashAddr _at_ 0x2015; unsigned char xdata iFlashAddrH _at_ 0x2017; unsigned char xdata iFlashAddrM _at_ 0x2018; unsigned char xdata iFlashAddrL _at_ 0x2019; unsigned char xdata iFlashRdWrNum _at_ 0x201a; //菜单专用 unsigned char xdata cMenuTemp1 _at_ 0x2020; unsigned char xdata cMenuTemp2 _at_ 0x2021; unsigned char xdata cMenuTemp3 _at_ 0x2022; // unsigned int xdata iMenuID _at_ 0x2023; unsigned int xdata iMenuNextID _at_ 0x2025; // //画线专用 unsigned char xdata cLineTemp1 _at_ 0x2030; unsigned char xdata cLineTemp2 _at_ 0x2031; unsigned char xdata cLineTemp3 _at_ 0x2032; unsigned char xdata cLineTemp4 _at_ 0x2033; unsigned char xdata cLineTemp5 _at_ 0x2034; unsigned char xdata cLineTemp6 _at_ 0x2035; unsigned char xdata cLineTemp7 _at_ 0x2036; unsigned char xdata cLineTemp8 _at_ 0x2037; unsigned char xdata cLineTemp9 _at_ 0x2038; unsigned char xdata cLineTemp10 _at_ 0x2039; unsigned char xdata cLineTemp11 _at_ 0x203a; unsigned char xdata cLineTemp12 _at_ 0x203b; unsigned char xdata cLineTemp13 _at_ 0x203c; //DispTextLine unsigned char xdata cTextLineTemp1 _at_ 0x203d; unsigned char xdata cTextLineTemp2 _at_ 0x203e; unsigned char xdata cTextLineTemp3 _at_ 0x203f; //图形字符专用 unsigned char xdata cGraphTemp1 _at_ 0x2040; unsigned char xdata cGraphTemp2 _at_ 0x2041; unsigned char xdata cGraphTemp3 _at_ 0x2042; unsigned char xdata cGraphTemp4 _at_ 0x2043; //主程序用 unsigned char xdata NowKey _at_ 0x2044; unsigned char xdata RxPos _at_ 0x2045; unsigned char xdata RxStep _at_ 0x2046; unsigned char xdata RxPrev _at_ 0x2047; unsigned char xdata RxNow _at_ 0x2048; unsigned char xdata RxDataLenght _at_ 0x2049; unsigned char xdata TxPos _at_ 0x204a; unsigned char xdata TxNum _at_ 0x204b; //中断0用 unsigned char xdata cTemp_ex0 _at_ 0x204c; //通讯中断用 unsigned int xdata i_uart _at_ 0x204d; //写Flash用 unsigned int xdata i_FlashWr _at_ 0x204f; unsigned char xdata c1_FlashWr _at_ 0x2051; //读Flash用 unsigned int xdata i_FlashRd _at_ 0x2052; unsigned char xdata c1_FlashRd _at_ 0x2054; //Make05Answe专用 unsigned int xdata i_Make05Answer _at_ 0x2055; unsigned char xdata cAdd_Make05Answer _at_ 0x2057; unsigned char xdata cXor_Make05Answer _at_ 0x2058; //读时间用 unsigned char xdata i_RdTime _at_ 0x2059; //显示文本行用 unsigned char xdata col_DispTextLine _at_ 0x205a; unsigned char code * xdata p_DispTextLine _at_ 0x205b; //显示开机画面 unsigned char xdata i_FaceBmp _at_ 0x205d; unsigned char xdata j_FaceBmp _at_ 0x205e; unsigned char xdata k_FaceBmp _at_ 0x205f; unsigned char xdata c1_FaceBmp _at_ 0x2060; //DisponeTextChar unsigned char xdata i_DisponeTextChar _at_ 0x2061; unsigned char xdata j_DisponeTextChar _at_ 0x2062; unsigned char xdata k_DisponeTextChar _at_ 0x2063; unsigned char xdata cTemp_DisponeTextChar _at_ 0x2064; //键处理程序专用 unsigned char xdata cKeyTemp1 _at_ 0x2065; //定时器0专用 unsigned int xdata iT0_1S _at_ 0x2066; unsigned char xdata cClock_Year _at_ 0x2068; unsigned char xdata cClock_Month _at_ 0x2069; unsigned char xdata cClock_Day _at_ 0x206a; unsigned char xdata cClock_Hour _at_ 0x206b; unsigned char xdata cClock_Minute _at_ 0x206c; unsigned char xdata cClock_Second _at_ 0x206d;
//cx //Timer #define TH0data 0xb8//20ms=0xb800,1ms=0xfc66 #define TL0data 0x00// // sbit LCD_CS=P1^0; sbit LCD_RESET=P1^1; sbit LCD_A0=P1^5; sbit LCD_WR=P1^6; sbit KEYINT=P3^2; sbit I2C_SCK=P3^4; sbit I2C_SDA=P3^5; // sbit KEYROW1=P1^5; sbit KEYROW2=P1^6; sbit KEYROW3=P1^7; // unsigned char bdata BitByte0; sbit bOldOnline=BitByte0^7; sbit b_ReceiveOver=BitByte0^6; sbit b_KeyInt=BitByte0^5; sbit b_Arrive1S=BitByte0^4; unsigned char bdata BitByte1; unsigned char bdata BitByte2; unsigned char bdata BitValue; sbit bOnline=BitValue^7; sbit bPowerOff=BitValue^6; unsigned char bdata BitValue1; sbit bBit7=BitValue1^7; sbit bBit6=BitValue1^6; sbit bBit5=BitValue1^5; sbit bBit4=BitValue1^4; sbit bBit3=BitValue1^3; sbit bBit2=BitValue1^2; sbit bBit1=BitValue1^1; sbit bBit0=BitValue1^0;
// // void lcd_write_d(unsigned char c1); void lcd_write_c(unsigned char c1); void LcdInit(); void MyInit(); // void DispOneBoxTextChar(unsigned char Row,unsigned char Col,unsigned char c1,unsigned char DispAttrib); void DispTwoBoxHexChar(unsigned char Row,unsigned char Col,unsigned char c1,unsigned char DispAttrib); void DispGraphChar(unsigned char Row,unsigned char Col,unsigned char xdata *cArray,unsigned char DispAttrib); void DispTextLine(unsigned char Row,unsigned char code *MenuText,unsigned char DispAttrib); // void ReadyForKey(); void DelayMs(unsigned int iMs); void UartProcess(); void IAmZj(); void IAmOk(); void IAmUnKnow(); void FlashSectorWr(unsigned int SourceXRamAddr,unsigned int TargetFlashAddr); void FlashSectorRd(unsigned int SourceFlashAddr,unsigned int TargetXRamAddr); void Make05Answer(); void Make06Answer(); void I2Cstart(void); void I2Csend(unsigned char); unsigned char I2Csuback(void); void I2Cmastack(void); unsigned char I2Cread(void); void I2Cnoack(void); void I2Cstop(void); void Make07Answer(); unsigned char set_time(); void Make08Answer(); void MakeBox(unsigned char row1,unsigned char col1,unsigned char row2,unsigned char col2); void MenuFunctionNull(); void MenuFunctionDemo1(); void MenuFunctionDemo2(); void MenuFunctionDemo3(); void MenuFunctionDemo4(); void MenuFunctionDemo5(); void MenuFunctionDemo6(); void MenuFunctionDemo7(); void MenuFunctionDemo8(); void MenuFunctionDemo9(); void MenuFunctionDemo10(); void MenuFunctionDemo11(); void MenuFunctionDemo12(); void MenuFunctionDemo13(); void MenuFunctionDemo14(); void MenuFunctionDemo15(); void MenuFunctionDemo16(); void MenuFunctionDemo17(); void MenuFunctionDemo18(); void MenuFunctionDemo19(); // void DispFaceBmp(); void DispMenu_Root(); void DispMenu_View(); void DispMenu_Operation(); void DispMenu_Test(); void DispMenu_SystemSet(); void DispMenu_Debug(); // void JudgeHLight(); // unsigned char ReadTime(); void ShowDesktopTime(); // unsigned char code Echar[96][8]; unsigned char code FaceBmp[112][8]; // unsigned char code *Menu_Root[4]= { " View ", " Operation ", " Test ", " System Set " }; unsigned int code Menu_RootID[4]= { MENU_VIEW, MENU_OPERATION, MENU_TEST, MENU_SYSTEMSET }; // unsigned char code *Menu_View[2]= { " About ZL ", " HandSet CLK " }; unsigned int code Menu_ViewID[2]= { MENU_VIEW_ABOUTRECORDE, MENU_VIEW_HANDSETCLOCK }; // unsigned char code *Menu_Operation[5]= { " Set Position ", " Rd Zj To ROM ", " Rd ZL To Ram ", " Del Given ZL ", " Del All ZL " }; unsigned int code Menu_OperationID[5]= { MENU_OPERATION_SETPOSITION, MENU_OPERATION_READZJTOFLASH, MENU_OPERATION_RDZJTORAM, MENU_OPERATION_DELGIVENZL, MENU_OPERATION_DELALLZJ }; // unsigned char code *Menu_Test[2]= { " Ram Test ", " Flash Test " }; unsigned int code Menu_TestID[2]= { MENU_TEST_RAMTEST, MENU_TEST_FLASHTEST }; // unsigned char code *Menu_SystemSet[2]= { " Debug ", " Set Hand Clk " }; unsigned int code Menu_SystemSetID[2]= { MENU_SYSTEMSET_DEBUG, MENU_SYSTEMSET_SETHANDCLK }; // unsigned char code *Menu_Debug[2]= { " PassWord ", " See Picture " }; unsigned int code Menu_DebugID[2]= { MENU_SYSTEMSET_DEBUG_PASSWORD, MENU_SYSTEMSET_DEBUG_SEEPICTURE }; // unsigned char code MenuNULL[]={" "}; // main() { MyInit(); LcdInit(); // cMenuHLight[0x00]=0x00; cMenuHLight[0x01]=0x00; cMenuHLight[0x02]=0x00; cMenuHLight[0x03]=0x00; cMenuHLight[0x04]=0x00; cMenuHLight[0x05]=0x00; cMenuHLight[0x06]=0x00; cMenuHLight[0x07]=0x00; cMenuHLight[0x08]=0x00; cMenuHLight[0x09]=0x00; cMenuHLight[0x0a]=0x00; cMenuHLight[0x0b]=0x00; cMenuHLight[0x0c]=0x00; cMenuHLight[0x0d]=0x00; cMenuHLight[0x0e]=0x00; cMenuHLight[0x0f]=0x00; // DelayMs(20); //调试用 MenuFunctionNull(); // BitValue=XBYTE[Addr_Key]; bOldOnline=(~bOnline); b_KeyInt=0; b_ReceiveOver=0; b_Arrive1S=0; // DispFaceBmp(); // iMenuID=MENU_FACE; // while(1) { ReadyForKey(); // BitValue=XBYTE[Addr_Key]; if(bOldOnline!=bOnline) { bOldOnline=bOnline; if(!bOldOnline) {//Line=1 } else {//Line=0; } } if(b_ReceiveOver) { // UartProcess(); // b_ReceiveOver=0; RxStep=0; RxPos=0; REN=1; } // if(b_KeyInt) { switch(NowKey) { case KEY_OK://KEY_OK, KEY_UP, KEY_ESC, if(KeyTab[iMenuID].KeyTab_PressOk!=999) { iMenuID=KeyTab[iMenuID].KeyTab_PressOk; iMenuNextID=KeyTab[iMenuID].KeyTab_PressOk; JudgeHLight(); } KeyFuncPtr=KeyTab[iMenuID].CurrentOperate; (*KeyFuncPtr)(); //执行当前按键的操作 break; case KEY_UP: if((KeyTab[iMenuID].KeyTab_PressUp!=999)&&(iMenuNextID!=999)) { KeyTab[iMenuID].KeyTab_PressOk=KeyTab[iMenuNextID].KeyTab_PressUp; iMenuNextID=KeyTab[iMenuNextID].KeyTab_PressUp; JudgeHLight(); } break; case KEY_ESC: // if(KeyTab[iMenuID].KeyTab_PressEsc!=999) { iMenuID=KeyTab[iMenuID].KeyTab_PressEsc; iMenuNextID=KeyTab[iMenuID].KeyTab_PressOk; JudgeHLight(); KeyFuncPtr=KeyTab[iMenuID].CurrentOperate; (*KeyFuncPtr)(); //执行当前按键的操作 } break; // case KEY_LEFT://KEY_LEFT, KEY_DOWN, KEY_RIGHT, if((KeyTab[iMenuID].KeyTab_PressUp!=999)&&(iMenuNextID!=999)) { KeyTab[iMenuID].KeyTab_PressOk=KeyTab[iMenuNextID].KeyTab_PressUp; iMenuNextID=KeyTab[iMenuNextID].KeyTab_PressUp; JudgeHLight(); } break; case KEY_DOWN: if((KeyTab[iMenuID].KeyTab_PressDown!=999)&&(iMenuNextID!=999)) { KeyTab[iMenuID].KeyTab_PressOk=KeyTab[iMenuNextID].KeyTab_PressDown; iMenuNextID=KeyTab[iMenuNextID].KeyTab_PressDown; JudgeHLight(); } break; case KEY_RIGHT: if((KeyTab[iMenuID].KeyTab_PressDown!=999)&&(iMenuNextID!=999)) { KeyTab[iMenuID].KeyTab_PressOk=KeyTab[iMenuNextID].KeyTab_PressDown; iMenuNextID=KeyTab[iMenuNextID].KeyTab_PressDown; JudgeHLight(); } break; // case KEY_1://KEY_1, KEY_2, KEY_3, break; case KEY_2: break; case KEY_3: break; case KEY_4://KEY_4, KEY_5, KEY_6, break; case KEY_5: break; case KEY_6: break; case KEY_7://KEY_7, KEY_8, KEY_9, break; case KEY_8: break; case KEY_9: break; case KEY_XING://KEY_XING, KEY_0, KEY_JING, break; case KEY_0: break; case KEY_JING: break; case KEY_POWER://KEY_POWER, KEY_NULL break; case KEY_NULL: MakeBox(3,3,5,12); break; // default: break; } b_KeyInt=0; } if((b_Arrive1S==1)&&(iMenuID==MENU_FACE)) { ReadTime(); // ShowDesktopTime(); // b_Arrive1S=0; } } } void isr_ex0(void) interrupt 0 using 1 { b_KeyInt=1; // cTemp_ex0=0xff; // DelayMs(20); ReadyForKey(); cTemp_ex0=XBYTE[Addr_Key]; // cTemp_ex0=cTemp_ex0&0x3f; switch(cTemp_ex0) { case 0x3e://第一行 NowKey=0x10; break; case 0x3d://第二行 NowKey=0x20; break; case 0x3b://第三行 NowKey=0x30; break; case 0x37://第四行 NowKey=0x40; break; case 0x2f://第五行 NowKey=0x50; break; case 0x1f://第六行 NowKey=0x60; break; default: NowKey=0x00; break; } // KEYROW1=0; KEYROW2=1; KEYROW3=1; cTemp_ex0=XBYTE[Addr_Key]; // cTemp_ex0&=0x3f; if(cTemp_ex0!=0x3f) { NowKey=NowKey|0x01; } else { KEYROW1=1; KEYROW2=0; KEYROW3=1; cTemp_ex0=XBYTE[Addr_Key]; // cTemp_ex0&=0x3f; if(cTemp_ex0!=0x3f) { NowKey=NowKey|0x02; } else { KEYROW1=1; KEYROW2=1; KEYROW3=0; cTemp_ex0=XBYTE[Addr_Key]; cTemp_ex0&=0x3f; if(cTemp_ex0!=0x3f) { NowKey=NowKey|0x03; } else { BitValue=XBYTE[Addr_Key]; if(!bPowerOff) { NowKey=0x71; } else { NowKey=0x00; } } } } // do { DelayMs(100); } while(!KEYINT); IE0=0; //清外中断0请求 }
void isr_t0(void) interrupt 1 using 2 { TL0=TL0data; TH0=TH0data; iT0_1S+=20; //因为定时器的定时为20Ms一次 if(iT0_1S>=1000) { iT0_1S=0; b_Arrive1S=1; } } // void isr_ex1(void) interrupt 2 using 1 { _nop_(); } // void isr_t1(void) interrupt 3 using 2 { _nop_(); } // void isr_ser(void) interrupt 4 using 3 { if(TI) { if((TxNum--)>0) { SBUF=Send232Buffer[TxPos++]; } else { TxNum=0; TxPos=0; } // TI=0; } else { RI=0; RxNow=SBUF; Rev232Buffer[RxPos++]=RxNow; if(RxPos>=255) { RxPos=0; } // if(!b_ReceiveOver) { switch(RxStep) { case 0: //帧头:55 55 if(RxNow==0x55) { if(RxPrev==0x55) { RxStep=1; } else { RxPrev=RxNow; RxPos=0; Rev232Buffer[RxPos++]=RxNow; RxStep=0; } } else { RxStep=0; RxPos=0; REN=1; } break; case 1: //命令帧和数据帧的判断 if((RxNow&0x80)==0) { RxStep=3; } else { RxPrev=RxNow; RxStep=2; }
|
|