// -------------------------------------------------- // Initialization of the backlight LCD. Using PWM. void Init_LCD_BackLight(void) { uint32_t pclk; PWM_TIMERCFG_Type PWMCfgDat; PWM_MATCHCFG_Type PWMMatchCfgDat; pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL; PWMCfgDat.PrescaleValue = 1; PWM_Init(LCD_BL_PWM_PERI_ID, PWM_MODE_TIMER, (void *) &PWMCfgDat); PINSEL_ConfigPin(LCD_BL_PWM_PORT, LCD_BL_PWM_PIN, 1); // funct.no.1 - PWM1[2] — Pulse Width Modulator 1, channel 2 output. PWM_MatchUpdate(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHA, pclk / LCD_BL_PWM_BASE, PWM_MATCH_UPDATE_NOW); // UPDATE VALUE OF THE PWM DUTY CYCLE PWM_MatchUpdate(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHB , 0 *(( pclk / LCD_BL_PWM_BASE) / 100), PWM_MATCH_UPDATE_NOW); // switch off backlight PWMMatchCfgDat.IntOnMatch = DISABLE; // without interrupt PWMMatchCfgDat.MatchChannel = LCD_BL_PWM_PERI_CHB; // Match channel register - duty cycle - xx % PWMMatchCfgDat.ResetOnMatch = DISABLE; // PWMMatchCfgDat.StopOnMatch = DISABLE; PWM_ConfigMatch(LCD_BL_PWM_PERI_ID, &PWMMatchCfgDat); // store it PWM_ChannelCmd(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHB, ENABLE); // Enable PWM Channel Output PWM_ResetCounter(LCD_BL_PWM_PERI_ID); // reset and start counter PWM_CounterCmd(LCD_BL_PWM_PERI_ID, ENABLE); // start PWM Counter PWM_Cmd(LCD_BL_PWM_PERI_ID, ENABLE); // start PWM }
// -------------------------------------------------- // Set nev intensity [%] of backlight. void Set_LCD_BackLight(uint16_t level) // Level: 0-100% { uint32_t pclk; pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); if (level > 100) level = 100; PWM_MatchUpdate(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHB,level * ((pclk / LCD_BL_PWM_BASE) / 100), PWM_MATCH_UPDATE_NOW); }
static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg) { LPC_TIM_TypeDef *tim; rt_err_t err = RT_EOK; tim = (LPC_TIM_TypeDef *)timer->parent.user_data; switch (cmd) { case HWTIMER_CTRL_FREQ_SET: { uint32_t clk; uint32_t pre; clk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); pre = clk / *((uint32_t*)arg) - 1; tim->PR = pre; } break; default: { err = -RT_ENOSYS; } break; } return err; }
/*********************************************************************//** * @brief Initial for ADC * + Set bit PCADC * + Set clock for ADC * + Set Clock Frequency * @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC * @param[in] rate ADC conversion rate, should be <=200KHz * @return None **********************************************************************/ void ADC_Init(LPC_ADC_TypeDef *ADCx, uint32_t rate) { uint32_t temp, tmp; // Turn on power and clock CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCADC, ENABLE); ADCx->CR = 0; //Enable PDN bit tmp = ADC_CR_PDN; // Set clock frequency temp = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); /* The APB clock (PCLK_ADC0) is divided by (CLKDIV+1) to produce the clock for * A/D converter, which should be less than or equal to 12.4MHz. * A fully conversion requires 31 of these clocks. * ADC clock = PCLK_ADC0 / (CLKDIV + 1); * ADC rate = ADC clock / 31; */ temp = (temp /(rate * 31)) - 1; tmp |= ADC_CR_CLKDIV(temp); ADCx->CR = tmp; }
/*********************************************************************//** * @brief Setup clock rate for SSP device * @param[in] SSPx SSP peripheral definition, should be: * - LPC_SSP0: SSP0 peripheral * - LPC_SSP1: SSP1 peripheral * @param[in] target_clock : clock of SSP (Hz) * @return None ***********************************************************************/ static void setSSPclock (LPC_SSP_TypeDef *SSPx, uint32_t target_clock) { uint32_t prescale, cr0_div, cmp_clk, ssp_clk; ssp_clk = CLKPWR_GetCLK (CLKPWR_CLKTYPE_PER); /* Find closest divider to get at or under the target frequency. Use smallest prescale possible and rely on the divider to get the closest target frequency */ cr0_div = 0; cmp_clk = 0xFFFFFFFF; prescale = 2; while (cmp_clk > target_clock) { cmp_clk = ssp_clk / ((cr0_div + 1) * prescale); if (cmp_clk > target_clock) { cr0_div++; if (cr0_div > 0xFF) { cr0_div = 0; prescale += 2; } } } /* Write computed prescaler and divider back to register */ SSPx->CR0 &= (~SSP_CR0_SCR(0xFF)) & SSP_CR0_BITMASK; SSPx->CR0 |= (SSP_CR0_SCR(cr0_div)) & SSP_CR0_BITMASK; SSPx->CPSR = prescale & SSP_CPSR_BITMASK; }
/*********************************************************************//** * @brief Initial System Tick with using internal CPU clock source * @param[in] time time interval(ms) * @return None * Note: time interval parameter should be less than: * 1/cclk * (2^24) * 1000 (ms) * In this case, with cclk = 96Mhz, time interval value < 174ms **********************************************************************/ void SYSTICK_InternalInit(uint32_t time) { uint32_t cclk; float maxtime; cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU); /* With internal CPU clock frequency for LPC178X is 'SystemCoreClock' * And limit 24 bit for RELOAD value * So the maximum time can be set: * 1/SystemCoreClock * (2^24) * 1000 (ms) */ //check time value is available or not maxtime = (1<<24)/(cclk / 1000) ; if(time > maxtime) { //Error loop while(1); } else { //Select CPU clock is System Tick clock source SysTick->CTRL |= ST_CTRL_CLKSOURCE; /* Set RELOAD value * RELOAD = (SystemCoreClock/1000) * time - 1 * with time base is millisecond */ SysTick->LOAD = (cclk/1000)*time - 1; } }
/*********************************************************************//** * @brief Initializes the pPwm peripheral corresponding to the specified * parameters in the PWM_ConfigStruct. * @param[in] pwmId The Id of the expected PWM component * * * @param[in] PWMTimerCounterMode Timer or Counter mode, should be: * - PWM_MODE_TIMER: Counter of PWM peripheral is in Timer mode * - PWM_MODE_COUNTER: Counter of PWM peripheral is in Counter mode * @param[in] PWM_ConfigStruct Pointer to structure (PWM_TIMERCFG_Type or * PWM_COUNTERCFG_Type) which will be initialized. * @return None * Note: PWM_ConfigStruct pointer will be assigned to corresponding structure * (PWM_TIMERCFG_Type or PWM_COUNTERCFG_Type) due to PWMTimerCounterMode. **********************************************************************/ void PWM_Init(uint8_t pwmId, uint32_t PWMTimerCounterMode, void *PWM_ConfigStruct) { LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId); PWM_TIMERCFG_Type *pTimeCfg; PWM_COUNTERCFG_Type *pCounterCfg; uint64_t clkdlycnt; pTimeCfg = (PWM_TIMERCFG_Type *)PWM_ConfigStruct; pCounterCfg = (PWM_COUNTERCFG_Type *)PWM_ConfigStruct; if(pwmId == PWM_0) { CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM0, ENABLE); } else if(pwmId == PWM_1) { CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM1, ENABLE); } else { //Trap the error while(1); } // Get peripheral clock of PWM1 clkdlycnt = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); // Clear all interrupts pending pPwm->IR = 0xFF & PWM_IR_BITMASK; pPwm->TCR = 0x00; pPwm->CTCR = 0x00; pPwm->MCR = 0x00; pPwm->CCR = 0x00; pPwm->PCR = 0x00; pPwm->LER = 0x00; if (PWMTimerCounterMode == PWM_MODE_TIMER) { /* Absolute prescale value */ if (pTimeCfg->PrescaleOption == PWM_TIMER_PRESCALE_TICKVAL) { pPwm->PR = pTimeCfg->PrescaleValue - 1; } /* uSecond prescale value */ else { clkdlycnt = (clkdlycnt * pTimeCfg->PrescaleValue) / 1000000; pPwm->PR = ((uint32_t) clkdlycnt) - 1; } } else if (PWMTimerCounterMode == PWM_MODE_COUNTER) { pPwm->CTCR |= (PWM_CTCR_MODE((uint32_t)pCounterCfg->CounterOption)) \ | (PWM_CTCR_SELECT_INPUT((uint32_t)pCounterCfg->CountInputSelect)); } }
/*********************************************************************//** * @brief Get peripheral clock of each timer controller * @param[in] timernum Timer number * @return Peripheral clock of timer **********************************************************************/ static uint32_t getPClock (uint32_t timernum) { (void)timernum; uint32_t clkdlycnt; clkdlycnt = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); return clkdlycnt; }
/*********************************************************************//** * @brief Setup clock rate for I2C peripheral * @param[in] I2Cx I2C peripheral selected, should be: * - LPC_I2C0 * - LPC_I2C1 * - LPC_I2C2 * @param[in] target_clock : clock of SSP (Hz) * @return None ***********************************************************************/ static void I2C_SetClock (LPC_I2C_TypeDef *I2Cx, uint32_t target_clock) { uint32_t temp; temp = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / target_clock; /* Set the I2C clock value to register */ I2Cx->SCLH = (uint32_t)(temp / 2); I2Cx->SCLL = (uint32_t)(temp - I2Cx->SCLH); }
/*********************************************************************//** * @brief Set timer reload value for QEI peripheral. When the velocity timer is * over-flow, the value that set for Timer Reload register will be loaded * into the velocity timer for next period. The calculated velocity in RPM * therefore will be affect by this value. * @param[in] qeiId The Id of the expected QEI component * It should be 0 (zero) always with LPC177x_8x * * @param[in] QEIReloadStruct QEI reload structure * @return None **********************************************************************/ void QEI_SetTimerReload(uint8_t qeiId, QEI_RELOADCFG_Type *QEIReloadStruct) { LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId); uint64_t pclk; uint32_t ld = 0; if (QEIReloadStruct->ReloadOption == QEI_TIMERRELOAD_TICKVAL) { pQei->LOAD = QEIReloadStruct->ReloadValue - 1; } else { #if 1 pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); pclk = (pclk /(1000000/QEIReloadStruct->ReloadValue)) - 1; pQei->LOAD = (uint32_t)pclk; #else ld = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); if (ld/1000000 > 0) { ld /= 1000000; ld *= QEIReloadStruct->ReloadValue; ld -= 1; } else { ld *= QEIReloadStruct->ReloadValue; ld /= 1000000; ld -= 1; } pQei->LOAD = ld; #endif } }
/********************************************************************* * @brief Power on EMC Block * @param[in] None * @return None **********************************************************************/ EMC_FUNC_CODE EMC_PwrOn(void) { // If CPU clock is > 80 MHz, then divide it by two to create the EMC clock if(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) > 80000000) { CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 1); // CPU clock / 2 } else { CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 0); // Same clock as CPU } // Power on CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE); // Enable LPC_EMC->Control = EMC_Control_E; return EMC_FUNC_OK; }
/*********************************************************************//** * @brief Initial EEPROM * @param[in] None * @return None **********************************************************************/ void EEPROM_Init(void) { uint32_t val, cclk; LPC_EEPROM->PWRDWN = 0x0; /* EEPROM is automate turn on after reset */ /* Setting clock: * EEPROM required a 375kHz. This clock is generated by dividing the * system bus clock. */ cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU); val = (cclk/375000)-1; LPC_EEPROM->CLKDIV = val; /* Setting wait state */ val = ((((cclk / 1000000) * 15) / 1000) + 1); val |= (((((cclk / 1000000) * 55) / 1000) + 1) << 8); val |= (((((cclk / 1000000) * 35) / 1000) + 1) << 16); LPC_EEPROM->WSTATE = val; }
/*********************************************************************//** * @brief Calculates the actual velocity in RPM passed via velocity * capture value and Pulse Per Round (of the encoder) value * parameter input. * @param[in] qeiId The Id of the expected QEI component * It should be 0 (zero) always with LPC177x_8x * * @param[in] ulVelCapValue Velocity capture input value that can * be got from QEI_GetVelocityCap() function * @param[in] ulPPR Pulse per round of encoder * @return The actual value of velocity in RPM (Round per minute) **********************************************************************/ uint32_t QEI_CalculateRPM(uint8_t qeiId, uint32_t ulVelCapValue, uint32_t ulPPR) { LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId); uint64_t rpm, clock, Load, edges; // Get current Clock rate for timer input clock = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); // Get Timer load value (velocity capture period) Load = (uint64_t)(pQei->LOAD + 1); // Get Edge edges = (uint64_t)((pQei->CONF & QEI_CONF_CAPMODE) ? 4 : 2); // Calculate RPM rpm = ((clock * ulVelCapValue * 60) / (Load * ulPPR * edges)); return (uint32_t)(rpm); }
int main(void) { OS_CPU_SysTickInit(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / 1000 - 1); Board_Init(); //KeyInit(); GUI_Init(); Display_Logo(); /* init phy */ PHY_Init(optionSaveStruct.ipConfig.mac); M25P128_SSP_Init(); GT21L16S2W_SSP_Init(); #if FRMB_DEBUG LPC_Uart_Init(1200*(0x01<<optionSaveStruct.uartConfig[2]),1200*(0x01<<optionSaveStruct.uartConfig[3]),1200*(0x01<<optionSaveStruct.uartConfig[4]),1200*(0x01<<optionSaveStruct.uartConfig[5])); #endif System_Time_Init(); /* Init RTC */ OSInit(); OSTaskCreate ( TaskStart,(void *)0,&GstkStart[TASK_START_STK_SIZE-1],TASK_START_PRIO ); /* Initialize the start task */ /* Start OS Schedule */ OSStart(); /* Start uC/OS-II ??uC/OS-II */ return(0); }
static void lpccan_baud_set(rt_uint32_t id, rt_uint32_t baud) { uint32_t result = 0; uint8_t NT, TSEG1, TSEG2; uint32_t CANPclk = 0; uint32_t BRP; LPC_CAN_TypeDef* pCan = lcpcan_get_reg_base(id); CANPclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER); result = CANPclk / LPCBAUDTAB[baud]; /* Calculate suitable nominal time value * NT (nominal time) = (TSEG1 + TSEG2 + 3) * NT <= 24 * TSEG1 >= 2*TSEG2 */ for(NT = 24; NT > 0; NT = NT-2) { if ((result%NT) == 0) { BRP = result / NT - 1; NT--; TSEG2 = (NT/3) - 1; TSEG1 = NT -(NT/3) - 1; break; } } /* Enter reset mode */ pCan->MOD = 0x01; /* Set bit timing * Default: SAM = 0x00; * SJW = 0x03; */ pCan->BTR = (TSEG2 << 20) | (TSEG1 << 16) | (3 << 14) | BRP; /* Return to normal operating */ pCan->MOD = 0; }
int main() { int8_t res; uint32_t n, m, p, cnt; uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU); uint32_t filesize = 0; uint32_t time_end; // SystemInit(); SysTick_Config(cclk/1000 - 1); /* Generate interrupt each 1 ms */ debug_frmwrk_init(); // UART0 xfunc_out = put_char; xfunc_in = get_char; xprintf("%s",mciFsMenu); xprintf("\nMMC/SD Card Filesystem Test (P:LPC1788 L:EFSL)\n"); xprintf("\nCARD init..."); // init file system if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { xprintf("failed with %d\n",res); } else { xprintf("ok\n"); xprintf("Card type: "); switch (CardConfig.CardType) { case MCI_MMC_CARD: xprintf("MMC\n"); break; case MCI_SDSC_V1_CARD: xprintf("Version 1.x Standard Capacity SD card.\n"); break; case MCI_SDSC_V2_CARD: xprintf("Version 2.0 or later Standard Capacity SD card.\n"); break; case MCI_SDHC_SDXC_CARD: xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n"); break; default: break; } xprintf("Sector size: %d bytes\n", CardConfig.SectorSize); xprintf("Sector count: %d\n", CardConfig.SectorCount); xprintf("Block size: %d sectors\n", CardConfig.BlockSize); xprintf("Card capacity: %d MByte\n\n", (((CardConfig.SectorCount >> 10) * CardConfig.SectorSize)) >> 10); xprintf("\nDirectory of 'root':\n"); /* list files in root directory */ ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { // list.currentEntry is the current file list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ; } #if READ_TEST_ENABLED!=0 /* Read test */ xprintf("\nFile read test:\n"); xprintf("Open file %s ...", FILE_NAME_R); xmemset(Buff,0,sizeof(Buff)); if (file_fopen( &filer, &efs.myFs , FILE_NAME_R , 'r' ) == 0 ) { xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE); n=FILE_RW_SIZE; m = 0; Timer = 0; xprintf("File's content:\n"); while (n) { if (n>=blen) {cnt = blen; n -= blen;} else {cnt = n; n = 0;} p = file_read( &filer, cnt, &Buff[m] ); xprintf("%s",&Buff[m]); m += p; if (p != cnt) break; } filesize = m; time_end = Timer; xprintf("\n%lu bytes read in %lu milisec.\n", m, time_end); file_fclose( &filer ); } else { xprintf (" Failed.\n"); } #endif #if WRITE_TEST_ENABLED!=0 /* Write test*/ xprintf("\nFile write test:\n"); xprintf("Open file %s ...", FILE_NAME_W); if (file_fopen( &filew, &efs.myFs , FILE_NAME_W , 'a' ) == 0 ) { xprintf(" OK. \nWriting %lu bytes ...\n", filesize); n=filesize; m = 0; Timer = 0; while (n) { if (n>=blen) { cnt = blen; n -= blen; } else { cnt = n; n = 0; } p = file_write( &filew, cnt, &Buff[m] ); m += p; if (p != cnt) break; } time_end = Timer; xprintf("%lu bytes written in %lu milisec.\n", m, time_end); file_fclose( &filew ); } else { xprintf (" Failed.\n"); } #endif #if READ_TEST_ENABLED!=0 /* Read test */ xprintf("\nFile read test:\n"); xprintf("Open file %s ...", FILE_NAME_W); xmemset(Buff,0,sizeof(Buff)); if (file_fopen( &filer, &efs.myFs , FILE_NAME_W , 'r' ) == 0 ) { xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE); n=FILE_RW_SIZE; m = 0; Timer = 0; xprintf("File's content:\n"); while (n) { if (n>=blen) {cnt = blen; n -= blen;} else {cnt = n; n = 0;} p = file_read( &filer, cnt, &Buff[m] ); xprintf("%s",&Buff[m]); m += p; if (p != cnt) break; } filesize = m; time_end = Timer; xprintf("\n%lu bytes read in %lumiliseconds.\n", m, time_end); file_fclose( &filer ); } else { xprintf (" Failed.\n"); } #endif /* close file system */ fs_umount( &efs.myFs ) ; } xprintf("\nEFSL test complete.\n"); while (1); }
/********************************************************************* * @brief Calculate EMC Clock from nano second * @param[in] time - nano second * @return None **********************************************************************/ uint32_t EMC_NS2CLK(uint32_t time){ uint32_t emc_freq = CLKPWR_GetCLK(CLKPWR_CLKTYPE_EMC); return (((uint64_t)time*emc_freq/1000000000ull)); }
/********************************************************************* * @brief Calculate refresh timer (the multiple of 16 CCLKs) * @param[in] freq - frequency of EMC Clk * @param[in] time - micro second * @return None **********************************************************************/ uint32_t EMC_SDRAM_REFRESH(uint32_t time) { uint32_t emc_freq = CLKPWR_GetCLK(CLKPWR_CLKTYPE_EMC); return (((uint64_t)((uint64_t)time * emc_freq)/16000000ull)+1); }
/*********************************************************************//** * @brief EMC initialize (power on block, config EMC pins). * @param[in] None * @return None **********************************************************************/ EMC_FUNC_CODE EMC_Init(void) { uint8_t i; // If CPU clock is > 80 MHz, then divide it by two to create the EMC clock if(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) > 80000000) { CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 1); // CPU clock / 2 } else { CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 0); // Same clock as CPU } LPC_SC->PCONP |= 0x00000800; LPC_SC->EMCDLYCTL = 0x00001010; LPC_EMC->Control = 0x00000001; LPC_EMC->Config = 0x00000000; /* Pin configuration: * P2.14 - /EMC_CS2 * P2.15 - /EMC_CS3 * * P2.16 - /EMC_CAS * P2.17 - /EMC_RAS * P2.18 - EMC_CLK[0] * P2.19 - EMC_CLK[1] * * P2.20 - EMC_DYCS0 * P2.21 - EMC_DYCS1 * P2.22 - EMC_DYCS2 * P2.23 - EMC_DYCS3 * * P2.24 - EMC_CKE0 * P2.25 - EMC_CKE1 * P2.26 - EMC_CKE2 * P2.27 - EMC_CKE3 * * P2.28 - EMC_DQM0 * P2.29 - EMC_DQM1 * P2.30 - EMC_DQM2 * P2.31 - EMC_DQM3 * * P3.0-P3.31 - EMC_D[0-31] * P4.0-P4.23 - EMC_A[0-23] * P5.0-P5.1 - EMC_A[24-25] * * P4.24 - /EMC_OE * P4.25 - /EMC_WE * * P4.30 - /EMC_CS0 * P4.31 - /EMC_CS1 */ PINSEL_ConfigPin(2,14,1); PINSEL_ConfigPin(2,15,1); PINSEL_ConfigPin(2,16,1); PINSEL_ConfigPin(2,17,1); PINSEL_ConfigPin(2,18,1); PINSEL_ConfigPin(2,19,1); PINSEL_ConfigPin(2,20,1); PINSEL_ConfigPin(2,21,1); PINSEL_ConfigPin(2,22,1); PINSEL_ConfigPin(2,23,1); PINSEL_ConfigPin(2,24,1); PINSEL_ConfigPin(2,25,1); PINSEL_ConfigPin(2,26,1); PINSEL_ConfigPin(2,27,1); PINSEL_ConfigPin(2,28,1); PINSEL_ConfigPin(2,29,1); PINSEL_ConfigPin(2,30,1); PINSEL_ConfigPin(2,31,1); for(i = 0; i < 32; i++) { PINSEL_ConfigPin(3,i,1); PINSEL_ConfigPin(4,i,1); } PINSEL_ConfigPin(5,0,1); PINSEL_ConfigPin(5,1,1); return EMC_FUNC_OK; }
/*********************************************************************//** * @brief Init LCD. The input clock is CClk * * @param[in] pConfig Configuration Information * * @return LCD_FUNC_OK Execute successfully * LCD_FUNC_ERR Error occurred. * **********************************************************************/ LCD_RET_CODE LCD_Init (LCD_Config_Type* pConfig) { uint8_t clkdiv; if(pConfig == NULL) return LCD_FUNC_ERR; lcd_config = *pConfig; // Assign pins PINSEL_ConfigPin(0,4,7); PINSEL_ConfigPin(0,5,7); PINSEL_ConfigPin(0,6,7); PINSEL_ConfigPin(0,7,7); PINSEL_ConfigPin(0,8,7); PINSEL_ConfigPin(0,9,7); PINSEL_ConfigPin(1,20,7); PINSEL_ConfigPin(1,21,7); PINSEL_ConfigPin(1,22,7); PINSEL_ConfigPin(1,23,7); PINSEL_ConfigPin(1,24,7); PINSEL_ConfigPin(1,25,7); PINSEL_ConfigPin(1,26,7); PINSEL_ConfigPin(1,27,7); PINSEL_ConfigPin(1,28,7); PINSEL_ConfigPin(1,29,7); PINSEL_ConfigPin(2,2,7); PINSEL_ConfigPin(2,3,7); PINSEL_ConfigPin(2,4,7); PINSEL_ConfigPin(2,5,7); PINSEL_ConfigPin(2,6,7); PINSEL_ConfigPin(2,7,7); PINSEL_ConfigPin(2,8,7); PINSEL_ConfigPin(2,9,7); PINSEL_ConfigPin(2,12,7); PINSEL_ConfigPin(2,13,7); PINSEL_ConfigPin(4,28,7); PINSEL_ConfigPin(4,29,7); //Turn on LCD clock CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE); // Set clock LPC_LCD->POL &= ~(0x01 << 5); if( pConfig->panel_clk > 0) { clkdiv = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / pConfig->panel_clk - 1; LPC_SC->LCD_CFG = clkdiv & 0x1F; } // init Horizontal Timing LCD_SetHorizontalTiming(&pConfig->hConfig); // Init Vertical Timing LCD_SetVertialTiming(&pConfig->vConfig); // Set Polarity LCD_SetPolarity(pConfig->lcd_type, &pConfig->polarity); if(NULL != pConfig->lcd_palette) { LCD_SetPalette(pConfig->lcd_palette); } // Set Base address LCD_SetBaseAddress(LCD_PANEL_UPPER, pConfig->lcd_panel_upper); LCD_SetBaseAddress(LCD_PANEL_LOWER, pConfig->lcd_panel_lower); // Setup LCD_CtrlSetup(pConfig); return LCD_FUNC_OK; }