山东联通网站备案,广东网络seo推广,农业企业网站模板免费下载,wordpress文章全屏这个多通道采用非扫描模式--单次转换模式
1.代码配置链路图 2. ADC的输入通道 3.ADC的非扫描模式的转换模式#xff08;单次和连续#xff09; 4.ADC的扫描模式的转换模式#xff08;单次和连续#xff09; 5.采集校准 代码实验#xff1a; 代码部分#xff1a;
#inclu…这个多通道采用非扫描模式--单次转换模式
1.代码配置链路图 2. ADC的输入通道 3.ADC的非扫描模式的转换模式单次和连续 4.ADC的扫描模式的转换模式单次和连续 5.采集校准 代码实验 代码部分
#include stm32f10x.h // Device headervoid AD_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);RCC_ADCCLKConfig(RCC_PCLK2_Div6);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode GPIO_Mode_AIN;GPIO_InitStructure.GPIO_Pin GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;GPIO_InitStructure.GPIO_Speed GPIO_Speed_50MHz;GPIO_Init(GPIOA, GPIO_InitStructure);ADC_InitTypeDef ADC_InitStructure;ADC_InitStructure.ADC_Mode ADC_Mode_Independent;ADC_InitStructure.ADC_DataAlign ADC_DataAlign_Right;ADC_InitStructure.ADC_ExternalTrigConv ADC_ExternalTrigConv_None;ADC_InitStructure.ADC_ContinuousConvMode DISABLE;ADC_InitStructure.ADC_ScanConvMode DISABLE;ADC_InitStructure.ADC_NbrOfChannel 1;ADC_Init(ADC1, ADC_InitStructure);ADC_Cmd(ADC1, ENABLE);ADC_ResetCalibration(ADC1);while (ADC_GetResetCalibrationStatus(ADC1) SET);ADC_StartCalibration(ADC1);while (ADC_GetCalibrationStatus(ADC1) SET);
}uint16_t AD_GetValue(uint8_t ADC_Channel)
{ADC_RegularChannelConfig(ADC1, ADC_Channel, 1, ADC_SampleTime_55Cycles5);ADC_SoftwareStartConvCmd(ADC1, ENABLE);while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) RESET);return ADC_GetConversionValue(ADC1);
}#include stm32f10x.h // Device header
#include Delay.h
#include OLED.h
#include AD.huint16_t AD0,AD1,AD2,AD3;int main(void)
{OLED_Init();AD_Init();OLED_ShowString(1, 1, AD0:);OLED_ShowString(2, 1, AD1:);OLED_ShowString(3, 1, AD2:);OLED_ShowString(4, 1, AD3:);while (1){AD0 AD_GetValue(ADC_Channel_0);AD1 AD_GetValue(ADC_Channel_1);AD2 AD_GetValue(ADC_Channel_2);AD3 AD_GetValue(ADC_Channel_3);OLED_ShowNum(1,5,AD0,5);OLED_ShowNum(2,5,AD1,5);OLED_ShowNum(3,5,AD2,5);OLED_ShowNum(4,5,AD3,5);Delay_ms(500);}}