佚名通过本文主要向大家介绍了zigbee dht11,zigbee源代码,zigbee源程序,zigbee智能家居代理,zigbee无线传输模块等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:-基于zigbee2530的DHT11传感(含源代码和注释)
描述:
首先我自己买了一个18B20测温度,连接成功后,又买了一个DHT11,在18B20代码上修改的,但是出了些问题:
我在单片机上使用DHT11是成功的(含串口通信),移植到zigbee中的,大家看看出了那些问题:(主要在171 187行)
描述:
zigbee 2530 DHT11 湿度zigbeeCC2530DHT11传感器
我自己觉得zigbee开发板一个测量并传输芯片内部实验不好玩,自己又设计了2个首先我自己买了一个18B20测温度,连接成功后,又买了一个DHT11,在18B20代码上修改的,但是出了些问题:
我在单片机上使用DHT11是成功的(含串口通信),移植到zigbee中的,大家看看出了那些问题:(主要在171 187行)
/***********************************************************************************
Filename: SensorTXRX.c
Description: DHT11 温湿度传感器
我的思路:移植自 单片机,在18B20温度传感器基础上改的,但是传输的结果总是默认值
***********************************************************************************/
typedef unsigned char U8; //魏然2013年2月23日
typedef unsigned int U16;//wrwrwrwrwr
U8 U8FLAG,U8temp;//从DATA总线上读到的位值
U8 U8comdata;//从DHT11读取的一个字节的数据///????????????????????????????????
#define set_DQ_in P1DIR &= ~0x40 //P1.5
#define set_DQ_out P1DIR |= 0x40
U8 shidu_shi,shidu_ge,wendu_shi,wendu_ge;
U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;//校验过的温度高8位,温度低8位,湿度高8位,湿度低8位,校验和8位
U8 U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp;//未经校验的数据
//sbit P2_0 = P2^2;//此端口是数据输入端
//U8 dispbuf1[]="hum= temp= \n"; //用于串口通讯的字符数组。
U8 table1[]="0123456789";
/***********************************************************************************
* INCLUDES
*/
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
#include "Uart.h"
#include "mydefine.h"
#include "ioCC2530.h"
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xBEEF
#define APP_PAYLOAD_LENGTH 10
#define WENDU_CMD 0
#define GUANG_CMD 1
#define ZHENG_CMD 2
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
#define LED_BlUE 1
#define LED_RED 2
#define LED_YELLOW 3
/***********************************************************************************/
/**********************************************************************************/
static uint8 pRxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
#ifdef DataRX
uchar UartData[30]="XWWK test Data!";
#endif
#ifdef SensorDataTX
uchar UartData[30]=" sg HUM:sg";
#endif
WORD res;
BYTE Tx_buffer[APP_PAYLOAD_LENGTH]=" sg HUM:sg";
unsigned char ditab[16]=
{0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09}; //x小数处理 0.1
unsigned char display[5]={0x00,0x00,0x00,0x00,0x00};
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appDataRx();
static void appSensorTX();
void Wait(unsigned int wait);
void work_temp(WORD tem);
//////////////////////////////魏然2013年2月23日////////////////////////
/*此部分是温湿度传感器公司给的程序段中的延时函数,为了便于理解,没有修改此处*/
void Delay(U16 z)
{
U8 x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Delay_10us(void)
{
U8 i;
i--;
i--;
i--;
i--;
i--;
i--;
}
/*****************从DHT11读取一个字节函数******************/
void COM(void)//
{
U8 i;
for(i=0;i<8;i++) //循环8次,读取8bit的数据
{
U8FLAG=2; //读取并等待DHT11发出的12-14us低电平开始信号
//set_DQ_out;//P1DIR=0x00;////
while((!P1_5)&&U8FLAG++);
Delay_10us();
Delay_10us();
Delay_10us();
U8temp=0;//跳过门限后判断总线是高还是低,高为1,低为0
//if(DHT11_DATA)
if(P1_5)U8temp=1;
U8FLAG=2;//等待1bit的电平信号结束,不管是0是1在118us后都变为低电平,否则错误超时