uint8 Saddr[2]; //网络地址 uint8 DataBuf[16]; //数据缓冲区 uint8 CRC; //校验位 uint8 LastByte;//帧尾 }TXDATA;
}UartTxBuf;//从串口发送数据帧
union h{
uint8 RxBuf[32]; struct RFRXBUF {
uint8 Head; //头
uint8 HeadCom[3]; //命令头 uint8 Laddr[8]; uint8 Saddr[2];
uint8 DataBuf[16]; //数据缓冲区 uint8 CRC; //校验位 uint8 LastByte;//帧尾 }RXDATA;
}RfRx;//无线接收缓冲区
union j{
uint8 TxBuf[32]; struct RFTXBUF {
uint8 Head; //头 uint8 HeadCom[3]; //命令头 uint8 Laddr[8]; uint8 Saddr[2];
uint8 DataBuf[16]; //数据缓冲区 uint8 CRC; //校验位 uint8 LastByte;//帧尾 }TXDATA;
}RfTx;//无线发送缓冲区
uint16 Ultrasonic_Count;//超声波计数
/***************************************************************************** void WaitUs(uint16 microSecs)
延时uS函数.
*****************************************************************************/
void WaitUs(uint16 microSecs) {
while(microSecs--) {
/* 32 NOPs == 1 usecs */
asm(\ asm(\ asm(\ asm(\ asm(\ asm(\ asm(\ } }
/***************************************************************************** uint8 SendData( uint16 addr, uint8 *buf, uint8 Leng)
发送一组数据.
*****************************************************************************/ uint8 SendData( uint16 addr, uint8 *buf, uint8 Leng) {
afAddrType_t SendDataAddr;
SendDataAddr.addrMode = (afAddrMode_t)Addr16Bit; SendDataAddr.endPoint = SAMPLEAPP_ENDPOINT; SendDataAddr.addr.shortAddr = addr;
if ( AF_DataRequest( &SendDataAddr, &SampleApp_epDesc, 2,//SAMPLEAPP_PERIODIC_CLUSTERID, Leng, buf, &SampleApp_TransID,
AF_DISCV_ROUTE, // AF_ACK_REQUEST,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) {
return 1; } else {
return 0;// Error occurred in request to send. } }
case 1://DAC 输出
if(DispState == 0) {
DAC_OUT_CON(0x07ff, 0x07ff);
LcdPutString16_8(0, 0, (void*)\ }
else if(DispState == 1) {
DAC_OUT_CON(0x03ff, 0x03ff);
sprintf(msg,\
LcdPutString16_8(0, 0, (void*)msg, 12 , 1); }
else if(DispState == 2) {
DAC_OUT_CON(0x0Bff, 0x0Bff);
sprintf(msg,\
LcdPutString16_8(0, 0, (void*)msg, 12 , 1); }
break; case 2://高亮LED控制 if(DispState == 0) { ChangT3Cmp0Val(0xff); P1_6 = 0; LcdPutString16_8(0, 0, (void*)\ } else if(DispState == 1) { ChangT3Cmp0Val(230); LcdPutString16_8(0, 0, (void*)\ } else if(DispState == 2) { ChangT3Cmp0Val(25); LcdPutString16_8(0, 0, (void*)\ } break; }
void SampleApp_Init( uint8 task_id ) {
SampleApp_TaskID = task_id;
SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0;
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here.
// If the hardware is other parts of the device add it in main().
#if defined ( HOLD_AUTO_START )
// HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif
// Fill out the endpoint description.
SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint description with the AF afRegister( &SampleApp_epDesc );
// Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID );
#ifdef WXL_COORD
MT_UartRegisterTaskID(SampleApp_TaskID); #endif }
void SampleApp_Init( uint8 task_id ) {
SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0;
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here.
// If the hardware is other parts of the device add it in main().