示例#1
0
/**
 * @brief	main routine for ADC example
 * @return	Function should not exit
 */
int main(void)
{
	uint16_t dataADC;
	int j;

	SystemCoreClockUpdate();
	Board_Init();
	Init_ADC_PinMux();
	DEBUGSTR("ADC Demo\r\n");

	/* ADC Init */
	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, ENABLE);

	while (1) {
		/* Start A/D conversion */
		Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

		/* Waiting for A/D conversion complete */
		while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH0, ADC_DR_DONE_STAT) != SET) {}

		/* Read ADC value */
		Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &dataADC);

		/* Print ADC value */
		DEBUGOUT("ADC value is 0x%x\r\n", dataADC);

		/* Delay */
		j = 500000;
		while (j--) {}
	}

	/* Should not run to here */
	return 0;
}
示例#2
0
文件: main.c 项目: Maxim-DE/W5500_EVB
/**
 * @brief    Main routine for W5500 EVB firmware
 * @return   Function should not exit.
 */
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
#endif
#endif

    uint16_t dataADC;
    int16_t calc_temp;

    /* Flag for running user's code  */
    bool run_user_applications = true;

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ1);

	/* ADC Init */
	Init_ADC_PinMux();
	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_EnableChannel(LPC_ADC, TEMP_SENSOR_CH, ENABLE);

#ifdef _MAIN_DEBUG_
    printf("\r\n=======================================\r\n");
	printf(" WIZnet W5500 EVB\r\n");
	printf(" On-board Temperature sensor demo example v%d.%.2d\r\n", VER_H, VER_L);
	printf("=======================================\r\n");
	printf(">> This example using ADC, SysTick\r\n");
	printf("=======================================\r\n");
#endif

	/* Main loop ***************************************/
	while(1)
	{
    	// TODO: insert user's code here
    	if(run_user_applications)
    	{
    		if(ADC_read_enable)
    		{
    			ADC_read_enable = false;

				/* Start A/D conversion */
    			Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

				/* Waiting for A/D conversion complete */
				while (Chip_ADC_ReadStatus(LPC_ADC, TEMP_SENSOR_CH, ADC_DR_DONE_STAT) != SET) {}

				/* Read ADC value */
				Chip_ADC_ReadValue(LPC_ADC, TEMP_SENSOR_CH, &dataADC);

				/* Calculate ADC value to Celsius temperature */
				calc_temp = (((dataADC * SUPPLY_VOLTAGE) / 1023) - 500) / 10;

				/* Print ADC value */
				printf("ADC value is 0x%x, ", dataADC);
				/* Print Celsius temperature */
				printf("Celsius temperature : %d C\r\n", calc_temp);
    		}
    	} // End of user's code
	} // End of Main loop

    return 0;
}