liguohong327:
#include"mydefine.h"#include#includeBYTEmyAddr;BYTETx_buffer[4];BYTERx_buffer[4];BYTESendDataFlag;BYTETxcnt=0;WORDres;//externvolatileTIMER4_TABLE_ENTRYtimer4Table[TIMER_ADM_TABLE_LENGTH];unsignedcharditab[16]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};//x小数处理0.1unsignedchardisplay[5]={0x00,0x00,0x00,0x00,0x00};BYTEsendBuffer1[4];//发送的温度数据BOOL__xdataDebugFlag;BOOL__xdataFeetdogFlag;//主节点用函数voidInitWatchdog(void);//看门狗初始化voidFeetDog(void);//喂狗voidScanKey(void);//按键扫描voidInitkey(void);//按键初始化voidLED_Glitter(BYTEt,BYTEled);//灯闪烁一次/*******************************************************************************@fnmain**@brief*Mainfunctionofapplicationexample.**Parameters:**@paramvoid**@returnvoid*******************************************************************************/voidmain(void){SET_MAIN_CLOCK_SOURCE(CRYSTAL);//设置主时钟SET_MAIN_CLOCK_SPEED(MHZ_26);CLKCON=(CLKCON&0xC7);//CLKCON&=~0X7F;//选择32768时钟,看门狗使用//InitWatchdog();//FeetdogFlag=1;INIT_LED1();INIT_LED3();Initkey();IO_DIR_PORT_PIN(2,0,IO_OUT);P2SEL&=~0x01;P2_0=0;//使能串口InitUART(57600);//初始化串口UARTxISRopen();//打开接收中断RLED=LED_ON;YLED=LED_ON;halWait(200);halWait(200);halWait(100);RLED=LED_OFF;YLED=LED_OFF;#ifdefCC1110_TXmyAddr=ADDRESS_TX;radioInit(FREQUENCY_4_CC1110,myAddr);//射频初始化Init_T1();SendDataFlag=0;Txcnt=1;P0SEL&=~0x08;//仅仅发送时候,使用P0.3,接收时P0.3用于串口#endif#ifdefCC1110_RXmyAddr=ADDRESS_RX;radioInit(FREQUENCY_4_CC1110,myAddr);//射频初始化BYTElength;BYTEsender;BYTE*receiveBuffer;#endifINT_GLOBAL_ENABLE(INT_ON);//打开总中断while(1){//ScanKey();//************************************************************************************************************//等待接收数据,时间为500ms#ifdefCC1110_RX//if(FeetdogFlag)//FeetDog();if(radioReceive(&receiveBuffer,&length,RECEIVE_TIMEOUT,&sender)){for(BYTEi=0;i4;//取中间八位,即整数部分的值display[3]=display[4]/100;//取百位数据暂存display[1]=display[4]%100;//取后两位数据暂存display[2]=display[1]/10;//取十位数据暂存display[1]=display[1]%10;}voidInitWatchdog(void){WDCTL=0x00;//时间间隔一秒,看门狗模式WDCTL|=0x08;//启动看门狗}voidFeetDog(void){WDCTL=0xa0;WDCTL=0x50;}