无线传感网络课程设计 联系客服

发布时间 : 星期日 文章无线传感网络课程设计更新完毕开始阅读

adctemp = ADCCON3;

adctemp &= ~(HAL_ADC_CHN_BITS | HAL_ADC_DEC_BITS | HAL_ADC_REF_BITS); adctemp |= channel | resbits | HAL_ADC_REF_VOLT; /* writing to this register starts the extra conversion */ ADCCON3 = adctemp;

/* Wait for the conversion to be done */ while (!(ADCCON1 & HAL_ADC_EOC)); /* Disable channel after done conversion */ ADCCFG &= (adcChannel ^ 0xFF); /* Read the result */

reading = (int16) (ADCL);

reading |= (int16) (ADCH << 8); /* Treat small negative as 0 */ if (reading < 0) reading = 0;

switch (resolution) {

case HAL_ADC_RESOLUTION_8: reading >>= 8; break;

case HAL_ADC_RESOLUTION_10: reading >>= 6; break;

case HAL_ADC_RESOLUTION_12: reading >>= 4; break;

case HAL_ADC_RESOLUTION_14: default: break; } #else

// unused arguments (void) channel; (void) resolution; #endif

return ((uint16)reading); }

4.实验总结

打开“ EXPLORERF-CC2530 增配传感器光盘 V1.1\\软件工具及驱动” 中工具 “ 串口调试助手.exe”配置正确的串口号和通讯波特率,填入测试的数据指令, 点击发送就可以获取网关返回的读取到节点的数据。

实验四、综合实验

1. 实验原理

以一LED灯,LED显示屏作为工具。当LED灯显示时,LED显示屏上也显示信息灯亮。

将LED灯作为协调器,LED显示屏作为终端,当LED灯亮时,会通过组网将信息传给终端,即此时LED显示屏显示灯亮,即LED显示屏给予LED灯亮的一个信息反馈。 2.实验步骤

选择烧取设备的类型为CoordinatorEB-pro, 点击菜单 Project,选择“ Rebuild All”,等待一会儿工程文件编译完成。等待一会儿工程文件编译完成把仿真器与网关通过仿真器下载线连接起来。确保仿真器与计算机、仿真器与网关底板连接正确, ZigBee 无线模块正确地插在网关底板后。点击菜单 Project,选择“ Debug”,或点击如下图标,等待一会儿即完成程序下载.将烧取设备类型改为EndDeviceEB-pro,重复上述步骤。当LED亮时,此时显示屏也将有相应反应。 4.实验代码

#include \#include \#include \

#include \#include \

#include \#include \

#include \

/* HAL */

#include \#include \#include \#include \#include #include \#include \

#include \#include \

#include \#include \#include \

#include \

/********************************************************************* * MACROS */

/********************************************************************* * CONSTANTS */

/********************************************************************* * TYPEDEFS */

/********************************************************************* * GLOBAL VARIABLES */

// This list should be filled with Application specific Cluster IDs. const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] = {

SAMPLEAPP_PERIODIC_CLUSTERID, SAMPLEAPP_FLASH_CLUSTERID };

const SimpleDescriptionFormat_t SampleApp_SimpleDesc = {

SAMPLEAPP_ENDPOINT, // int Endpoint;

SAMPLEAPP_PROFID, // uint16 AppProfId[2]; SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2]; SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4; SAMPLEAPP_FLAGS, // int AppFlags:4;

SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; (cId_t *)SampleApp_ClusterList, // uint8 *pAppInClusterList; SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; (cId_t *)SampleApp_ClusterList // uint8 *pAppInClusterList; };

// This is the Endpoint/Interface description. It is defined here, but // filled-in in SampleApp_Init(). Another way to go would be to fill // in the structure here and make it a \// way it's defined in this sample app it is define in RAM. endPointDesc_t SampleApp_epDesc;

/********************************************************************* * EXTERNAL VARIABLES */

extern unsigned char SensorNum; extern INT8U DispNum;

unsigned char DispState = 0; unsigned char Relay1State = 0; unsigned char Relay2State = 0; extern INT16U LEDDispNum;

/********************************************************************* * EXTERNAL FUNCTIONS */

/********************************************************************* * LOCAL VARIABLES */

uint8 SampleApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // SampleApp_Init() is called. devStates_t SampleApp_NwkState;

uint8 SampleApp_TransID; // This is the unique message ID (counter) uint8 *ieeeAddr;//物理地址

unsigned char LCDUPDATA = 0;//LCD刷新标致位 unsigned char Shakeflag = 0; unsigned char InfraredState = 0; unsigned char InfraredCount = 0; unsigned char InfraredInitFlag = 0; unsigned char HallState = 0; union f1{

uint8 RxBuf[32]; struct UARTCOMBUF {

uint8 Head; //头 uint8 HeadCom[3]; //命令头 uint8 Laddr[8]; //物理地址 uint8 Saddr[2]; //网络地址 uint8 DataBuf[16]; //数据缓冲区 uint8 CRC; //校验位 uint8 LastByte;//帧尾 }RXDATA;

}UartRxBuf;//从串口接收到的数据帧

union e{

uint8 TxBuf[32]; struct UARTBUF {

uint8 Head; //头 uint8 HeadCom[3]; //命令头 uint8 Laddr[8]; //物理地址