#ifndef __ADC_H__#define __ADC_H__#include <rtthread.h>void rt_hw_adc_init(void);#endif
# Include <rtthread. h> # include <stm32f10x. h> void construct (void) {ADC_InitTypeDef ADC_InitStructure; using GPIO_InitStructure; using (encoding, ENABLE); Using (encoding, ENABLE); Using = GPIO_Pin_0; using = callback; GPIO_Init (GPIOC, & GPIO_InitStructure); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // standalone mode = DISABLE; // continuous multi-channel mode = ENABLE; // Continuous Conversion Scheme = ADC_ExternalTrigConv_None; // conversion is not determined by the outside world. bytes = ADC_DataAlign_Right; // right-aligned bytes = 1; // Number of scan channels ADC_Init (ADC1, & ADC_InitStructure); ADC_RegularChannelConfig (ADC1, ADC_Channel_10, 1, dependencies); ADC_Cmd (ADC1, ENABLE); // enables or disables the specified ADCADC_ResetCalibration (ADC1); while (ADC_GetResetCalibrationStatus (ADC1); ADC_StartCalibration (ADC1 ); rt_kprintf ("ACD init ..... OK \ n \ r ") ;}# ifdef RT_USING_FINSH # include <finsh. h> void adc (void) {rt_int32_t adc; rt_kprintf ("hello here is a ADC test \ n \ r"); ADC_SoftwareStartConvCmd (ADC1, ENABLE ); // enable or disable the software conversion startup function of the specified ADC while (ADC_GetFlagStatus (ADC1, ADC_FLAG_EOC) = RESET ); // check whether the specified ADC_FLAG_EOC flag position is 1 or not. ADC_GetConversionValue (ADC1); rt_kprintf ("ADC: 0X % xV \ n \ r", adc ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc); rt_kprintf ("ADC: 0X % xV \ n \ r", adc * 3230 ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc * 3230); rt_kprintf ("ADC: 0X % xV \ n \ r", adc * 3230/4095 ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc * 3230/4095); rt_thread_delay (RT_TICK_PER_SECOND/2);} FINSH_FUNCTION_EXPORT (adc, start adc test function .) # endif