xbl1986的专栏

#ifndef __ADC_H__#define __ADC_H__#include <rtthread.h>void rt_hw_adc_init(void);#endif#include <rtthread.h>#include <stm32f10x.h>void rt_hw_adc_init(void){ADC_InitTypeDef ADC_InitStructure;GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0;GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AIN;GPIO_Init(GPIOC,&GPIO_InitStructure);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_10, 1,ADC_SampleTime_13Cycles5);ADC_Cmd (ADC1,ENABLE);//使能或者失能指定的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);//使能或者失能指定的ADC的软件转换启动功能while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)==RESET); //检查制定ADC标志位置1与否 ADC_FLAG_EOC 转换结束标志位adc = 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 function test.)#endif

,有希望在的地方,痛苦也成欢乐

xbl1986的专栏

相关文章:

你感兴趣的文章:

标签云: