58 lines
1.3 KiB
C
58 lines
1.3 KiB
C
#ifndef _AHT20_H
|
||
#define _AHT20_H
|
||
|
||
#include "user.h"
|
||
|
||
|
||
|
||
|
||
|
||
#define MYI2C_Tick 10//定时调用时间,单位:毫秒,请根据定时调用时间设置,定时调用时间设置范围1-100ms
|
||
#define MYI2C_Buffer_Size 20
|
||
|
||
|
||
#define Wait_Ack_time 199//等待ACK应答时间,单位:微秒
|
||
#define MinReadTim 500//读取传感器最小间隔时间,单位:毫秒
|
||
#define PowerOnTim 10//上电延迟10毫秒
|
||
#define MeasureTim 150//等待测量结果延迟150毫秒
|
||
|
||
|
||
|
||
#define SENSOR_IDLE 0 //
|
||
#define SENSOR_MEASURE 1 //
|
||
#define SENSOR_COMPLETE 2 //
|
||
|
||
|
||
typedef struct
|
||
{
|
||
|
||
uint8_t Adrr;
|
||
uint16_t timcnt;
|
||
uint8_t ErrFlag;
|
||
uint8_t Step;
|
||
uint16_t SetRTim;
|
||
|
||
uint8_t SendByte[MYI2C_Buffer_Size];
|
||
uint8_t ReadByte[MYI2C_Buffer_Size];
|
||
float RH;//湿度
|
||
float T;//温度
|
||
}MYI2C_Struct;
|
||
|
||
extern MYI2C_Struct SENx;
|
||
|
||
|
||
uint8_t AHT20_READ_FUNC(MYI2C_Struct *pst,uint8_t device_addr,uint8_t register_addr,uint8_t *pDat,uint8_t len);
|
||
uint8_t AHT20_WRITE_FUNC(MYI2C_Struct *pst,uint8_t device_addr,uint8_t register_addr,uint8_t *pDat,uint8_t len);
|
||
uint8_t CheckCrc8(uint8_t *pDat,uint8_t Lenth);
|
||
|
||
/* Exported functions ------------------------------------------------------- */
|
||
void AHT20_Init(MYI2C_Struct *pst,uint16_t ReadTimMS,uint16_t xAddr);
|
||
void AHT20_Handle(MYI2C_Struct *pst);
|
||
|
||
|
||
|
||
|
||
|
||
#endif
|
||
|