/*------------------------------------------------------------------ ----------------TEST FUNCTION-------------------------------------- -----------------------------------------------------------------*/ void test(void) { int len, i; // set up length variable and index for topstring char topstring[] = { "This is a test" }; // this is the string that will be written on the top row char bottomstring[] = { "This is line 2" }; // this is the string that will be written on the bottom row Init_Lcd(); // Run Init_Lcd function which sets up LCD with your preferences len = strlen(topstring); // measure the length of topstring using strlen() and store the into in len1 variable { // lets write topstring to the LCD for (i = 0; i < len; i++) // the for loop steps through the string sending each letter Lcd_Send(topstring[i]); // the Lcd_Send function is run for the given letter of the topstring at index i } delay(50); // a quick delay in ms to allow LCD to display the value for a little bit before refreshing len = strlen(bottomstring); // measure length of the bottom string using strlen() from string.h Set_Cursor(0xC0); //set cursor to the beginning of the second line for (i = 0; i < len; i++) { Lcd_Send(bottomstring[i]); // Display the winner string on the LCD } delay(5000); // wait 5000ms so you can enjoy the feeling of victory Clear_LCD(); } // end test
char Proc_Paint(char *NC) { unsigned int pos[2] ; Color = Black ; Color_BK = 0xEF9F ; Clear_LCD(Color_BK) ; DrawRectFill(0,0,240,25,Blue) ; DrawRectFill(0,295,240,25,Blue) ; ShowIcon24(217,0,24,23,ICON_CLOSE) ; Color = 0xFFFF ; Color_BK = Blue ; PutStringCN16(4,4,"画笔") ; PutStringCN16(4,300,"清空") ; PutStringCN16(200,300,"退出") ; Color = Black ; Color_BK = WINDOW_BK_COLOR ; for(;;) { if(Read_TP_Twice(&pos[0],&pos[1])) { Convert_Pos(pos[0],pos[1], &pos[0],&pos[1] ) ; if(pos[0]<50&&pos[1]>295) DrawRectFill(0,25,240,270,WINDOW_BK_COLOR) ; else if( (pos[0]<230&&pos[0]>200&&pos[1]>295) ||(pos[0]>220&&pos[1]<20 )) break ; else if(pos[1]<280&&pos[1]>30) DrawRectFill(pos[0],pos[1],4,4,Red) ; } } return 0x00 ; }
char Proc_TP_Adj(char *NC) { unsigned int temp[8] ; Color = Green ; Color_BK = Black ; TP_Init() ; Clear_LCD(Color_BK) ; PutStringCN24(58,120,"触摸屏校正") ; Color = Cyan ; PutStringCN16(30,165,"请用触控笔点测试点中心") ; for(;;) { Draw_Test_Point(20,20,Yellow) ; for(;;) { if(Read_TP_Twice(&temp[0],&temp[1])) break ; if(ReadKey()==Cancel) return 0x00 ; } DrawRectFill(0,0,40,40,Color_BK) ; Wait_Pen_Up() ; Draw_Test_Point(220,20,Yellow) ; for(;;) { if(Read_TP_Twice(&temp[2],&temp[3])) break ; if(ReadKey()==Cancel) return 0x00 ; } DrawRectFill(200,0,40,40,Color_BK) ; Wait_Pen_Up() ; Draw_Test_Point(20,300,Yellow) ; for(;;) { if(Read_TP_Twice(&temp[4],&temp[5])) break ; if(ReadKey()==Cancel) return 0x00 ; } DrawRectFill(0,280,40,40,Color_BK) ; Wait_Pen_Up() ; Draw_Test_Point(220,300,Yellow) ; for(;;) { if(Read_TP_Twice(&temp[6],&temp[7])) break ; if(ReadKey()==Cancel) return 0x00 ; } DrawRectFill(200,280,40,40,Color_BK) ; Wait_Pen_Up() ; if(TP_Adjust(temp)) break ; } return 0x00 ; }
void RunMenu(unsigned char Menu_Index) { unsigned char key = 0xFF , menu_index , SubMenuIndex ; unsigned char First_Item , Active_Item , Active_Item_Index ; unsigned char CallBackIndex ; Clear_LCD(Color_BK) ; DrawRectFill(0,0,240,25,Blue) ; DrawRectFill(0,295,240,25,Blue) ; Color = 0xFFFF ; Color_BK = Blue ; PutStringCN16(4,4,Menus[Menu_Index].MenuTitle) ; Color = Black ; Color_BK = WINDOW_BK_COLOR ; Clear_LCD(STATUS_BK_COLOR) ; Color_BK = STATUS_BK_COLOR ; PutStringCN24(10,294,"确认") ; // 底栏 PutStringCN24(185,294,"取消") ; LoadMenu(MAIN_MENU,PERMISSION) ; Initial_Menu() ; for(;;) { key = GetKeyPress() ; switch(key) { case Up: case Down: case Left: case Right: MenuMessage(key) ; break ; case 8: MenuMessage(Up) ; break ; case 0: MenuMessage(Down) ; break ; case Esc: { // if(Current_Menu[0][6]!=EMPTY) // Item_OP[Current_Menu[0][6]](0,0) ; // 菜单执行函数 menu_index = GetMenuIndex() ; if(Menus[menu_index].MasterMenu!=EMPTY) // return Menus[menu_index].MasterMenu ; { LoadMenu(Menus[menu_index].MasterMenu,PERMISSION) ; Initial_Menu() ; } break ; } case OK: case Enter: { First_Item = GetFirstItem() ; Active_Item = GetActiveItem() ; Active_Item_Index = GetActiveItemIndex() ; if(MENU_ITEM[Active_Item_Index].CallBackFuncIndex!=EMPTY) // 有操作函数 { CallBackIndex= MENU_ITEM[Active_Item_Index].CallBackFuncIndex ; SubMenuIndex = MENU_ITEM[Active_Item_Index].SubMenuIndex ; if(SubMenuIndex!=EMPTY) // 有操作函数且有动态子菜单 { SubMenuIndex = MENU_ITEM[Active_Item_Index].SubMenuIndex ; if(Item_OP[CallBackIndex](0,Active_Item_Index )==0x00) // 生成子菜单成功 Initial_Menu() ; // 初始化动态子菜单 else Redraw_Menu(First_Item,Active_Item) ; // 未生成子菜单,重画原菜单 } else { Item_OP[CallBackIndex](0,Active_Item_Index ) ; // 无动态子菜单 Redraw_Menu(First_Item,Active_Item) ; // 重画菜单 } } /* if(MENU_ITEM[Item_Index].CallBackFuncIndex!=EMPTY) { Item_OP[MENU_ITEM[Item_Index].CallBackFuncIndex](0,Active_Index); if( (MENU_ITEM[Item_Index].SubMenuIndex!=EMPTY) &&(Master_Or_Sub==GOTO_SUB )) return MENU_ITEM[Item_Index].SubMenuIndex ; Redraw_Menu(First_Index,Active_Index,(UCHAR**)P_Current_Menu) ; } else */ else if(MENU_ITEM[Active_Item_Index].SubMenuIndex!=EMPTY) // return MENU_ITEM[Item_Index].SubMenuIndex ; { LoadMenu(MENU_ITEM[Active_Item_Index].SubMenuIndex,PERMISSION) ; Initial_Menu() ; } break ; } case Power: return ; default: break ; } } }
//---------------------------------------------------------------------------// // // //函数:void ShowMenu_Item(unsigned char ,unsigned char,unsigned char) // //描述:显示菜单项子函数 // //参数:index ——菜单项索引 // // no ——显示位置序号 // // mode ——显示模式 // // // //---------------------------------------------------------------------------// void RunMenu(unsigned char index) { char key,i,Active_Item = 0x00 ; OS_U8 Event ; union { unsigned int pos[2] ; char byte[4] ; }TPoint ; Ini_Background: Color = Black ; Color_BK = 0xEF9F ; Clear_LCD(Color_BK) ; DrawRectFill(0,0,240,25,Blue) ; DrawRectFill(0,295,240,25,Blue) ; Color = 0xFFFF ; Color_BK = Blue ; PutStringCN16(4,4,(unsigned char *)Menus[index].MenuTitle) ; Color = Black ; Color_BK = WINDOW_BK_COLOR ; for(i=0;i<Menus[index].MenuConfig[0];i++) { if(i==Active_Item) ShowMenu_Item(Menus[index].ItemIndex[i],i,1) ; else ShowMenu_Item(Menus[index].ItemIndex[i],i,0) ; } for(;;) { // Event = OS_WaitEvent(EVENT_KEY_PRESSED+EVENT_TP_PRESSED) ; OS_WaitMail(&MBKey) ; // if(Event&EVENT_KEY_PRESSED) { OS_GetMail1(&MBKey, &key) ; switch(key) { case Right: InactivateItem(Active_Item) ; if(++Active_Item>=Menus[index].MenuConfig[0]) Active_Item = 0x00 ; ActivateItem(Active_Item) ; break ; case Left: InactivateItem(Active_Item) ; if(Active_Item==0) Active_Item = 0x08 ; else Active_Item-- ; ActivateItem(Active_Item) ; break ; case 8: InactivateItem(Active_Item) ; if(Active_Item==0) Active_Item = 0x08 ; else if(Active_Item==1||Active_Item==2) Active_Item = Active_Item+5 ; else Active_Item = Active_Item-3 ; ActivateItem(Active_Item) ; break ; case 0: InactivateItem(Active_Item) ; if(Active_Item==8) Active_Item = 0x00 ; else if(Active_Item==6||Active_Item==7) Active_Item = Active_Item-5 ; else Active_Item = Active_Item+3 ; ActivateItem(Active_Item) ; break ; case Enter: OS_PutMail1(&MBFunc, &Active_Item) ; OS_SignalEvent(EVENT_OP_STARTED,&MENU_OP_TASK_TCB) ; OS_Suspend(&LCD_TASK_TCB) ; goto Ini_Background ; default: break ; } } /* else { OS_GetMail(&MBTouch, TPoint.byte) ; for(i=0;i<Menus[index].MenuConfig[0];i++) { if( (TPoint.pos[0]<(60+i%3*80)&&TPoint.pos[0]>(20+i%3*80)) &&(TPoint.pos[1]<(95+i/3*84)&&TPoint.pos[1]>(55+i/3*82))) { Active_Item = i ; OS_PutMail1(&MBFunc, &Active_Item) ; OS_SignalEvent(EVENT_OP_STARTED,&MENU_OP_TASK_TCB) ; OS_Suspend(&LCD_TASK_TCB) ; goto Ini_Background ; } } } */ } }
char Proc_Display(char *NC) { CHECK_BOX Disp_Check[3] ; char key,Event,temp[1],active_digit,rx_char ; char index,down_id=0xFF,i,flicker = 0 ; union { unsigned int pos[2] ; char byte[4] ; }TPoint ; Color = Black ; Color_BK = 0xEF9F ; Clear_LCD(Color_BK) ; DrawRectFill(0,0,240,25,Blue) ; DrawRectFill(0,295,240,25,Blue) ; ShowIcon24(217,0,24,23,ICON_CLOSE) ; Color = 0xFFFF ; Color_BK = Blue ; PutStringCN16(4,4,"数码管控制") ; PutStringCN16(200,300,"退出") ; Color = Black ; Color_BK = WINDOW_BK_COLOR ; DrawFrame(3,80,232,48) ; DrawRectFill(4,81,232,46,Black) ; DrawPanel(6,160,228,72,"") ; CreateButton(1,"<",15, 175,45,20) ; CreateButton(2,">",70, 175,45,20) ; CreateButton(3,"+",125,175,45,20) ; CreateButton(4,"-",180,175,45,20) ; for(active_digit=1;active_digit<9;active_digit++) { temp[0] = Find_Data(LED[active_digit-1].data) ; if(!(LED[active_digit-1].mode&DIGIT_OFF)) Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120, 3,3,Red) ; } for(active_digit=1;active_digit<9;active_digit++) { DrawFrame((active_digit-1)*29+14,139,11,11) ; DrawRectFill((active_digit-1)*29+15,140,10,10,Dark_Grey); } DrawRectFill(15,140,10,10,Green) ; active_digit = 1 ; CreateCheck(&Disp_Check[0],25 ,210,12,12,"闪烁") ; CreateCheck(&Disp_Check[1],90 ,210,12,12,"消隐") ; CreateCheck(&Disp_Check[2],150,210,12,12,"小数点") ; if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; temp[0] = 0x00 ; for(;;) { OS_WaitMail(&MBKeyTP) ; OS_GetMail1(&MBKeyTP, &Event) ; OS_GetMail1(&MBKeyTP, &key) ; OS_GetMail1(&MBKeyTP, &rx_char) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[0]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[1]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[2]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[3]) ; if(Event&EVENT_TP_TOUCHED) { index = InScopeButton(TPoint.pos[0], TPoint.pos[1] ) ; if(index==0xFF) { OS_Use(&SemaLCD) ; SetButtonUp(down_id) ; down_id = index ; OS_Unuse(&SemaLCD) ; } else if(index!=down_id) { OS_Use(&SemaLCD) ; SetButtonUp(down_id) ; down_id = index ; SetButtonDown(down_id) ; OS_Unuse(&SemaLCD) ; } } else if(Event&EVENT_TP_PRESSED) { index = InScopeButton(TPoint.pos[0], TPoint.pos[1] ) ; OS_Use(&SemaLCD) ; SetButtonUp(index) ; down_id = 0xFF ; OS_Unuse(&SemaLCD) ; switch(index) { case 1: if(active_digit>1) { active_digit-- ; DrawRectFill((active_digit)*29+15,140,10,10,Dark_Grey); DrawRectFill((active_digit-1)*29+15,140,10,10,Green); if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; else unCheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; else unCheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; else unCheckCheck(&Disp_Check[2]) ; } break ; case 2: if(active_digit<8) { active_digit++ ; DrawRectFill((active_digit-2)*29+15,140,10,10,Dark_Grey); DrawRectFill((active_digit-1)*29+15,140,10,10,Green); if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; else unCheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; else unCheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; else unCheckCheck(&Disp_Check[2]) ; } break ; case 3: temp[0] = Find_Data(LED[active_digit-1].data); if(++temp[0]>9) temp[0] = 0 ; LED[active_digit-1].data |= 0x7F ; LED[active_digit-1].data &= SMG[temp[0]] ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; break ; case 4: temp[0] = Find_Data(LED[active_digit-1].data); if(--temp[0]>250) temp[0] = 9 ; LED[active_digit-1].data |= 0x7F ; LED[active_digit-1].data &= SMG[temp[0]] ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; break ; } for(i=0;i<3;i++) { if(!InCheckScope(TPoint.pos[0], TPoint.pos[1], &Disp_Check[i])) { if(Disp_Check[i].status&CHECK_CHECKED) { unCheckCheck(&Disp_Check[i]) ; switch(i) { case 0: LED_Flicker_Digit(active_digit,0) ; temp[0] = Find_Data(LED[active_digit-1].data) ; if(!(LED[active_digit-1].mode&DIGIT_OFF)) { Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120,3,3,Red) ; } break ; case 1: temp[0] = Find_Data(LED[active_digit-1].data) ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120,3,3,Red) ; LED[active_digit-1].mode &=~DIGIT_OFF ; break ; case 2: LED[active_digit-1].data |= SEGDP ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Black) ; break ; } } else { CheckCheck(&Disp_Check[i]) ; switch(i) { case 0: LED_Flicker_Digit(active_digit,1) ; break ; case 1: temp[0] = Find_Data(LED[active_digit-1].data) ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Black,Black ) ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Black) ; LED[active_digit-1].mode |= DIGIT_OFF ; break ; case 2: LED[active_digit-1].data &=~SEGDP ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Red) ; break ; } } break ; } } if( (TPoint.pos[0]<230&&TPoint.pos[0]>200&&TPoint.pos[1]>295) ||(TPoint.pos[0]>220&&TPoint.pos[1]<20 )) break ; } else if(Event&EVENT_FLICKER) { if(flicker++>0) { for(i=1;i<9;i++) { temp[0] = Find_Data(LED[i-1].data) ; if( !(LED[i-1].mode&DIGIT_OFF) && (LED[i-1].mode&DIGIT_FLICKER)) { Draw7Seg2436(temp[0],(i-1)*29+5, 87,Red,Black ) ; if(!(LED[i-1].data&SEGDP)) DrawRectFill((i-1)*29+30,120,3,3,Red) ; } } flicker = 0x00 ; } else { for(i=1;i<9;i++) { temp[0] = Find_Data(LED[i-1].data) ; if( !(LED[i-1].mode&DIGIT_OFF) && (LED[i-1].mode&DIGIT_FLICKER)) { Draw7Seg2436(temp[0],(i-1)*29+5, 87,Black,Black ) ; if(!(LED[i-1].data&SEGDP)) DrawRectFill((i-1)*29+30,120,3,3,Black) ; } } } } } DeleteButton(1) ; DeleteButton(2) ; DeleteButton(3) ; DeleteButton(4) ; return 0x00 ; }