stm32 adc 采样烟雾传感器
单片机源程序如下:
- // ADC 单通道采集,不使用DMA,一般只有ADC2才这样使用,因为ADC2不能使用DMA
- #include "stm32f10x.h"
- #include "bsp_usart.h"
- #include "bsp_adc.h"
- #include "bsp_TiMbase.h"
- extern __IO uint16_t ADC_ConvertedValue;
- volatile uint32_t time = 0; // ms 计时变量
- // 局部变量,用于保存转换计算后的电压值
- float ADC_ConvertedValueLocal = 0.0;
- int main(void)
- {
- // 配置串口
- USART_Config();
-
- // ADC 初始化
- ADCx_Init();
-
- BASIC_TIM_Init();
- while (1)
- {
- ADC_ConvertedValueLocal =(float) ADC_ConvertedValue/4096*3.3;
- if ( time == 1000 )
- {
- time = 0;
- printf("\r\n The current AD value = %f V \r\n",
- ADC_ConvertedValueLocal);
- }
- }
- }
- /*********************************************END OF FILE**********************/
复制代码
所有资料51hei提供下载:
物联网设计.7z
(599.28 KB, 下载次数: 43)
|