自己也是初學者,大部分程序是芯片、顯示屏自帶的例程,自己移植并修改為我所用,代碼沒有仔細整理,但沒有用到的函數全部注釋掉了,也加了必要的注釋,方便閱讀
再次向原作者表示感謝。。。
自己測試全部通過,
SHT31 SCL和SDA在i2c_hal.c中修改
顯示如圖。
51hei圖片_20191220221314.jpg (177.75 KB, 下載次數: 52)
下載附件
2019-12-20 22:13 上傳
51hei截圖_20191220221645.png (5.21 KB, 下載次數: 53)
下載附件
2019-12-20 22:17 上傳
單片機源程序如下:
- //-- Includes -----------------------------------------------------------------
- #include "system.h"
- #include "sht3x.h"
- #include "math.h"
- #include "i2c_hal.h"
- ft temperature; // temperature [°C]
- ft humidity; // relative humidity [%RH]
-
- void OLED_P20x48Ch(unsigned char x, y, N);
- void OLED_P14x32Ch(unsigned char x, y, N);
- void Delay100us(unsigned int j);
- void SHT3X_Init(u8t i2cAddress);
- void SHT3X_SetI2cAdr(u8t i2cAddress);
- etError SHT3X_GetTempAndHumi(ft* temperature, ft* humidity,
- etRepeatability repeatability, etMode mode,
- u8t timeout);
- void Write_IIC_Byte(unsigned char IIC_Byte);
- void display(void);
- int main(void)
- {
- SHT3X_Init(0x44) ;
- display();
-
- while(1)
- {
- int a,b,c;
- etError error;
- I2c_StartCondition();
- if(SHT_SDA != 0){} // do error handling here
-
- error =SHT3X_GetTempAndHumi(&temperature, &humidity, REPEATAB_HIGH, MODE_CLKSTRETCH, 50);
-
- I2c_StopCondition();
-
- a=floor(temperature);
- b=floor(temperature*10);
- c=(int)(humidity) ;
-
- OLED_P20x48Ch(0,2,(a/10));
- OLED_P20x48Ch(23,2,(a%10));
- OLED_P14x32Ch(48,4,(b%10));
-
- OLED_P20x48Ch(80,2,(c/10));
- OLED_P20x48Ch(103,2,(c%10));
- //Delay100us(250);
- }
- }
復制代碼
所有資料51hei提供下載:
SHT31_OLED12864溫濕度.zip
(93.8 KB, 下載次數: 180)
2019-12-20 22:36 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|