资源简介

利用MSP430g2231+nrf24l01+DHT11实现温湿度远程无线监控

资源截图

代码片段和文件信息

#include
#include “DHT11.h“

unsigned char DATA;

#define PBIT BIT4
#define PIN P1IN
#define POUT P1OUT
#define PDIR P1DIR

#define DIR_IN PDIR&=~PBIT
#define DATA_H PDIR|=PBIT;POUT|=PBIT
#define DATA_L PDIR|=PBIT;POUT&=~PBIT
#define DATA_IN (PIN&PBIT)
    

void delayns(unsigned int ns)     //延时子函数
{
while(ns--); 
}



//数据格式:8bit湿度整数数据+8bit湿度小数数据+8bi温度整数数据+8bit温度小数数据+8bit校验和
unsigned char getData(unsigned char Data[5])
{
unsigned char ijk;
unsigned int overtime;
unsigned int t;
unsigned int threshold;


DATA_H;

//主机发送开始信号
DATA_L;
delayns(0x07ff); // >= 18ms

DATA_H;//主机拉高数据线,>=20us
delayns(5); 

DIR_IN;
overtime=0xffff;
while(DATA_IN==PBIT && overtime>0) overtime--; //等待高电平结束,即等待 DHT 的低电平响应信号
if(overtime==0) return 1;
delayns(1); // >= 20us -- 40us


overtime=0xffff;
while(DATA_IN==0 && overtime>0)overtime--; //等待低电平结束
if(overtime==0) return 2;

overtime=0xffff;
while(DATA_IN==PBIT && overtime>0)overtime--; //等待高电平结束
if(overtime==0) return 3;
threshold=(65536-overtime);
threshold>>=1;

for(j=0;j<5;j++)
{
k=0;
for(i=0;i<8;i++)
{
t=0;
k=k<<1;
while(DATA_IN==0 && t<0xffff) t++; //等待低电平结束
if(t==0xffff)
{
Data[0]=i;
return 4;
}

t=0;
while(DATA_IN==PBIT && t<0xffff) t++; //等待高电平结束
if(t==0xffff)
{
Data[0]=i;
return 5;
}
//Data[i+j*8]=t;
if(t>=threshold)
k|=0x01;
}
Data[j]=k;
}
k=0;
for(i=0;i<4;i++)
{
k+=Data[i];
}
if(k!=Data[4])
{
return 6;
}
return 0;
}
//*/

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-27 10:52  nrf24l01_430g2231_v2\
     文件       19032  2012-02-20 16:17  nrf24l01_430g2231_v2\Backup of new_430g2231_nrf24l01.ewd
     文件       47845  2012-02-21 16:58  nrf24l01_430g2231_v2\Backup of new_430g2231_nrf24l01.ewp
     目录           0  2013-11-27 09:51  nrf24l01_430g2231_v2\Debug\
     目录           0  2013-11-27 09:56  nrf24l01_430g2231_v2\Debug\Exe\
     文件       23500  2013-11-27 10:52  nrf24l01_430g2231_v2\Debug\Exe\new_430g2231_nrf24l01.d43
     目录           0  2013-11-27 09:51  nrf24l01_430g2231_v2\Debug\List\
     目录           0  2013-12-23 21:47  nrf24l01_430g2231_v2\Debug\Obj\
     文件      228288  2013-11-27 09:58  nrf24l01_430g2231_v2\Debug\Obj\dht11.pbi
     文件        9697  2013-11-27 09:58  nrf24l01_430g2231_v2\Debug\Obj\dht11.pbi.cout
     文件       12965  2013-11-27 09:59  nrf24l01_430g2231_v2\Debug\Obj\dht11.r43
     文件         865  2012-02-20 17:32  nrf24l01_430g2231_v2\Debug\Obj\EW101.r43
     文件         867  2012-02-20 17:18  nrf24l01_430g2231_v2\Debug\Obj\EW1110.r43
     文件         898  2012-02-19 21:50  nrf24l01_430g2231_v2\Debug\Obj\EW114D.r43
     文件         867  2012-02-21 17:20  nrf24l01_430g2231_v2\Debug\Obj\EW120D.r43
     文件         867  2012-02-21 17:19  nrf24l01_430g2231_v2\Debug\Obj\EW183D.r43
     文件         896  2012-02-20 16:08  nrf24l01_430g2231_v2\Debug\Obj\EW189.r43
     文件         867  2012-02-20 16:22  nrf24l01_430g2231_v2\Debug\Obj\EW18D1.r43
     文件         867  2012-02-21 17:23  nrf24l01_430g2231_v2\Debug\Obj\EW1E78.r43
     文件         867  2012-02-20 18:01  nrf24l01_430g2231_v2\Debug\Obj\EW1F50.r43
     文件         867  2012-02-20 16:18  nrf24l01_430g2231_v2\Debug\Obj\EW1F6A.r43
     文件         867  2012-02-20 16:18  nrf24l01_430g2231_v2\Debug\Obj\EW2008.r43
     文件         867  2012-02-20 18:02  nrf24l01_430g2231_v2\Debug\Obj\EW214C.r43
     文件         867  2012-02-21 18:14  nrf24l01_430g2231_v2\Debug\Obj\EW2372.r43
     文件         867  2012-02-20 17:47  nrf24l01_430g2231_v2\Debug\Obj\EW284B.r43
     文件         867  2012-02-20 18:20  nrf24l01_430g2231_v2\Debug\Obj\EW28BD.r43
     文件         867  2012-02-21 16:51  nrf24l01_430g2231_v2\Debug\Obj\EW2A5A.r43
     文件         867  2012-02-21 17:22  nrf24l01_430g2231_v2\Debug\Obj\EW2B6A.r43
     文件         867  2012-02-20 17:38  nrf24l01_430g2231_v2\Debug\Obj\EW2C06.r43
     文件         867  2012-02-20 17:19  nrf24l01_430g2231_v2\Debug\Obj\EW3104.r43
     文件         867  2012-02-20 16:58  nrf24l01_430g2231_v2\Debug\Obj\EW3459.r43
............此处省略114个文件信息

评论

共有 条评论