|
剛加入貴站,參考許多資料,非常感謝。
前幾天在此下載了bme280 pdf,
得知濕度的讀出方法。
bme280與bmp280的差別僅在於多了濕度資料可以讀出,
所以用bmp280程式小改一下就完成。
以下是我購(gòu)買(mǎi)的C51練習(xí)模組,
c51.JPG (177.02 KB, 下載次數(shù): 67)
下載附件
2019-7-22 13:31 上傳
他帶有繼電器,接腳在p1_7
繼電器的三個(gè)引出點(diǎn)從左至右:
b接,com , a接
我用外接電源透過(guò)繼電器a接點(diǎn)接風(fēng)扇,
超過(guò)25度C時(shí)轉(zhuǎn)
低於25度C時(shí)停
----------------------
LCD1602 用p0
RS P2_4
RW P2_5
EN P2_6
----------------------
bme280
SCL P3_0
SDA P3_1
bme280.jpg (48.83 KB, 下載次數(shù): 71)
下載附件
2019-7-22 13:53 上傳
----------------------
由於模組買(mǎi)來(lái)時(shí)並未附硬體電路圖,
所以僅寫(xiě)出IO供參考。
---------------------
RUN
c51-bme280.JPG (113.61 KB, 下載次數(shù): 62)
下載附件
2019-7-22 13:56 上傳
T:攝氏溫度
P:壓力(hpa)
H:海拔 (以1013.25hpa 為基點(diǎn)計(jì)算)
HU:濕度(%)
-----------------------
風(fēng)扇轉(zhuǎn)
c51-fan.JPG (104.49 KB, 下載次數(shù): 65)
下載附件
2019-7-22 13:53 上傳
---------------------
濕度讀取的部份,
註測(cè)位址 0xF2
讀出位址0xFD,0xFE
---------------------
程式碼壓縮打包.
---------------------
新手,請(qǐng)多多指教。
單片機(jī)源程序如下:
- #include <reg52.h>
- #include "common.h"
- #include "Lcd.h"
- #include "bmp280.h"
- sbit Relay = P1^7 ;
- unsigned char abc[16];
- void main()
- {
- uint i,j;
- //int j = 0;
- //uart_init();
- Init_BMP280();//﹍てBMP180
- LCD_Init();
- LCD_Clear();//睲
- Delay_1ms(50);
- //EA = 1;
- while(1)
- {
-
- bmp280Convert();
- if (temperature >= 2500 ){
- Relay=0; //Fan on
- }
- else {
- Relay=1; //Fan off
- }
- if (j==0){
-
- abc[0]='T';
- abc[1]=':';
- abc[2]='0'+ temperature/1000;
- abc[3]='0'+ temperature%1000/100;
- abc[4]='.'; //計(jì)翴
- abc[5]='0'+ temperature%100/10;
- abc[6]='0'+ temperature%10/1;
- abc[7]=' ';
- abc[8]='P';
- abc[9]=':';
- abc[10]='0'+pressure/100000;
- abc[11]='0'+pressure%100000/10000;
- abc[12]='0'+pressure%10000/1000;
- abc[13]='0'+pressure%1000/100;
- abc[14]='.';
- abc[15]='0'+pressure%100/10;
-
- }
-
- if (j==1){
-
- abc[0]='H';
- abc[1]=':';
- abc[2]='0'+height/100000;
- abc[3]='0'+height%100000/10000;
- abc[4]='0'+height%10000/1000;
- abc[5]='0'+height%1000/100;
- abc[6]='.';
- abc[7]='0'+height%100/10;
- /*
- abc[2]='0'+humidity/10;
- abc[3]='0'+humidity%10;
- abc[4]=' ';
- abc[5]=' ';
- abc[6]=' ';
- abc[7]=' '; */
- abc[8]=' ';
- abc[9]='H';
- abc[10]='U';
- abc[11]=':';
- abc[12]='0'+humidity/10;
- abc[13]='0'+humidity%10;
- abc[14]=' ';
- abc[15]=' ';
- }
-
-
- for(i=0;i<16;i++)
- {
- LCD_Write_Char(i,j,abc[i]);
- }
- //j++;
- Delay_1ms(50);
- j=!j;
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
BMP280-LCD.rar
(10.9 KB, 下載次數(shù): 118)
2019-7-22 14:18 上傳
點(diǎn)擊文件名下載附件
BME280 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|