没有合适的资源?快使用搜索试试~ 我知道了~
首页stm32_GP2Y1010AU0F
stm32_GP2Y1010AU0F
需积分: 10 109 下载量 147 浏览量
更新于2023-06-03
2
收藏 295KB DOCX 举报
stm32_GP2Y1010AU0F 里面有51的 以及stm32的 有ad的平均算法 等等
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/9116891/bg2.jpg)
使用 PA0 接收模拟信号,PB1 发送脉冲信号。
代码如下:
GP2Y.c
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include"GP2Y.h"
#include"system.h"
u16AD_PM;
voidGP2Yinit(void)
{
//定义变量
ADC_InitTypeDefA_InitStructure;
GPIO_InitTypeDefG_InitStructure; //PA0
GPIO_InitTypeDefGpio_InitStructure;//PB1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1,ENABLE);//使能
ADC2 通道时钟
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//设置 ADC 分频因子 672M/6=12,ADC 最大时间不能超过 14M
//PA0作为模拟通道输入引脚
G_InitStructure.GPIO_Pin=GPIO_Pin_0;
G_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//模拟输入引脚
GPIO_Init(GPIOA,&G_InitStructure);
ADC_DeInit(ADC1);//复位 ADC1,将外设ADC1的全部寄存器重设为缺省值
A_InitStructure.ADC_Mode=ADC_Mode_Independent;//ADC 工作模式:ADC1 和 ADC2 工作在独立模式
A_InitStructure.ADC_ScanConvMode=DISABLE;//模数转换工作在单通道模式
A_InitStructure.ADC_ContinuousConvMode=DISABLE;//模数转换工作在单次转换模式
A_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;//转换由软件而不是外部
触发启动
A_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;//ADC 数据右对齐
A_InitStructure.ADC_NbrOfChannel=1;//顺序进行规则转换的 ADC 通道的数目
ADC_Init(ADC1,&A_InitStructure);//根据 ADC_InitStruct 中指定的参数初始化外设 ADCx 的寄存器
ADC_Cmd(ADC1,ENABLE);//使能指定的 ADC1
ADC_ResetCalibration(ADC1);//使能复位校准
while(ADC_GetResetCalibrationStatus(ADC1));//等待复位校准结束
ADC_StartCalibration(ADC1);//开启 AD 校准
while(ADC_GetCalibrationStatus(ADC1));//等待校准结束
Gpio_InitStructure.GPIO_Pin=GPIO_Pin_1;
Gpio_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//推挽输出
Gpio_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&Gpio_InitStructure);
GP2Y_High;
}
voidGetGP2Y(void)
{
floatpm;
GP2Y_Low;
delay_us(280);
![](https://csdnimg.cn/release/download_crawler_static/9116891/bg3.jpg)
45
46
47
48
49
50
51
52
AD_PM=Get_Adc(ADC_Channel_0); //PA0
delay_us(40);
GP2Y_High;
delay_us(9680);
pm=0.17*AD_PM-0.1;//电压-灰尘转换
printf("%f\n",pm);
}
GP2Y.h
?
1
2
3
4
5
6
7
8
9
#ifndef__GP2Y_H
#define__GP2Y_H
#include"stm32f10x_lib.h"
#defineGP2Y_HighGPIO_SetBits(GPIOB,GPIO_Pin_1);
#defineGP2Y_LowGPIO_ResetBits(GPIOB,GPIO_Pin_1);
voidGP2Yinit(void);
voidGetGP2Y(void);
#endif
PB1 输出波形
获取到灰尘数值。
剩余13页未读,继续阅读
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/955d703de18b45deb458ac65be0e5f61_shudenaye.jpg!1)
shudenaye
- 粉丝: 7
- 资源: 6
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)