/******************************************************************************* * Function Name : TaskStart * Description : UCOS-II. * Input : *pdata. * Output : None * Return : None *******************************************************************************/ void TaskStart(void *pdata) { //u16 tp_xvalue = 0, tp_yvalue = 0; //INT8U err = 0; pdata = pdata; // 防止编译器告警 SysTick_Configuration(); // 初始化系统节拍(1ms) OSStatInit(); // 初始化统计任务 TaskStartCreateTasks(); // 建立其他任务 /* 初始化TFT, 设置TFT背光 */ TFT_Init(); TFT_SetBlackLight(TFT_BL_PERCENT_90); TFT_Clear(Blue); TFT_DisplayD36x48(10, 150, '2', White, Blue); TFT_DisplayD36x48(46, 150, '1', White, Blue); TFT_DisplayD36x48(82, 150, ':', White, Blue); TFT_DisplayD36x48(118, 150, '5', White, Blue); TFT_DisplayD36x48(154, 150, '8', White, Blue); TFT_DisplayString(200, 182, "2011", White, Blue); TFT_DisplayString(30, 218, "Wendnesday, Septermber 23", White, Blue); TFT_DrawHLine(30, 236, 230, Blue); while(1) { //printf("Start task is running!\r\n"); /* 任务延时500ms */ OSTimeDlyHMSM(0, 0, 20, 0); } }
void DrawScreen(TScreen *aScreen) { int order; char save_bled, save_bled_direction; object_pressed = 0; order = 0; CurrentScreen = aScreen; if ((display_width != CurrentScreen->Width) || (display_height != CurrentScreen->Height)) { save_bled = TFT_BLED; save_bled_direction = TFT_BLED_Direction; TFT_BLED_Direction = 0; TFT_BLED = 0; TFT_Set_Active(Set_Index, Write_Command, Write_Data); TFT_Init(CurrentScreen->Width, CurrentScreen->Height); TFT_Set_Ext_Buffer(TFT_Get_Data); TP_TFT_Init(CurrentScreen->Width, CurrentScreen->Height, 13, 12); // Initialize touch panel TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold TFT_Fill_Screen(CurrentScreen->Color); display_width = CurrentScreen->Width; display_height = CurrentScreen->Height; TFT_BLED = save_bled; TFT_BLED_Direction = save_bled_direction; } else TFT_Fill_Screen(CurrentScreen->Color); while (order < CurrentScreen->ObjectsCount) { } }
void Initialize() { short int i = 0; // variable initialization LQI = 0; RSSI2 = 0; SEQ_NUMBER = 0x23; lost_data = 0; address_RX_FIFO = 0x300; address_TX_normal_FIFO = 0; for (i = 0; i < 2; i++) { ADDRESS_short_1[i] = 1; ADDRESS_short_2[i] = 2; PAN_ID_1[i] = 3; PAN_ID_2[i] = 3; } for (i = 0; i < 8; i++) { ADDRESS_long_1[i] = 1; ADDRESS_long_2[i] = 2; } // Set Chip Select pin as Output GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_13); GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_10); GPIO_Digital_Output(&GPIOC_BASE, _GPIO_PINMASK_2); // Set PD0 and PD1 as digital input GPIO_Digital_Input(&GPIOD_BASE, _GPIO_PINMASK_0); Delay_ms(5); // SPI config SPI3_Init_Advanced(_SPI_FPCLK_DIV4, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI3_PC10_11_12); TFT_BLED = 1; // Turn on TFT Backlight TFT_Init(320, 240); // Initialize TFT display TFT_Fill_Screen(CL_WHITE); // Clear Screen pin_reset(); // Activate reset from pin software_reset(); // Activate software reset RF_reset(); // RF reset set_WAKE_from_pin(); // Set wake from pin set_long_address(ADDRESS_long_2); // Set long address set_short_address(ADDRESS_short_2); // Set short address set_PAN_ID(PAN_ID_2); // Set PAN_ID init_ZIGBEE_nonbeacon(); // Initialize ZigBee module nonbeacon_PAN_coordinator_device(); set_TX_power(31); // Set max TX power set_frame_format_filter(1); // 1 all frames, 3 data frame only set_reception_mode(1); // 1 normal mode pin_wake(); // Wake from pin }
/* 显示菜单 */ void show_menu() { TFT_Init(); ClearScreen(Black); TFT_Show_Bmp_8b(50,80,80,80,gImage_tmp); TFT_Show_Bmp_8b(190,80,80,80,gImage_net); }
static void InitializeTouchPanel() { Init_ADC(); TFT_Set_Active(Set_Index, Write_Command, Write_Data); TFT_Init(320, 240); TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold }
static void InitializeTouchPanel() { Init_ADC(); TFT_Set_Active(Set_Index, Write_Command, Write_Data); TFT_Init(320, 240); TFT_Set_Ext_Buffer(TFT_Get_Data); TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold PenDown = 0; PressedObject = 0; PressedObjectType = -1; }
void Camera_Test(void) { int i; SetSysFclk(FCLK_220M); //设置系统时钟 220M ChangeClockDivider(1, 1); //设置分频 1:2:4 CalcBusClk(); //计算总线频 Uart_Select(0); Uart_Init(0, 115200); Uart_Printf("\nCamera Preview Test\n"); CamReset(); // Initializing camif rCLKCON |= (1<<19); // enable camclk CamPortSet(); ChangeUPllValue(56, 2, 1); // UPLL clock = 96MHz, PLL input 12MHz rCLKDIVN|=(1<<3); // UCLK 48MHz setting for UPLL 96MHz // 0:48MHz, 1:24MHz, 2:16MHz, 3:12MHz... // Camera clock = UPLL/[(CAMCLK_DIV+1)X2] SetCAMClockDivider(CAMCLK24000000); //Set Camera Clock 24MHz s5x532, OV9650 i = Test_OV9650(); if( i ) { Uart_Printf("\nTest is failed!!!\n"); return ; } Uart_Printf("Initializing end...\n"); Test_CamPreview() ; Uart_Printf("\nCamera Preview Test End\n"); rCLKCON &= ~(1<<19); // disable camclk TFT_Init(); SetSysFclk(FCLK_400M); //设置系统时钟 400M ChangeClockDivider(2, 1); //设置分频 1:4:8 CalcBusClk(); //计算总线频 Uart_Select(0); Uart_Init(0, 115200); }
void UI_Setup() { GPIO_Config(&GPIO_PORTA, 0b00001000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE | _GPIO_CFG_DRIVE_8mA, 0); // Init back light GPIO TFT_BACKLIGHT = 0; // We need to Unlock PR7 before we can use it as GPIO (MCU specific) GPIO_Unlock(_GPIO_COMMIT_PIN_B7); GPIO_Digital_Input(&GPIO_PORTB, _GPIO_PINMASK_0 | _GPIO_PINMASK_7); // Set Up and Left as digital input GPIO_Digital_Input(&GPIO_PORTE, _GPIO_PINMASK_4 | _GPIO_PINMASK_5); // Set Right and Down as digital input GPIO_Digital_Input(&GPIO_PORTH, _GPIO_PINMASK_2); // Set Center as digital input Delay_100ms(); TFT_Init(320, 240); TFT_Fill_Screen(0); InitializeObjects(); display_width = LoadingScreen.Width; display_height = LoadingScreen.Height; UI_LoadingScreen("Fetching IP address"); TFT_BACKLIGHT = 1; }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { Init_Debug_Signals(); Init_RGB_LEDs(); Sound_Init(); // Sound_Disable_Amp(); Play_Tone(); TFT_Init(); TFT_Text_Init(1); TFT_Erase(); TFT_Text_PrintStr_RC(0,0, "Test Code"); /* Graphics_Test(); while (1) ; */ // TFT_TS_Calibrate(); // TFT_TS_Test(); TFT_Text_PrintStr_RC(1,0, "Accel..."); i2c_init(); // init I2C peripheral if (!init_mma()) { // init accelerometer Control_RGB_LEDs(1,0,0); // accel initialization failed, so turn on red error light while (1) ; } TFT_Text_PrintStr_RC(1,9, "Done"); Play_Waveform_with_DMA(); Delay(70); os_sys_init(&Task_Init); while (1) ; }
/** * @brief Displays a keypad on touchscreen * @param none * @retval none */ void Make_Touch_Pad(void) { int t_y = 7; int t_y1; int ft = 2; int t_x = 4; int lines = 7; int column = 20; int pitch; int ys; //terminal is organised in lines 1..30/15, depending on //selcted font -> to calculate pixelpostion, decrement line and multiplay with font height int yh; int xw; int xs; int x; int y; TFT_Init(); TFT_cursor_off(); TFT_graphic_cls(); TFT_touch_area_clear(); //_------------------------------------------------- //---- 2. Define the small blue terminal window ---- //-------------------------------------------------- TFT_set_font_color(YELLOW); // define terminal colors t_y = 3; ft = 2; t_x = 4; lines = 7; column = 20; TFT_set_window(ft, t_x, t_y, column, lines); // define the font (8x16), origin //(5x8=40,7x16=112), width (20 character) and height (7 lines) // note: origin is defined as column no.7 and line no.10 (not dots) TFT_terminal_on(); // Terminal on // ---------------------------------------------- //---- 3. Define a keypad with numbers 0..9 ---- //--------------------------------------------- TFT_touch_area_font_color(YELLOW, BLACK); // define color for touch font TFT_touch_area_font(SWISS30B); // set font for touch area TFT_touch_area_frame(20, 0); //set border no. 20 TFT_touch_area_color(WHITE, BLACK, BLUE, WHITE, BLACK, YELLOW); //set border colors normal and for selection // using a constant for (touch)size and (touch)pitch makes it //more easy to move the whole key group later // XPIXEL=320 and YPIXEL=240 pitch = 2; t_y1 = 5; // startline for button ys = (t_y1 - 1) * ft * 8; //terminal is organised in lines 1..30/15, depending on //selcted font -> to calculate pixelpostion, decrement line and multiplay with font height yh = (YPIXEL - ys - 3 * pitch) / NUMBER_BUTTON_VERTICAL; // 4 button vertical xw = yh; // width same as hight xs = XPIXEL - (NUMBER_BUTTON_HORIZONTAL * xw + 2 * pitch); // 7 button in line x = xs; // xs is left start of button y = ys; TFT_touch_area(x, y, x + xw, y + yh, '1', 0, "1"); // define a touchkey with number "1". x += pitch + xw; //while release, touchmacro no. 20 will be executed TFT_touch_area(x, y, x + xw, y + yh, '2', 0, "2"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '3', 0, "3"); x += pitch + xw; // empty place x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, 'r', 0, "r"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, 'd', 0, "d"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, 's', 0, "st"); // -- start 2nd row of buttons x = xs; y += pitch + yh; TFT_touch_area(x, y, x + xw, y + yh, '4', 0, "4"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '5', 0, "5"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '6', 0, "6"); x += pitch + xw; // empty place x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '+', 0, "+"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '-', 0, "-"); // -- start 3rd row of buttons x = xs; y += pitch + yh; TFT_touch_area(x, y, x + xw, y + yh, '7', 0, "7"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '8', 0, "8"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '9', 0, "9"); x += pitch + xw; // empty place x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '*', 0, "*"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '/', 0, "/"); // -- start 4th row of button x = xs; y += pitch + yh; //TFT_touch_area( x,y,x+xw,y+yh, 0,0, "=" ); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, '0', 0, "0"); x += pitch + xw; //TFT_touch_area( x, y, x+xw, y+yh, 0, 0, "" ); x += pitch + xw; // empty place //x+=pitch+xw; //TFT_touch_area( x, y, x+xw, y+yh, '=', 0, "=" ); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, 'e', 0, "e"); x += pitch + xw; TFT_touch_area(x, y, x + xw, y + yh, 'c', 0, "c"); return; }
void DrawScreen(TScreen *aScreen) { int order; unsigned short button_idx; TButton *local_button; unsigned short image_idx; TImage *local_image; unsigned short radio_button_idx; TRadioButton *local_radio_button; char save_bled, save_bled_direction; object_pressed = 0; order = 0; button_idx = 0; image_idx = 0; radio_button_idx = 0; CurrentScreen = aScreen; if ((display_width != CurrentScreen->Width) || (display_height != CurrentScreen->Height)) { save_bled = TFT_BLED; save_bled_direction = TFT_BLED_Direction; TFT_BLED_Direction = 0; TFT_BLED = 0; TFT_Set_Active(Set_Index, Write_Command, Write_Data); TFT_Init(CurrentScreen->Width, CurrentScreen->Height); TFT_Set_Ext_Buffer(TFT_Get_Data); TP_TFT_Init(CurrentScreen->Width, CurrentScreen->Height, 13, 12); // Initialize touch panel TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold TFT_Fill_Screen(CurrentScreen->Color); display_width = CurrentScreen->Width; display_height = CurrentScreen->Height; TFT_BLED = save_bled; TFT_BLED_Direction = save_bled_direction; } else TFT_Fill_Screen(CurrentScreen->Color); while (order < CurrentScreen->ObjectsCount) { if (button_idx < CurrentScreen->ButtonsCount) { local_button = GetButton(button_idx); if (order == local_button->Order) { button_idx++; order++; DrawButton(local_button); } } if (image_idx < CurrentScreen->ImagesCount) { local_image = GetImage(image_idx); if (order == local_image->Order) { image_idx++; order++; DrawImage(local_image); } } if (radio_button_idx < CurrentScreen->RadioButtonsCount) { local_radio_button = GetRadioButton(radio_button_idx); if (order == local_radio_button->Order) { radio_button_idx++; order++; DrawRadioButton(local_radio_button); } } } }
void DrawScreen(TScreen *aScreen) { unsigned int order; unsigned short round_button_idx; TButton_Round *local_round_button; unsigned short label_idx; TLabel *local_label; unsigned short image_idx; TImage *local_image; char save_bled, save_bled_direction; object_pressed = 0; order = 0; round_button_idx = 0; label_idx = 0; image_idx = 0; CurrentScreen = aScreen; if ((display_width != CurrentScreen->Width) || (display_height != CurrentScreen->Height)) { save_bled = TFT_BLED; save_bled_direction = TFT_BLED_Direction; TFT_BLED_Direction = 0; TFT_BLED = 0; TFT_Set_Active(Set_Index, Write_Command, Write_Data); TFT_Init(CurrentScreen->Width, CurrentScreen->Height); TP_TFT_Init(CurrentScreen->Width, CurrentScreen->Height, 13, 12); // Initialize touch panel TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold TFT_Fill_Screen(CurrentScreen->Color); display_width = CurrentScreen->Width; display_height = CurrentScreen->Height; TFT_BLED = save_bled; TFT_BLED_Direction = save_bled_direction; } else TFT_Fill_Screen(CurrentScreen->Color); while (order < CurrentScreen->ObjectsCount) { if (round_button_idx < CurrentScreen->Buttons_RoundCount) { local_round_button = GetRoundButton(round_button_idx); if (order == local_round_button->Order) { round_button_idx++; order++; DrawRoundButton(local_round_button); } } if (label_idx < CurrentScreen->LabelsCount) { local_label = GetLabel(label_idx); if (order == local_label->Order) { label_idx++; order++; DrawLabel(local_label); } } if (image_idx < CurrentScreen->ImagesCount) { local_image = GetImage(image_idx); if (order == local_image->Order) { image_idx++; order++; DrawImage(local_image); } } } }
int main(void) { uint8_t ledState = 0; uint8_t num = 5; uint32_t i; /* ³õʼ»¯ */ SYSTEM_SetClock(72); TFT_Init(); LED_Config(); while(1) { i++; if(i > 0xFFFFF) { i = 0; if(ledState == 0xFE) { ledState = 0xFF; } else { ledState = 0xFE; } LED_SetState(ledState); num++; if(num == 21) { num = 0; } /* ÆÁÏÔʾ */ switch(num) { case(0): GUI_Box(0, 0, TFT_XMAX, 49, WHITE); GUI_Box(0, 50, TFT_XMAX, 99, BLACK); GUI_Box(0, 100, TFT_XMAX, 149, BLUE); GUI_Box(0, 150, TFT_XMAX, 199, RED); GUI_Box(0, 200, TFT_XMAX, 249, MAGENTA); GUI_Box(0, 250, TFT_XMAX, 299, GREEN); GUI_Box(0, 300, TFT_XMAX, 349, CYAN); GUI_Box(0, 350, TFT_XMAX, 399, YELLOW); break; case(6): TFT_ClearScreen(BLACK); GUI_Show12ASCII(90, 0, "PERCHIN", RED, BLACK); GUI_Show12ASCII(0, 16, "welcome to the world of STM32!", RED, BLACK); break; case(13): GUI_Box(0, 0, 29, TFT_YMAX, WHITE); GUI_Box(30, 0, 59, TFT_YMAX, BLACK); GUI_Box(60, 0, 89, TFT_YMAX, BLUE); GUI_Box(90, 0, 119, TFT_YMAX, RED); GUI_Box(120, 0, 149, TFT_YMAX, MAGENTA); GUI_Box(150, 0, 179, TFT_YMAX, GREEN); GUI_Box(180, 0, 209, TFT_YMAX, CYAN); GUI_Box(210, 0, 239, TFT_YMAX, YELLOW); break; default: break; } } } }