コード例 #1
0
ファイル: board.c プロジェクト: Silmac/ModulAid
/* 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);
}
コード例 #2
0
ファイル: acmp.c プロジェクト: frankzzcn/M2_SE_RTOS_Project
/**
 * @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;
}