/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { EXTI_InitTypeDef EXTICfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize EXT pin and registers * P2.10 as /EINT0 */ PINSEL_ConfigPin(2,10,1); EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT0; /* edge sensitive */ EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_ClearEXTIFlag(EXTI_EINT0); EXTI_Config(&EXTICfg); NVIC_SetPriorityGrouping(4); NVIC_SetPriority(EINT0_IRQn, 0); NVIC_EnableIRQ(EINT0_IRQn); _DBG_("Press '1' to enter system in deep sleep mode.\n\r"\ "If you want to wake-up the system, press INT/WAKE-UP button."); while(_DG !='1') { _DBG_("I'm waiting...\n\r"); } _DBG_("I'm sleeping..."); // Enter target deep sleep mode CLKPWR_DeepSleep(); SystemInit(); debug_frmwrk_init(); // MCU will be here after waking up _DBG_("\n\r-------- I'm wake up! -------- "); while (1); }
/*********************************************************************//** * @brief c_entry: Main RIT program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); _DBG(menu); RIT_Init(LPC_RIT); /* Configure time_interval for RIT * In this case: time_interval = 1000 ms = 1s * So, RIT will generate interrupt each 1s */ RIT_TimerConfig(LPC_RIT,TIME_INTERVAL); _DBG("The time interval is: "); _DBD32(TIME_INTERVAL); _DBG_(" millisecond.."); #ifdef MCB_LPC_1768 /* Using LED2.2 for testing */ //turn on LED2.2 FIO_SetDir(2,(1<<2),1); FIO_SetValue(2,(1<<2)); #elif defined(IAR_LPC_1768) /* Using LED1 (P1.25 for testing */ FIO_SetDir(1,(1<<25),1); FIO_ClearValue(1,(1<<25)); #endif NVIC_EnableIRQ(RIT_IRQn); while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main CAN program body * @param[in] none * @return int **********************************************************************/ int c_entry(void) { /* Main Program */ PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* Pin configuration * CAN1: select P0.0 as RD1. P0.1 as TD1 * CAN2: select P2.7 as RD2, P2.8 as RD2 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 0; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 1; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PinCfg.Portnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); //Initialize CAN1 & CAN2 CAN_Init(LPC_CAN1, 125000); CAN_Init(LPC_CAN2, 125000); //Enable Interrupt CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE); //Enable CAN Interrupt NVIC_EnableIRQ(CAN_IRQn); _DBG_("CAN test Bypass Mode function..."); _DBG_("Press '1' to initialize CAN message...");_DBG_(""); while(_DG !='1'); CAN_SetAFMode(LPC_CANAF,CAN_AccBP); CAN_InitMessage(); PrintMessage(&TXMsg); _DBG_("Message ID and data will be increased continuously..."); _DBG_("Press '2' to start CAN operation..."); while(_DG !='2'); /** To test Bypass Mode: we send infinite messages to CAN2 and check * receive process via COM1 */ CAN_SendMsg(LPC_CAN1, &TXMsg); while (1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); // Init WDT, IRC OSC, interrupt mode, timeout = 2000000 us = 2s WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_INT_ONLY); _DBG_("Press '1' to enter system in Deep Sleep mode"); while(_DG !='1'); NVIC_EnableIRQ(WDT_IRQn); WDT_Start(WDT_TIMEOUT); _DBG_("Enter Deep Sleep mode!"); _DBG_("Wait 2s for WDT wake-up system..."); /*---------- Disable and disconnect the main PLL0 before enter into Deep-Sleep * or Power-Down mode <according to errata.lpc1768-16.March.2010> ------------ */ LPC_SC->PLL0CON &= ~(1<<1); /* Disconnect the main PLL (PLL0) */ LPC_SC->PLL0FEED = 0xAA; /* Feed */ LPC_SC->PLL0FEED = 0x55; /* Feed */ while ((LPC_SC->PLL0STAT & (1<<25)) != 0x00); /* Wait for main PLL (PLL0) to disconnect */ LPC_SC->PLL0CON &= ~(1<<0); /* Turn off the main PLL (PLL0) */ LPC_SC->PLL0FEED = 0xAA; /* Feed */ LPC_SC->PLL0FEED = 0x55; /* Feed */ while ((LPC_SC->PLL0STAT & (1<<24)) != 0x00); /* Wait for main PLL (PLL0) to shut down */ /*------------Then enter into PowerDown mode ----------------------------------*/ // Enter target power down mode CLKPWR_DeepSleep(); SystemInit(); debug_frmwrk_init(); _DBG_("\n\rSystem wake-up!\n\r"); while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { volatile uint32_t adc_value, tmp; uint8_t quit; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize ADC ----------------------------------------------------*/ /* * Init ADC pin that currently is being used on the board */ PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); /* Configuration for ADC : * ADC conversion rate = 400Khz */ ADC_Init(LPC_ADC, 400000); ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, DISABLE); ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE); while(1) { // Start conversion ADC_StartCmd(LPC_ADC, ADC_START_NOW); //Wait conversion complete while (!(ADC_ChannelGetStatus(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ADC_DATA_DONE))); adc_value = ADC_ChannelGetData(LPC_ADC, BRD_ADC_PREPARED_CHANNEL); //Display the result of conversion on the UART _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(" is: "); _DBD32(adc_value); _DBG_(""); //delay for(tmp = 0; tmp < 1000000; tmp++); if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ int main(void) { debug_frmwrk_init(); EMC_NAND_Test(); /* Infinite loop */ while( 1 ) { } }
/** \brief Sets up system hardware */ static void prvSetupHardware(void) { /* Setup board including GPIOs and pin muxing */ board_setup(); led_set(0); /* Initialize debug output via serial port */ debug_frmwrk_init(); }
int main (void) { debug_frmwrk_init(); _printf("Up and running!"); while(true) { _printf("Still running..."); } return 0; }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ int main (void) { uint32_t n; uint32_t ret; SysTick_Config(SystemCoreClock / 1000); #ifdef CFG_SDCARD /* Setup SD Card/FATFS */ SDInit(); #endif debug_frmwrk_init(); printf("\r\n hello"); //for (n = 0; n < MSC_ImageSize; n++) { /* Copy Initial Disk Image */ // Memory[n] = DiskImage[n]; /* from Flash to RAM */ //} if(!KEY1_PIN) { UsbMode = 0; while(!KEY1_PIN); delay(100000); while(!KEY1_PIN); } if(UsbMode == 0){ USB_Init(); /* USB Initialization */ USB_Connect(TRUE); /* USB Connect */ } else{ Host_Init(); // Initialize the lpc17xx host controller if( Host_EnumDev() == 0 ) /* Enumerate the device connected */ { printf("-- USB device detected OK \r\n"); } else { printf("-- Please connect a USB device \r\n"); while( Host_EnumDev() == 0 ); printf("-- USB device connection detected \r\n"); Delay(0x00ffff); } } while (1){ if(!KEY1_PIN) { ret = Host_CtrlSend(0x40, 0x50, 0, 0, 0, NULL); printf("\r\n sent switch cmd,ret= %x ",ret); delay(100); NVIC_SystemReset(); } } }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { uint8_t* pDest = (uint8_t*)VTOR_OFFSET; uint8_t* pSource = NULL; GPIO_Init(); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, 1); _DBG(" Remapping Vector Table at address: "); _DBH32(VTOR_OFFSET); _DBG_(""); NVIC_SetVTOR(VTOR_OFFSET); /* Copy Vector Table from 0x00000000 to new address * In ROM mode: Vector Interrupt Table is initialized at 0x00000000 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000 * Aligned: 256 words */ #ifdef __RAM_MODE__ //Run in RAM mode pSource = (void*)0x10000000; memcpy(pDest,pSource , 256*4); #else pSource = (void*)0x00000000; memcpy(pDest,pSource , 256*4); #endif _DBG_(" If Vector Table remapping is successful, LED P2.10 will blink by using\n\r SysTick interrupt"); //Initialize System Tick with 100ms time interval /* Input parameter for SysTick in range 0..174 ms */ SYSTICK_InternalInit(100); //Enable System Tick interrupt SYSTICK_IntCmd(ENABLE); //Enable System Tick Counter SYSTICK_Cmd(ENABLE); while(1); }
/*********************************************************************//** * @brief c_entry: Main TIMER program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); //Config P1.26 as CAP0.0 PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 1; PinCfg.Pinnum = 26; PINSEL_ConfigPin(&PinCfg); // Initialize timer 0, prescale count time of 1000000uS = 1S TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1000000; // use channel 0, CAPn.0 TIM_CaptureConfigStruct.CaptureChannel = 0; // Enable capture on CAPn.0 rising edge TIM_CaptureConfigStruct.RisingEdge = ENABLE; // Enable capture on CAPn.0 falling edge TIM_CaptureConfigStruct.FallingEdge = ENABLE; // Generate capture interrupt TIM_CaptureConfigStruct.IntOnCaption = ENABLE; // Set configuration for Tim_config and Tim_MatchConfig TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct); TIM_ResetCounter(LPC_TIM0); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01)); /* Enable interrupt for timer 0 */ NVIC_EnableIRQ(TIMER0_IRQn); // To start timer 0 TIM_Cmd(LPC_TIM0,ENABLE); while (1); return 1; }
/*********************************************************************//** * @brief Main I2S program body **********************************************************************/ int c_entry (void) { /* Main Program */ RIT_CMP_VAL value; PINSEL_CFG_Type PinCfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif debug_frmwrk_init(); _DBG(menu); value.CMPVAL = 10000000; value.COUNTVAL = 0x00000000; value.MASKVAL = 0x00000000; RIT_Init(LPC_RIT); RIT_TimerConfig(LPC_RIT,&value); RIT_TimerClearCmd(LPC_RIT,ENABLE); _DBG("The value compare is: "); _DBD32(value.CMPVAL); _DBG_(" system tick"); //Config P2.2 as GPO2.2 PinCfg.Funcnum = 0; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 2; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); //turn on LED2.2 GPIO_SetDir(2,(1<<2),1); GPIO_SetValue(2,(1<<2)); NVIC_EnableIRQ(RIT_IRQn); while(1); return 1; }
/** * @brief Main Program body */ int c_entry(void) { PINSEL_CFG_Type PinCfg; uint32_t adc_value; /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Init ADC pin connect * AD0.2 on P0.25 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 25; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); /* Configuration for ADC : * Frequency at 1Mhz * ADC channel 2, no Interrupt */ ADC_Init(LPC_ADC, 1000000); ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,DISABLE); ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE); while(1) { // Start conversion ADC_StartCmd(LPC_ADC,ADC_START_NOW); //Wait conversion complete while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE))); adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2); //Display the result of conversion on the UART0 _DBG("ADC value on channel 2: "); _DBD32(adc_value); _DBG_(""); //delay 1s Timer_Wait(1000); } ADC_DeInit(LPC_ADC); return 1; }
/*********************************************************************//** * @brief This function is the main function where the execution begins * @param[in] None * @return None **********************************************************************/ int main() { int32_t rc; uint32_t numBlks, blkSize; uint8_t buffer[30]; UINT nun; uint8_t inquiryResult[INQUIRY_LENGTH]; FATFS fs; FIL fsrc, fdst; const TCHAR a=1; SystemInit(); debug_frmwrk_init(); print_menu(); Host_Init(); /* Initialize the lpc17xx host controller */ PRINT_Log("Host Initialized\r\n"); PRINT_Log("Connect a Mass Storage device\r\n"); rc = Host_EnumDev(); /* Enumerate the device connected */ PRINT_Log("Á¬½ÓÉ豸\r\n"); if ((rc == USB_HOST_FUNC_OK) && (Host_GetDeviceType() == MASS_STORAGE_DEVICE)) { PRINT_Log("Mass Storage device connected\r\n"); rc = f_mount(&fs,"0:",1); if(rc==0) { rc = f_open(&fdst, "0:read.txt", FA_READ); if(rc==0) { PRINT_Log("open ok\r\n"); f_read (&fdst, buffer, 30, &nun ); PRINT_Log(buffer); f_close(&fdst); } } } else { PRINT_Log("Not a Mass Storage device\n"); return (0); } return 0; }
int main (void) { SystemInit(); /* initialize clocks */ debug_frmwrk_init(); do{ user_switch_init(); }while(int_flag != 1); print_menu(); i2c_lpc_init(I2C_SPEED_100); test_i2c_at24c256_flash(); while(1); }
/*********************************************************************//** * @brief c_entry: Main CAN program body * @param[in] none * @return none **********************************************************************/ void c_entry(void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* Initialize CAN1 peripheral * Note: Self-test mode doesn't require pin selection */ CAN_Init(_USING_CAN_NO, 125000); //Enable self-test mode CAN_ModeConfig(_USING_CAN_NO, CAN_SELFTEST_MODE, ENABLE); //Enable Interrupt CAN_IRQCmd(_USING_CAN_NO, CANINT_RIE, ENABLE); CAN_IRQCmd(_USING_CAN_NO, CANINT_TIE1, ENABLE); //Enable CAN Interrupt NVIC_EnableIRQ(CAN_IRQn); CAN_SetAFMode(CAN_ACC_BP); CAN_InitMessage(); _DBG_("Transmitted buffer:"); PrintMessage(&TXMsg); /** To test Bypass Mode: we send infinite messages to CAN2 and check * receive process via COM1 */ CAN_SendMsg(_USING_CAN_NO, &TXMsg); #if (_USING_CAN_NO == CAN_1) LPC_CAN1->CMR |=(1<<4); //Self Reception Request #else LPC_CAN2->CMR |=(1<<4); #endif while (1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* In this example: * Suppose that the RTC need periodically adjust after each 5 second. * And the time counter need by incrementing the counter by 2 instead of 1 * We will observe timer counter after calibration via serial display */ // Init RTC module RTC_Init(LPC_RTC); /* Enable rtc (starts increase the tick counter and second counter register) */ RTC_ResetClockTickCounter(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); //Set current time = 0 RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); /* Setting Timer calibration * Calibration value = 5s; * Direction = Forward calibration * So after each 5s, calibration logic can periodically adjust the time counter by * incrementing the counter by 2 instead of 1 */ RTC_CalibConfig(LPC_RTC, 5, RTC_CALIB_DIR_FORWARD); RTC_CalibCounterCmd(LPC_RTC, ENABLE); /* Set the CIIR for second counter interrupt*/ RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initialize and configure RTC */ RTC_Init(LPC_RTC); RTC_ResetClockTickCounter(LPC_RTC); RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); /* Set alarm time = 5s. * So, after each 5s, RTC will generate and wake-up system * out of Deep PowerDown mode. */ RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 5); RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE); /* Set the AMR for 5s match alarm interrupt */ RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM); _DBG_("Press '1' to enter system in Deep PowerDown mode"); while(_DG !='1'); RTC_Cmd(LPC_RTC, ENABLE); NVIC_EnableIRQ(RTC_IRQn); _DBG_("Enter Deep PowerDown mode..."); _DBG_("Wait 5s, RTC will wake-up system...\n\r"); // Enter target power down mode CLKPWR_DeepPowerDown(); while(1); return 1; }
int c_entry(void) { // Init LED port LED_Init(); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); // Read back TimeOut flag to determine previous timeout reset if (WDT_ReadTimeOutFlag()){ _DBG_(info1); // Clear WDT TimeOut WDT_ClrTimeOutFlag(); } else{ _DBG_(info2); } // Initialize WDT, IRC OSC, interrupt mode, timeout = 2000000 microsecond WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET); // Start watchdog with timeout given WDT_Start(WDT_TIMEOUT); // set timer 100 ms Timer_Wait(100); while (1){ // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn on led FIO_ByteSetValue(2, 0, LED_PIN); // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn off led FIO_ByteClearValue(2, 0, LED_PIN); } return 0; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); //Use P0.0 to test System Tick interrupt GPIO_SetDir(1, (1<<28), 1); //Set P0.0 as output _DBG("Remapping Vector Table at address: "); _DBH32(VTOR_OFFSET); _DBG_(""); NVIC_SetVTOR(VTOR_OFFSET); /* Copy Vector Table from 0x00000000 to new address * In ROM mode: Vector Interrupt Table is initialized at 0x00000000 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000 * Aligned: 256 words */ #if(__RAM_MODE__==0)//Run in ROM mode memcpy(VTOR_OFFSET, 0x00000000, 256*4); #else memcpy(VTOR_OFFSET, 0x10000000, 256*4); #endif _DBG_("If Vector Table remapping is successful, LED P1.28 will blink by using SysTick interrupt"); //Initialize System Tick with 100ms time interval SYSTICK_InternalInit(100); //Enable System Tick interrupt SYSTICK_IntCmd(ENABLE); //Enable System Tick Counter SYSTICK_Cmd(ENABLE); while(1); return 1; }
/** * Runs all the initialisations that are needed * Please put them in here. */ void initialise() { debug_frmwrk_init(); setSensorSide(-1); trackingState = 0; timerCounter = 0; courseType = 0; initSerial(); serialTest(); initSensors(); // Even tho this is a test it needs to run so that the serial is set up properly initTimers(); //__enable_irq(); if (DBG_LEVEL >= 1) { _DBG_("MOUSE"); } mouseinitial(); if (DBG_LEVEL >= 1) { _DBG_("I've completed"); } }
/*********************************************************************//** * @brief Main 4-bit LCD porting with GPIO program body **********************************************************************/ int c_entry(void) { // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* Initialize debug */ debug_frmwrk_init(); // print welcome screen print_menu(); /* LCD block section -------------------------------------------- */ GLCD_Init(); // LCD_cur_off(); GLCD_Clear(White); /* Update LCD Module display text. */ GLCD_DisplayString(0,0, lcd_text[0] ); GLCD_DisplayString(1,2, lcd_text[1] ); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main SPI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; SPI_DATA_SETUP_Type xferConfig; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND; SPI_ConfigStruct.CPOL = SPI_CPOL_LO; SPI_ConfigStruct.ClockRate = 2000000; SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct.Databit = SPI_DATABIT_SIZE; SPI_ConfigStruct.Mode = SPI_MASTER_MODE; // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); /* Initialize Buffer */ Buffer_Init(); xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete"); SPI_DeInit(LPC_SPI); /* Loop forever */ while(1); return 1; }
/*-------------------------MAIN FUNCTION------------------------------ **********************************************************************/ int c_entry(void) { InitIR2110(); // Use for Driver PWM IC IR2110 // EnableIR2110(); DisableIR2110(); flag_soft_start = 1; #ifdef RUN_OK Delayms(3000); #endif // InitDAC(); // Initialize debug via UART0 // – 9600bps // – 8 data bit // – No parity // – 1 stop bit // – No flow control debug_frmwrk_init(); SetOutputDTR(); ClearDTR(); //data receive InitLedAlarmBattery(); InitLedAlarmOverload(); InitPWM(PWM_FREQUENCY,DEADTIME); SetDutyPWM(0,0); InitADC(ADC_FREQUENCY); InitTimerADCRead(); InitTimerProcessSinwave(); InitTimerProcessSensorRMSValue(); InitTimerMainProcess(); InitBuzzer(10000); #ifdef RUN_OK while(fist_startup) { if(f_Vin_RMS > VOLTAGE_MIN/*Vol*/) { flag_voltage_low = 0; flag_current_high = 0; fist_startup = 0; } } #endif while (1) { if ((LPC_UART1->LSR & UART_LSR_RDR)) { buff[0] = UART_ReceiveByte((LPC_UART_TypeDef *)LPC_UART1); if(buff[0] == 'I') { Delayms(100); SetDTR(); //data transmission printf_dbg("I,%d,\r",(uint32_t)(f_Vin_RMS*f_Iin_RMS)); Delayms(10); ClearDTR(); //data receive buff[0] = 0; } } } return 1; }
/*********************************************************************//** * @brief c_entry: Main MCPWM program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { // MCPWM Channel configuration data MCPWM_CHANNEL_CFG_Type channelsetup[3]; uint32_t i; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); _DBG_("Hello MCPWM ..."); /* Pin configuration for MCPWM function: * Assign: - P1.19 as MCOA0 - Motor Control Channel 0 Output A * - P1.22 as MCOB0 - Motor Control Channel 0 Output B * - P1.25 as MCOA1 - Motor Control Channel 1 Output A * - P1.26 as MCOB1 - Motor Control Channel 1 Output B * - P1.28 as MCOA2 - Motor Control Channel 2 Output A * - P1.29 as MCOB2 - Motor Control Channel 2 Output B * - P1.20 as MCI0 - Motor Control Feed Back Channel 0 * Warning: According to Errata.lpc1768-18.March.2010: Input pin (MIC0-2) * on the Motor Control PWM peripheral are not functional */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 1; PinCfg.Pinnum = 19; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 22; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 25; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 26; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 29; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 20; PINSEL_ConfigPin(&PinCfg); /* Disable interrupt for MCPWM */ NVIC_DisableIRQ(MCPWM_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(MCPWM_IRQn, ((0x01<<3)|0x01)); /* Init MCPWM peripheral */ MCPWM_Init(LPC_MCPWM); channelsetup[0].channelType = MCPWM_CHANNEL_EDGE_MODE; channelsetup[0].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO; channelsetup[0].channelDeadtimeEnable = DISABLE; channelsetup[0].channelDeadtimeValue = 0; channelsetup[0].channelUpdateEnable = ENABLE; channelsetup[0].channelTimercounterValue = 0; channelsetup[0].channelPeriodValue = 300; channelsetup[0].channelPulsewidthValue = 0; channelsetup[1].channelType = MCPWM_CHANNEL_EDGE_MODE; channelsetup[1].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO; channelsetup[1].channelDeadtimeEnable = DISABLE; channelsetup[1].channelDeadtimeValue = 0; channelsetup[1].channelUpdateEnable = ENABLE; channelsetup[1].channelTimercounterValue = 0; channelsetup[1].channelPeriodValue = 300; channelsetup[1].channelPulsewidthValue = 100; channelsetup[2].channelType = MCPWM_CHANNEL_EDGE_MODE; channelsetup[2].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO; channelsetup[2].channelDeadtimeEnable = DISABLE; channelsetup[2].channelDeadtimeValue = 0; channelsetup[2].channelUpdateEnable = ENABLE; channelsetup[2].channelTimercounterValue = 0; channelsetup[2].channelPeriodValue = 300; channelsetup[2].channelPulsewidthValue = 200; MCPWM_ConfigChannel(LPC_MCPWM, 0, &channelsetup[0]); MCPWM_ConfigChannel(LPC_MCPWM, 1, &channelsetup[1]); MCPWM_ConfigChannel(LPC_MCPWM, 2, &channelsetup[2]); #if DC_MODE_TEST /* * - DC mode enabled. * - Invert Output enabled * - A0 and A1 output pin is internally routed to A0 signal */ MCPWM_DCMode(LPC_MCPWM, ENABLE, ENABLE, (MCPWM_PATENT_A0|MCPWM_PATENT_A1)); #endif #if AC_MODE_TEST /* * - AC mode is enabled. */ MCPWM_ACMode(LPC_MCPWM, ENABLE); #endif #if CAPTURE_MODE_TEST /* * Capture mode in this case is used to detect the falling edge on MCO0B output pin. * The MCFB0 input pin therefore must be connected to MCO0B. (P1.20 - P1.22) * - Capture Channel 0. * - Capture falling edge on MCFB0 input pin. * - Interrupt enabled on capture event. */ captureCfg.captureChannel = 0; captureCfg.captureFalling = ENABLE; captureCfg.captureRising = DISABLE; captureCfg.hnfEnable = DISABLE; captureCfg.timerReset = DISABLE; MCPWM_ConfigCapture(LPC_MCPWM, 0, &captureCfg); // Reset flag for the first time CapFlag = RESET; // Enable interrupt for capture event on MCI0 (MCFB0) MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE); /* Enable interrupt for MCPWM */ NVIC_EnableIRQ(MCPWM_IRQn); #endif MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE); // Main loop while (1) { // Timer_Wait(LPC_TIM0, 1000); //delay for(i=0; i<100000; i++); channelsetup[0].channelPulsewidthValue = (channelsetup[0].channelPulsewidthValue >= 300) ? 0 : channelsetup[0].channelPulsewidthValue + 20; channelsetup[1].channelPulsewidthValue = (channelsetup[1].channelPulsewidthValue >= 300) ? 0 : channelsetup[1].channelPulsewidthValue + 20; channelsetup[2].channelPulsewidthValue = (channelsetup[2].channelPulsewidthValue >= 300) ? 0 : channelsetup[2].channelPulsewidthValue + 20; _DBG_("Update!"); MCPWM_WriteToShadow(LPC_MCPWM, 0, &channelsetup[0]); MCPWM_WriteToShadow(LPC_MCPWM, 1, &channelsetup[1]); MCPWM_WriteToShadow(LPC_MCPWM, 2, &channelsetup[2]); #if CAPTURE_MODE_TEST // Check capture flag is set or not if (CapFlag) { // Print out the value _DBG("Capture Value: "); _DBD32(CapVal); _DBG_(""); // Setup a new capture event MCPWM_ConfigCapture(LPC_MCPWM, 0, &captureCfg); // Re-Enable interrupt for capture event on MCI0 (MCFB0) MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE); // Reset flag CapFlag = RESET; } #endif } /* Loop forever */ return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { uint32_t pre_secval = 0, inc = 0, calib_cnt = 0; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* In this example: * Suppose that the RTC need periodically adjust after each 5 second. * And the time counter need by incrementing the counter by 2 instead of 1 * We will observe timer counter after calibration via serial display */ // Init RTC module RTC_Init(LPC_RTC); /* Enable rtc (starts increase the tick counter and second counter register) */ RTC_ResetClockTickCounter(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); //Set current time = 0 RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0); /* Setting Timer calibration * Calibration value = 6s; * Direction = Forward calibration * So after each 6s, calibration logic can periodically adjust the time counter by * incrementing the counter by 2 instead of 1 */ RTC_CalibConfig(LPC_RTC, 6, RTC_CALIB_DIR_FORWARD); RTC_CalibCounterCmd(LPC_RTC, ENABLE); /* Set the CIIR for second counter interrupt*/ RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Loop forever */ while(1) { if(pre_secval != secval) { if(pre_secval > secval) inc = 60 + secval - pre_secval; else inc = secval - pre_secval; if(inc > 1) { _DBG ("Second: "); _DBD(secval); _DBG("--> Increase ");_DBD(inc); _DBG(" after ");_DBD(calib_cnt);_DBG(" seconds"); _DBG_(""); calib_cnt = 0; } else { _DBG ("Second: "); _DBD(secval); _DBG_(""); calib_cnt++; } pre_secval = secval; } } }
/*********************************************************************//** * @brief c_entry: Main TIMER program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Select pin: * P1.28: MAT0.0 * P1.22: MAT1.0 * P0.6: MAT2.0 * P0.10: MAT3.0 */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 1; PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 22; PINSEL_ConfigPin(&PinCfg); PinCfg.Portnum = 0; PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 10; PINSEL_ConfigPin(&PinCfg); // Initialize 4 timers, prescale count time of 100uS TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 100; TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_Init(LPC_TIM1, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_Init(LPC_TIM2, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_Init(LPC_TIM3, TIM_TIMER_MODE,&TIM_ConfigStruct); // Configure 4 match channels // use channel 0, MR0 TIM_MatchConfigStruct.MatchChannel = 0; // Enable interrupt when MR0 matches the value in TC register TIM_MatchConfigStruct.IntOnMatch = TRUE; //Enable reset on MR0: TIMER will reset if MR0 matches it TIM_MatchConfigStruct.ResetOnMatch = TRUE; //Stop on MR0 if MR0 matches it TIM_MatchConfigStruct.StopOnMatch = FALSE; //Toggle MR0 pin if MR0 matches it TIM_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_TOGGLE; // Set Match value TIM_MatchConfigStruct.MatchValue = 700; // Set configuration for Tim_MatchConfig TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct); TIM_MatchConfigStruct.MatchValue = 600; TIM_ConfigMatch(LPC_TIM1,&TIM_MatchConfigStruct); TIM_MatchConfigStruct.MatchValue = 500; TIM_ConfigMatch(LPC_TIM2,&TIM_MatchConfigStruct); TIM_MatchConfigStruct.MatchValue = 800; TIM_ConfigMatch(LPC_TIM3,&TIM_MatchConfigStruct); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01)); /* Enable interrupt for timer 0 */ NVIC_EnableIRQ(TIMER0_IRQn); // To start timer 0 TIM_Cmd(LPC_TIM0,ENABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER1_IRQn, ((0x01<<3)|0x02)); /* Enable interrupt for timer 1 */ NVIC_EnableIRQ(TIMER1_IRQn); // To start timer 1 TIM_Cmd(LPC_TIM1,ENABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER2_IRQn, ((0x01<<3)|0x03)); /* Enable interrupt for timer 1 */ NVIC_EnableIRQ(TIMER2_IRQn); // To start timer 1 TIM_Cmd(LPC_TIM2,ENABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER3_IRQn, ((0x01<<3)|0x04)); /* Enable interrupt for timer 1 */ NVIC_EnableIRQ(TIMER3_IRQn); // To start timer 1 TIM_Cmd(LPC_TIM3,ENABLE); while(1); return (1); }
void initialize_logging() { debug_frmwrk_init(); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_M_SETUP_Type transferMCfg; uint32_t tempp; uint8_t *pdat; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_M == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_M == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Slave I2C peripheral I2C_Init(I2CDEV_M, 100000); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_M, ENABLE); /* Transmit -------------------------------------------------------- */ _DBG_("Press '1' to transmit"); while (_DG != '1'); _DBG_("Start Transmit..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = Master_Buf; transferMCfg.tx_length = sizeof(Master_Buf); transferMCfg.rx_data = NULL; transferMCfg.rx_length = 0; transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); /* Receive -------------------------------------------------------- */ _DBG_("Press '2' to receive"); while(_DG != '2'); _DBG_("Receive..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = NULL ; transferMCfg.tx_length = 0; transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } #if 1 /* Transmit and receive -------------------------------------------------------- */ _DBG_("Press '3' to Transmit, then repeat start and receive..."); while (_DG != '3'); /* Initialize buffer */ Buffer_Init(0); master_test[0] = 0xAA; master_test[1] = 0x55; /* Start I2C slave device first */ transferMCfg.sl_addr7bit = I2CDEV_S_ADDR; transferMCfg.tx_data = master_test ; transferMCfg.tx_length = sizeof(master_test); transferMCfg.rx_data = Master_Buf; transferMCfg.rx_length = sizeof(Master_Buf); transferMCfg.retransmissions_max = 3; I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING); #endif pdat = Master_Buf; // Verify for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Master_Buf)){ _DBG_("Verify successfully"); } I2C_DeInit(I2CDEV_M); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { EXTI_InitTypeDef EXTICfg; GPIO_Init(); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); PINSEL_ConfigPin(2, 10,1); ADC_Init(LPC_ADC, 100); ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, ENABLE); ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE); GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, GPIO_DIRECTION_OUTPUT); GPIO_SetDir(BRD_LED_2_CONNECTED_PORT, BRD_LED_2_CONNECTED_MASK, GPIO_DIRECTION_OUTPUT); /* Initialize External 0 interrupt */ EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT0; /* edge sensitive */ EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_Config(&EXTICfg); #if (INT_MODE == 0) //same group, different sub-levels (Tail-chaining example) //sets group priorities: 8 - subpriorities: 3 NVIC_SetPriorityGrouping(4); //000:10 (bit 7:3) assign eint0 to group 0, sub-priority 2 within group 0 NVIC_SetPriority(EINT0_IRQn, 2); NVIC_SetPriority(ADC_IRQn, 0x01); #else //different group - (Late-arriving example) ================================================== //sets group priorities: 8 - subpriorities: 3 NVIC_SetPriorityGrouping(4); //000:00 (bit 7:3) assign eint0 to group 0, sub-priority 0 within group 0 NVIC_SetPriority(EINT0_IRQn, 0); NVIC_SetPriority(ADC_IRQn, 0x04); #endif NVIC_EnableIRQ(EINT0_IRQn); /* Enable ADC in NVIC */ NVIC_EnableIRQ(ADC_IRQn); while(1) { // Start conversion ADC_StartCmd(LPC_ADC, ADC_START_NOW); /* Enable ADC in NVIC */ NVIC_EnableIRQ(ADC_IRQn); } }