/** * @brief Main program. * @param None * @retval None */ void main ( void ) { ClockConfigure(); #if defined (_USE_DEBUG_UART_) DebugUARTInit(); #endif /* #if defined (_USE_DEBUG_UART_) */ /* ADC Configuration */ /* Reset all ADC settings */ ADC_DeInit(); DEBUG_PRINTF("ADC Init..."); // Inti clock ADC RST_CLK_ADCclkSelection(RST_CLK_ADCclkCPU_C1); RST_CLK_ADCclkPrescaler(RST_CLK_ADCclkDIV2); // Enable clock ADC RST_CLK_ADCclkEnable(ENABLE); RST_CLK_PCLKcmd(RST_CLK_PCLK_ADC, ENABLE); ADC_StructInit(&sADC); sADC.ADC_StartDelay = 0; sADC.ADC_TempSensor = ADC_TEMP_SENSOR_Enable; sADC.ADC_TempSensorAmplifier = ADC_TEMP_SENSOR_AMPLIFIER_Enable; sADC.ADC_TempSensorConversion = ADC_TEMP_SENSOR_CONVERSION_Enable; sADC.ADC_IntVRefConversion = ADC_VREF_CONVERSION_Disable; sADC.ADC_IntVRefTrimming = 1; ADC_Init(&sADC); /* ADC1 Configuration */ ADCx_StructInit(&sADCx); sADCx.ADC_ClockSource = ADC_CLOCK_SOURCE_CPU; sADCx.ADC_SamplingMode = ADC_SAMPLING_MODE_CICLIC_CONV; sADCx.ADC_ChannelSwitching = ADC_CH_SWITCHING_Disable; sADCx.ADC_ChannelNumber = ADC_CH_TEMP_SENSOR; sADCx.ADC_Channels = 0; sADCx.ADC_LevelControl = ADC_LEVEL_CONTROL_Disable; sADCx.ADC_LowLevel = 0; sADCx.ADC_HighLevel = 0; sADCx.ADC_VRefSource = ADC_VREF_SOURCE_INTERNAL; sADCx.ADC_IntVRefSource = ADC_INT_VREF_SOURCE_INEXACT; sADCx.ADC_Prescaler = ADC_CLK_div_512; sADCx.ADC_DelayGo = 7; ADC1_Init(&sADCx); /* Enable ADC1 EOCIF and AWOIFEN interupts */ ADC1_ITConfig(ADCx_IT_END_OF_CONVERSION, ENABLE); /* Enable ADC IRQ */ NVIC_EnableIRQ(ADC_IRQn); DEBUG_PRINTF("Ok\r\n"); /* ADC1 enable */ ADC1_Cmd(ENABLE); while (1); }
static void SetUARTFunction(void) { DebugUARTInit(); IintDVDUart(); }
void main(void) #endif { ClockConfigure(); #if defined (_USE_DEBUG_UART_) DebugUARTInit(); #endif /* #if defined (_USE_DEBUG_UART_) */ /* Enable peripheral clocks ----------------------------------------------*/ RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_ADC | RST_CLK_PCLK_PORTD | RST_CLK_PCLK_PORTB), ENABLE); /* Reset PORTD settings */ PORT_DeInit(MDR_PORTD ); /* Configure ADC pin: ADC2 */ /* Configure PORTD pin 9 */ PORT_InitStructure.PORT_Pin = PORT_Pin_9; PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_InitStructure.PORT_MODE = PORT_MODE_ANALOG; PORT_Init(MDR_PORTD, &PORT_InitStructure); /* Configure PORTB pins 0, 1 for output to switch LED1,2 on/off */ /* Configure PORTB pins 0, 1 */ PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_Pin = PORT_Pin_0 | PORT_Pin_1; PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_SPEED = PORT_SPEED_MAXFAST; PORT_Init(MDR_PORTB, &PORT_InitStructure); /* ADC Configuration */ /* Reset all ADC settings */ ADC_DeInit(); DEBUG_PRINTF("ADC Init..."); // Inti clock ADC RST_CLK_ADCclkSelection(RST_CLK_ADCclkCPU_C1); RST_CLK_ADCclkPrescaler(RST_CLK_ADCclkDIV2); // Enable clock ADC RST_CLK_ADCclkEnable(ENABLE); RST_CLK_PCLKcmd(RST_CLK_PCLK_ADC, ENABLE); ADC_StructInit(&sADC); sADC.ADC_StartDelay = 0; sADC.ADC_TempSensor = ADC_TEMP_SENSOR_Enable; sADC.ADC_TempSensorAmplifier = ADC_TEMP_SENSOR_AMPLIFIER_Enable; sADC.ADC_TempSensorConversion = ADC_TEMP_SENSOR_CONVERSION_Disable; sADC.ADC_IntVRefConversion = ADC_VREF_CONVERSION_Disable; sADC.ADC_IntVRefTrimming = 0; sADC.ADC_IntVRefAmplifier = ADC_INT_VREF_AMPLIFIER_Enable; ADC_Init(&sADC); ADCx_StructInit(&sADCx); sADCx.ADC_ClockSource = ADC_CLOCK_SOURCE_CPU; sADCx.ADC_SamplingMode = ADC_SAMPLING_MODE_CICLIC_CONV; sADCx.ADC_ChannelSwitching = ADC_CH_SWITCHING_Disable; sADCx.ADC_ChannelNumber = ADC_CH_ADC2; sADCx.ADC_Channels = 0; sADCx.ADC_LevelControl = ADC_LEVEL_CONTROL_Enable; sADCx.ADC_LowLevel = L_Level; sADCx.ADC_HighLevel = H_Level; sADCx.ADC_VRefSource = ADC_VREF_SOURCE_INTERNAL; sADCx.ADC_IntVRefSource = ADC_INT_VREF_SOURCE_INEXACT; sADCx.ADC_Prescaler = ADC_CLK_div_16; sADCx.ADC_DelayGo = 0xF; ADC1_Init(&sADCx); /* Enable ADC1 EOCIF and AWOIFEN interupts */ ADC1_ITConfig((ADCx_IT_END_OF_CONVERSION | ADCx_IT_OUT_OF_RANGE), ENABLE); NVIC_EnableIRQ(ADC_IRQn); /* ADC1 enable */ ADC1_Cmd(ENABLE); while (1); }