/** * @brief The main function of TMRB_PPG demo * @param None * @retval None */ void Example_TMRB_PPG(void) { uint32_t Duty[5] = { 0x1194U, 0xEA6U, 0x9C4U, 0x4E2U, 0x1F4U }; /* duty: 10%, 25%, 50%, 75%, 90% */ uint8_t keyvalue; TMRB_InitTypeDef m_tmrb; TMRB_FFOutputTypeDef PPGFFInital; /* LCD & switch initialization */ LCD_Configuration(); SW_Init(); /* Set PA5 as TB6OUT for PPG output */ GPIO_SetOutput(GPIO_PA, GPIO_BIT_5); GPIO_EnableFuncReg(GPIO_PA, GPIO_FUNC_REG_2, GPIO_BIT_5); m_tmrb.Mode = TMRB_INTERVAL_TIMER; m_tmrb.ClkDiv = TMRB_CLK_DIV_8; m_tmrb.UpCntCtrl = TMRB_AUTO_CLEAR; m_tmrb.Cycle = TMRB6TIME; /* T = 500us */ m_tmrb.Duty = Duty[Rate]; PPGFFInital.FlipflopCtrl = TMRB_FLIPFLOP_CLEAR; PPGFFInital.FlipflopReverseTrg = TMRB_FLIPFLOP_MATCH_CYCLE | TMRB_FLIPFLOP_MATCH_DUTY; TMRB_Enable(TSB_TB6); TMRB_Init(TSB_TB6, &m_tmrb); TMRB_SetFlipFlop(TSB_TB6, &PPGFFInital); TMRB_SetDoubleBuf(TSB_TB6, ENABLE, TMRB_WRITE_REG_SEPARATE); /* enable double buffer */ TMRB_SetRunState(TSB_TB6, TMRB_RUN); do { /* Handle the condition that start with the SW0 is high*/ keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0); duty_display(); } while (GPIO_BIT_VALUE_1 == keyvalue); delay(0xFFFFU); /* noise cancel */ while (1) { do { keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0); /* display when switch is low */ duty_display(); } while (GPIO_BIT_VALUE_0 == keyvalue); delay(0xFFFFU); /* noise cancel */ Rate++; if (Rate >= DUTYMAX) { /* change duty rate */ Rate = DUTYINIT; } else { /* Do nothing */ } TMRB_ChangeDuty(TSB_TB6, Duty[Rate]); do { keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0); /* display when switch is high */ duty_display(); } while (GPIO_BIT_VALUE_1 == keyvalue); delay(0xFFFFU); /* noise cancel */ } }
int main(int argc, char *argv[]) { //BOOTLOADER_reset(); int r; __enable_irq(); //NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000); // make sure that // interrupts work clock_init(); // hey, you can overclock later here. maybe. JSON_init(); USART_Config(); TIM_init(); LCD_Configuration(); LCD_Initialization(); LCD_Clear(LCD_Black); USART_PutString(HOST_USART,"***** INIT DONE *****\n"); while(1) { r = JSON_render(); // todo: better error reporting if(r == 3) { // no free bufs continue; } else if(r != 0) { JSON_init(); // reset buffers in case of errors char abuf[32]; itoa(abuf, r, 10); USART_PutString(HOST_USART, abuf); USART_PutChar(HOST_USART, 'N'); USART_PutChar(HOST_USART, '\n'); } //USART1_PutChar('A'); __asm__("WFI"); // sleep for a bit. } return 0; }
int main(void) { LED_Init(); SW_Init(); LCD_Configuration(); if (Mode_Judgement() == USER_BOOT_MODE) { /* if SW0 is turned on, enter user boot mode */ LED_On(LED3); /* enter user boot mode */ LCD_Display("User Boot Mode", ""); /* enter user boot mode */ LCD_Display("RAM transferring", "......"); Copy_Routine(FLASH_API_RAM, FLASH_API_ROM, SIZE_FLASH_API); /* copy flash API to RAM */ LCD_Display("Flash swapping", "......"); if (FC_SUCCESS == Flash_Swap()) { /* swap the flash content */ /* Do nothing */ } else { LED_On(LED1 | LED2 | LED3); /* if have any error, turn on all leds */ LCD_Display("Error", ""); /* if have any error, display error information */ } } else { /* if SW1 is turned off, enter normal mode */ #if defined ( __CC_ARM ) /* RealView Compiler */ ResetSP(); /* reset SP */ #elif defined ( __ICCARM__ ) /* IAR Compiler */ asm("MOV R0, #0"); /* reset SP */ asm("LDR SP, [r0]"); #endif SCB->VTOR = DEMO_START_ADDR; /* redirect vector table */ startup = CODE_START; startup(); /* jump to code start address to run */ } return 0; }
/***************************************************************************** ** �������: LCD_Init ** ��������: LCD��ʼ�� ** �� ����: Dream ** �ա� ��: 2010��12��06�� *****************************************************************************/ void LCD_Init(void) { static uint16_t DeviceCode; LCD_Configuration(); LCD_WriteReg(0x0000,0x0001); LCD_Delay(5); // LCD_Delay 50 ms DeviceCode = LCD_ReadReg(0x0000); printf(" ID=0x%x\n",DeviceCode); if(DeviceCode==0x9325||DeviceCode==0x9328)//ILI9325 { LCD_WriteReg(0x00e5,0x78F0); // LCD_WriteReg(0x0000,0x0001); LCD_WriteReg(0x0001,0x0100); LCD_WriteReg(0x0002,0x0700); LCD_WriteReg(0x0003,0x1030); LCD_WriteReg(0x0004,0x0000); LCD_WriteReg(0x0008,0x0202); LCD_WriteReg(0x0009,0x0000); LCD_WriteReg(0x000a,0x0000); LCD_WriteReg(0x000c,0x0001); LCD_WriteReg(0x000d,0x0000); LCD_WriteReg(0x000f,0x0000); //Power On sequence // LCD_WriteReg(0x0010,0x0000); LCD_WriteReg(0x0011,0x0007); LCD_WriteReg(0x0012,0x0000); LCD_WriteReg(0x0013,0x0000); LCD_WriteReg(0x0007,0x0001); LCD_Delay(5); LCD_WriteReg(0x0010,0x1690); LCD_WriteReg(0x0011,0x0227); LCD_Delay(5); LCD_WriteReg(0x0012,0x009d); LCD_Delay(5); LCD_WriteReg(0x0013,0x1900); LCD_WriteReg(0x0029,0x0025); LCD_WriteReg(0x002b,0x000d); LCD_Delay(5); LCD_WriteReg(0x0020,0x0000); LCD_WriteReg(0x0021,0x0000); LCD_Delay(5); //٤��У�� LCD_WriteReg(0x0030,0x0007); LCD_WriteReg(0x0031,0x0303); LCD_WriteReg(0x0032,0x0003); LCD_WriteReg(0x0035,0x0206); LCD_WriteReg(0x0036,0x0008); LCD_WriteReg(0x0037,0x0406); LCD_WriteReg(0x0038,0x0304); LCD_WriteReg(0x0039,0x0007); LCD_WriteReg(0x003c,0x0602); LCD_WriteReg(0x003d,0x0008); LCD_Delay(5); LCD_WriteReg(0x0050,0x0000); LCD_WriteReg(0x0051,0x00ef); LCD_WriteReg(0x0052,0x0000); LCD_WriteReg(0x0053,0x013f); LCD_WriteReg(0x0060,0xa700); LCD_WriteReg(0x0061,0x0001); LCD_WriteReg(0x006a,0x0000); LCD_WriteReg(0x0080,0x0000); LCD_WriteReg(0x0081,0x0000); LCD_WriteReg(0x0082,0x0000); LCD_WriteReg(0x0083,0x0000); LCD_WriteReg(0x0084,0x0000); LCD_WriteReg(0x0085,0x0000); LCD_WriteReg(0x0090,0x0010); LCD_WriteReg(0x0092,0x0600); LCD_WriteReg(0x0007,0x0133); } else if(DeviceCode==0x9320||DeviceCode==0x9300) { LCD_WriteReg(0x00,0x0000); LCD_WriteReg(0x01,0x0100); //Driver Output Contral. LCD_WriteReg(0x02,0x0700); //LCD Driver Waveform Contral. LCD_WriteReg(0x03,0x1030);//Entry Mode Set. //LCD_WriteReg(0x03,0x1018); //Entry Mode Set. LCD_WriteReg(0x04,0x0000); //Scalling Contral. LCD_WriteReg(0x08,0x0202); //Display Contral 2.(0x0207) LCD_WriteReg(0x09,0x0000); //Display Contral 3.(0x0000) LCD_WriteReg(0x0a,0x0000); //Frame Cycle Contal.(0x0000) LCD_WriteReg(0x0c,(1<<0)); //Extern Display Interface Contral 1.(0x0000) LCD_WriteReg(0x0d,0x0000); //Frame Maker Position. LCD_WriteReg(0x0f,0x0000); //Extern Display Interface Contral 2. LCD_Delay(10); LCD_WriteReg(0x07,0x0101); //Display Contral. LCD_Delay(10); LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); //Power Control 1.(0x16b0) LCD_WriteReg(0x11,0x0007); //Power Control 2.(0x0001) LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0)); //Power Control 3.(0x0138) LCD_WriteReg(0x13,0x0b00); //Power Control 4. LCD_WriteReg(0x29,0x0000); //Power Control 7. LCD_WriteReg(0x2b,(1<<14)|(1<<4)); LCD_WriteReg(0x50,0); //Set X Star //ˮƽGRAM��ֹλ��Set X End. LCD_WriteReg(0x51,239); //Set Y Star LCD_WriteReg(0x52,0); //Set Y End.t. LCD_WriteReg(0x53,319); // LCD_WriteReg(0x60,0x2700); //Driver Output Control. LCD_WriteReg(0x61,0x0001); //Driver Output Control. LCD_WriteReg(0x6a,0x0000); //Vertical Srcoll Control. LCD_WriteReg(0x80,0x0000); //Display Position? Partial Display 1. LCD_WriteReg(0x81,0x0000); //RAM Address Start? Partial Display 1. LCD_WriteReg(0x82,0x0000); //RAM Address End-Partial Display 1. LCD_WriteReg(0x83,0x0000); //Displsy Position? Partial Display 2. LCD_WriteReg(0x84,0x0000); //RAM Address Start? Partial Display 2. LCD_WriteReg(0x85,0x0000); //RAM Address End? Partial Display 2. LCD_WriteReg(0x90,(0<<7)|(16<<0)); //Frame Cycle Contral.(0x0013) LCD_WriteReg(0x92,0x0000); //Panel Interface Contral 2.(0x0000) LCD_WriteReg(0x93,0x0001); //Panel Interface Contral 3. LCD_WriteReg(0x95,0x0110); //Frame Cycle Contral.(0x0110) LCD_WriteReg(0x97,(0<<8)); // LCD_WriteReg(0x98,0x0000); //Frame Cycle Contral. LCD_WriteReg(0x07,0x0173); //(0x0173) LCD_Delay(10); } LCD_Clear(BACK_COLOR); }
/** ******************************************************************************* * @brief Initialization task * @param[in] pdata A pointer to parameter passed to task. * @param[out] None * @retval None * * @details This task is called to initial hardware and created tasks. ******************************************************************************* */ void task_init(void *pdata) { uart_printf (" [OK]. \n\r\n\r"); uart_printf ("\r \"task_init\" task enter. \n\r\n\r "); pdata = pdata; /* Initiate Time buffer for LCD display */ chart[0] = time[2]/10 + '0'; chart[1] = time[2]%10 + '0'; chart[3] = time[1]/10 + '0'; chart[4] = time[1]%10 + '0'; chart[6] = time[0]/10 + '0'; chart[7] = time[0]%10 + '0'; uart_printf ("\r Create the \"mut_uart\" mutex... "); mut_uart = CoCreateMutex(); if(mut_uart != E_CREATE_FAIL) uart_printf (" [OK]. \n"); else uart_printf (" [Fail]. \n"); uart_printf ("\r Create the \"mut_lcd\" mutex... "); mut_lcd = CoCreateMutex(); if(mut_lcd != E_CREATE_FAIL) uart_printf (" [OK]. \n"); else uart_printf (" [Fail]. \n"); uart_printf ("\r Create the \"button_sel_flg\" flag... "); /*!< Manual reset flag,initial state:0 */ button_sel_flg = CoCreateFlag(Co_FALSE,0); if(button_sel_flg != E_CREATE_FAIL) uart_printf (" [OK]. \n"); else uart_printf (" [Fail]. \n"); uart_printf ("\r Create the \"button_add_flag\" flag..."); /*!< Manual reset flag,initial state:0 */ button_add_flg = CoCreateFlag(Co_FALSE,0); if(button_add_flg != E_CREATE_FAIL) uart_printf (" [OK]. \n\n"); else uart_printf (" [Fail]. \n\n"); uart_printf ("\r Create the \"lcd_blink_flg\" flag... "); lcd_blink_flg = CoCreateFlag(Co_FALSE,0); /*!< Manual reset flag,initial state:0 */ if(lcd_blink_flg != E_CREATE_FAIL) uart_printf (" [OK]. \n"); else uart_printf (" [Fail]. \n"); uart_printf ("\r Create the \"time_display_flg\" flag..."); /*!< Manual reset flag,initial state:0 */ time_display_flg = CoCreateFlag(Co_FALSE,0); if(time_display_flg != E_CREATE_FAIL) uart_printf (" [OK]. \n"); else uart_printf (" [Fail]. \n"); /*!< Set flag to allow "time_display_flg" task run. */ CoSetFlag(time_display_flg); uart_printf ("\r Create the first mailbox... "); mbox0 = CoCreateMbox(EVENT_SORT_TYPE_FIFO); if(mbox0 == E_CREATE_FAIL) uart_printf (" [Fail]. \n\n"); else uart_printf (" [OK]. \n\n"); /* Configure Peripheral */ uart_printf ("\r Initial hardware in Board : \n\r"); uart_printf ("\r ADC initial... "); ADC_Configuration (); uart_printf (" [OK]. \n"); uart_printf ("\r RTC initial... "); RTC_Configuration (); uart_printf (" [OK]. \n"); uart_printf ("\r GPIO initial... "); GPIO_Configuration (); uart_printf (" [OK]. \n"); uart_printf ("\r External interrupt initial... "); EXIT_Configuration (); uart_printf (" [OK]. \n"); uart_printf ("\r LCD initial... "); LCD_Configuration (); uart_printf (" [OK]. \n\n"); /* Create Tasks */ CoCreateTask( lcd_display_adc, (void *)0 , LCD_DISPLAY_PRI , &lcd_display_adc_Stk[TASK_STK_SIZE-1] , TASK_STK_SIZE ); CoCreateTask( uart_print , (void *)0 , UART_PRINT_PRI , &uart_print_Stk[TASK_STK_SIZE-1], TASK_STK_SIZE ); CoCreateTask( led_blink , (void *)0 , LCD_BLINK_PRI , &led_display_Stk[TASK_STK_SIZE-1], TASK_STK_SIZE ); time_display_id = CoCreateTask( time_display, (void *)0, TIME_DISRPLAY_PRI, &time_display_Stk[TASK_STK_SIZE - 1], TASK_STK_SIZE ); CoCreateTask( time_set , (void *)0 , TIME_SET_PRI , &time_set_Stk[TASK_STK_SIZE-1], TASK_STK_SIZE ); CoExitTask(); /*!< Delete 'task_init' task. */ }