STM32F030读取温湿度传感器SHT20的C程序源码(经..doc
《STM32F030读取温湿度传感器SHT20的C程序源码(经..doc》由会员分享,可在线阅读,更多相关《STM32F030读取温湿度传感器SHT20的C程序源码(经..doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流STM32F030读取温湿度传感器SHT20的C程序源码(经.【精品文档】第 16 页* * file HTU20.x* brief HTU20 function* cpu STM32F051* compiler KeiluVision V5.01* author Hanney* copyright* version V1.0.1* date 18-Sept-2015* modifydate20-Sept-2015* * attention/STM32F051 模拟IIC/#include boardAPI.h/#include stm32f0xx.h/
2、#include HTU20.h/#include uart.h/#include delay.h#include stm32f0xx.h#include stm32lib.h#define HTU20_CLK RCC_AHBPeriph_GPIOB#define HTU20_SDA_PORT GPIOB#define HTU20_SCL_PORT GPIOB#define HTU20_SDA_PIN GPIO_Pin_11#define HTU20_SCL_PIN GPIO_Pin_10#define RESOLUTION_11b 0x81 /RH 11 TH 11#define RESOL
3、UTION_12b 0x01 /RH 8 TH 12#define RESOLUTION_13b 0x80 /RH 10 TH 13#define RESOLUTION_14b 0x00 /RH 12 TH 14#define OTP_disEN 0x02 /不能启动OPT加载#define OTP_EN 0x00 /启动OPT加载#define RESh 16 /湿度解析度#define RESt 16 /温度解析度#define MeasureDelay 12 /解析延时时间单位mstypedef unsigned char BYTE;typedef unsigned int WORD;B
4、YTE Delayms;GPIO_InitTypeDef GPIO_InitStructure;voiddelayms(BYTE ms;* brief Start HTU GPIO port CLK* retvalNonevoidHTUInit(voidRCC_AHBPeriphClockCmd(HTU20_CLK, ENABLE;IIC address=*/ #define SHT20ADDR 0x80/*= ACK and NACK defination=*/ #define ACK 0#define NACK 1HTU20D Command CodeCommand Code Commen
5、t Trigger Temperature Measurement 0xe3 Hold master Trigger Humidity Measurement 0xe5 Hold master Trigger Temperature Measuremeng 0xf3 No Hold master Trigger Humidity Measurement 0xf5 No Hold master Write user register 0xe6Read user register 0xe7Soft Reset 0xfe#define SOFT_RESET 0xfe#define READ_REGI
6、STER 0xe7#define WRITE_REGISTER 0xe6#define TRIGGER_TEMP 0xf3#define TRIGGER_HUMI 0xf5HTU20 operate interface#define HTU20_SCL GPIO_ReadInputDataBit(HTU20_SCL_PORT,HTU20_SCL_PIN #define HTU20_SDA GPIO_ReadInputDataBit(HTU20_SDA_PORT,HTU20_SDA_PIN* brief Set SDA pin dircate as output* retvalNonevoid
7、HTU20_SDA_OUT(GPIO_StructInit(&GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = HTU20_SDA_PIN;GPIO_InitStructure.GPIO_Mode =GPIO_Mode_OUT;GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL;GPIO_Init(HTU20_SD
8、A_PORT, &GPIO_InitStructure;* brief Set SDA pin dircate as intput* retvalNonevoid HTU20_SDA_IN(GPIO_StructInit(&GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = HTU20_SDA_PIN;GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IN;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;GPIO_InitStructure.GPIO_PuPd =G
9、PIO_PuPd_NOPULL;GPIO_Init(HTU20_SDA_PORT, &GPIO_InitStructure;* brief Set SDA pin as high* retvalNonevoid HTU20_SDA_1(GPIO_SetBits(HTU20_SDA_PORT,HTU20_SDA_PIN;* brief Set SDA pin as low* retvalNonevoid HTU20_SDA_0(GPIO_ResetBits(HTU20_SDA_PORT,HTU20_SDA_PIN; * brief Set SCL pin dircate as output* r
10、etvalNonevoid HTU20_SCL_OUT(GPIO_StructInit(&GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = HTU20_SCL_PIN; GPIO_InitStructure.GPIO_Mode =GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2; GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL;
11、 GPIO_Init(HTU20_SCL_PORT, &GPIO_InitStructure;* brief Set SCL pin as high* retvalNonevoid HTU20_SCL_1(GPIO_SetBits(HTU20_SCL_PORT,HTU20_SCL_PIN;* brief Set SCL pin as low* retvalNonevoid HTU20_SCL_0(GPIO_ResetBits(HTU20_SCL_PORT,HTU20_SCL_PIN;Simulation I2C Function* brief A short delay for iic syn
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- STM32F030 读取 温湿度 传感器 SHT20 程序 源码
限制150内