资源简介
SHT20温湿度传感器程序(使用GPIO口模拟I2C),包含头文件与c文件,内含中文技术手册!!
代码片段和文件信息
/**
* @file SHT2x.c
* @brief 温湿度传感器
* @details
* @author 华兄
* @email 591881218@qq.com
* @date 2015
* @version vX.XX
* @par Copyright (c):
* 华兄电子
* @par History:
* version: author date desc\n
*/
#include “includes.h“
SHT2x_PARAM g_sht2x_param;
void SHT2x_Delay(u32 n)
{
u8 i;
while(n--)
{
for(i = 0; i < 100; i++)
{
asm(“NOP“);
}
}
}
void SHT2x_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = SHT2x_SCL_PIN | SHT2x_SDA_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(SHT2x_I2C_PORT &GPIO_InitStructure);
SHT2x_SCL_HIGH();
SHT2x_SDA_HIGH();
SHT2x_Delay(80);
SHT2x_SoftReset();
}
void SHT2x_SCL_OUTPUT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = SHT2x_SCL_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(SHT2x_I2C_PORT &GPIO_InitStructure);
}
void SHT2x_SCL_INPUT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = SHT2x_SCL_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SHT2x_I2C_PORT &GPIO_InitStructure);
}
void SHT2x_SDA_OUTPUT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = SHT2x_SDA_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(SHT2x_I2C_PORT &GPIO_InitStructure);
}
void SHT2x_SDA_INPUT(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = SHT2x_SDA_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SHT2x_I2C_PORT &GPIO_InitStructure);
}
void SHT2x_I2cStartCondition(void)
{
SHT2x_SCL_OUTPUT();
SHT2x_SDA_OUTPUT();
SHT2x_SDA_HIGH();
SHT2x_SCL_HIGH();
SHT2x_SDA_LOW();
SHT2x_Delay(30);
SHT2x_SCL_LOW();
SHT2x_Delay(30);
}
void SHT2x_I2cStopCondition(void)
{
SHT2x_SCL_OUTPUT();
SHT2x_SDA_OUTPUT();
SHT2x_SDA_LOW();
SHT2x_SCL_LOW();
SHT2x_SCL_HIGH();
SHT2x_Delay(30);
SHT2x_SDA_HIGH();
SHT2x_Delay(30);
}
void SHT2x_I2cAcknowledge(void)
{
SHT2x_SCL_OUTPUT();
SHT2x_SDA_OUTPUT();
SHT2x_SDA_LOW();
SHT2x_SCL_HIGH();
SHT2x_Delay(80);
SHT2x_SCL_LOW();
SHT2x_Delay(80);
}
void SHT2x_I2cNoAcknowledge(void)
{
SHT2x_SCL_OUTPUT();
SHT2x_SDA_OUTPUT();
SHT2x_SDA_HIGH();
SHT2x_SCL_HIGH();
SHT2x_Delay(80);
SHT2x_SCL_LOW();
SHT2x_Delay(80);
}
u8 SHT2x_I2cReadByte(void)
{
u8 i val = 0;
SHT2x_SCL_OUTPUT();
SHT2x_SDA_OUTPUT();
SHT2x_SDA_HIGH();
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10264 2015-08-19 11:08 SHT2x.c
文件 3065 2015-08-18 17:57 SHT2x.h
文件 482899 2013-08-05 12:15 SHT20 中文技术手册.pdf
----------- --------- ---------- ----- ----
496228 3
相关资源
- TSL2561 测试代码
- STM32 模拟SPI 一主多从
- stm32输出锯齿波,频率可调
- STM32F103四个通用定时器编码器模式配
- stm32+MAX7219数码管模块显示程序 spi接口
- stm32和rfid读卡器模块
- LD3320语音识别模块stm32例程调试
- AN3155 STM32 bootloader协议ISP
- 数据手套数据包格式
- STM32短信接收发送TEXT
- ADA2200驱动
- Cortex-M3 反汇编器
- STM32F103ZET6原理图
- STM32L053C8T6驱动240×240彩屏钟表显示时
- STM32 AD7124
- ADS8688的STM32驱动代码
- stm32f103c8t6 最小系统 开发板 AD电路图
- stm32 modbus
- STM32 4*4矩阵键盘扫描方式
- STM32F103 AM2302温湿度模块驱动例程
- STM32F103 NRF24L01无线通讯模块驱动例程
- DHT11与STM32F103ZET6
- stm32f103的PCF8563驱动代码
- STM32并口、串口驱动12864
- STM32F1+PS2+Serial+PWM (KEIL5)
- STM32f103zet6.Schlib 器件原理图 封装 Al
- 基于stm32的血压算法
- STM32F103串口DMA接收
- STM32 DMA中断模式下ADC多通道数据采集
- 通过PID算法控制STM32的PWM输出
评论
共有 条评论