/* Set up and initialize all required blocks and functions related to the board hardware */ void Board_Init(void) { QUICKJACK_IO_Init(); /* Initialize GPIO */ Chip_GPIO_Init(LPC_GPIO_PORT); /* Initialize the LEDs */ Board_LED_Init(); // init sensor switch SensorSwitch_Init(); /* Configure GPIO pin as input pin */ Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 0, 0); /* MCU Tx Pin initialize */ Chip_IOCON_PinSetMode(LPC_IOCON, QUICKJACKTXPIN, PIN_MODE_INACTIVE); Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM); Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, QUICKJACKTXPINNUM, 1); /* MCU Rx Pin initialize */ Chip_IOCON_PinSetMode(LPC_IOCON, QUICKJACKRXPIN, PIN_MODE_INACTIVE); /* Configure analog comparator for Manchester Rx */ Chip_SWM_FixedPinEnable(SWM_FIXED_ACMP_I1, 1); Chip_ACMP_Init(LPC_CMP); Chip_ACMP_SetPosVoltRef(LPC_CMP, ACMP_POSIN_ACMP_I1); Chip_ACMP_SetNegVoltRef(LPC_CMP, ACMP_NEGIN_VLO); Chip_ACMP_SetupVoltLadder(LPC_CMP, (15<<1), false); Chip_ACMP_EnableVoltLadder(LPC_CMP); Chip_ACMP_SetHysteresis(LPC_CMP, ACMP_HYS_10MV); Chip_ACMP_SetEdgeSelection(LPC_CMP, ACMP_EDGESEL_RISING); /* Uncomment below 2 lines to connect analog comparator output to P1_0 (not needed for normal operation) */ // Chip_SWM_FixedPinEnable(SWM_FIXED_ACMP_I2, 0); // Chip_SWM_MovablePinAssign(SWM_ACMP_O_O, 1); Chip_ACMP_EdgeClear(LPC_CMP); NVIC_EnableIRQ(CMP_IRQn); /* Disable clocks to SWM and IOCON to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON); }
/** * @brief Main program body * @return Does not return */ int main(void) { /* initialize the board */ SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); /* initialize the ACMP */ Chip_ACMP_Init(LPC_CMP); /* Setup board specific ACMP pin muxing */ Init_ACMP_PinMux(); /* Positive and negative references, no hysteresis */ Chip_ACMP_SetupACMPRefs(LPC_CMP, CMP_INDEX, ACMP_POSIN_ADCIN_1, ACMP_NEGIN_VREF_DIV, ACMP_HYS_NONE); /* Edge triggered interrupt on both edges*/ Chip_ACMP_SetupACMPInt(LPC_CMP, CMP_INDEX, false, false, ACMP_EDGESEL_BOTH); Chip_ACMP_EnableCompInt(LPC_CMP, CMP_INDEX); Chip_ACMP_SetupVoltLadder(LPC_CMP, CMP_INDEX, 0x15, false); Chip_ACMP_EnableVoltLadder(LPC_CMP, CMP_INDEX); /* Setup Comparator Filter register to bypass filter and use SysClk without any division */ Chip_ACMP_SetCompFiltReg(LPC_CMP, CMP_INDEX, ACMP_SMODE_0, ACMP_CLKDIV_1); /* Enable Comparator */ Chip_ACMP_EnableComp(LPC_CMP, CMP_INDEX); /* Enable the Interrupt for the compare output */ NVIC_EnableIRQ(CMP3_IRQ); while (1) { /* Enter low power mode until interrupt */ __WFI(); if (Chip_ACMP_GetCompStatus(LPC_CMP, CMP_INDEX)) { Board_LED_Set(0, true); } else { Board_LED_Set(0, false); } } return 0; }
int __attribute__ ((noinline)) main(void) { /* set systick and start systick interrupt */ SysTick_Config(SYS_CORE_CLOCK/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS); /* turn on GPIO */ Chip_GPIO_Init(LPC_GPIO_PORT); /* disable SWCLK and SWDIO, after reset, boot code may activate this */ Chip_SWM_DisableFixedPin(2); Chip_SWM_DisableFixedPin(3); /* turn on IOCON */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); /* turn on switch matrix */ Chip_SWM_Init(); /* activate analog comperator */ Chip_ACMP_Init(LPC_CMP); /* let LED on pin 4 of the DIP8 blink */ Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 2); for(;;) { Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 2); delay_micro_seconds(500000UL); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 2); delay_micro_seconds(500000UL); } /* enter sleep mode: Reduce from 1.4mA to 0.8mA with 12MHz */ while (1) { SCB->SCR |= (1UL << SCB_SCR_SLEEPONEXIT_Pos); /* enter sleep mode after interrupt */ Chip_PMU_SleepState(LPC_PMU); /* enter sleep mode now */ } }