不用自己写程序,
用stm32f10x_adc.c中的函数调用一下就可以了
提醒一下,在调用ADC_Init之前先把42脚配成AN功能。
然后用
AD_value = ADC_GetConversionValue(ADC1);就可以了。
给你一段参考的
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_13Cycles5);
/* Configure high and low analog watchdog thresholds */
ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0fff, 0x0000);
/* Configure channel8 as the single analog watchdog guarded channel */
ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0);
/* Enable analog watchdog on one regular channel */
ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
AD_value = ADC_GetConversionValue(ADC1);
温馨提示:内容为网友见解,仅供参考