⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 zigbee子节点源代码
💻 C
字号:

#include "include.h"

#include "adcmain.h"
//UINT8 PPP[8];
//UINT64 PT;
//void adc_main();
UINT8 psduLength;
int main( void )
{
    int i;  
    PORT_INIT();
    SPI_INIT();
    InitClock();
    //time_sync_init();
    //Time_B0_init();///////////////////////////
    //Init_ADC12();
    adc_main();
    /*basicRfInit(26, 0x2420, 0x5678);
    basicRfReceiveOn(); 
    P2IFG=0;  ///TEST
    ///TEST
   //Tx device
  /* 
    basicRfInit(RFCHANNEL, PANID, 0x1234);
    basicRfReceiveOn();

    BYTE frameType=NWK_FCF_DATA;
    BYTE discoverRoute=NWK_FCF_SUPPRESSROUTEDISCOVERY;
    BOOL security=FALSE;
    WORD nwkFrameControlField;
    nwkFrameControlField = frameType;
    nwkFrameControlField |= (NWK_FCF_PROTOCOLVERSION<<2);
    nwkFrameControlField |= (discoverRoute<<6);
    if(security)
    {
          nwkFrameControlField |= BM(NWK_FCF_SECURITY); 
    }
    WORD destAddr=0x5678;
    WORD srcAddr=0x1234;
    BYTE radiusCounter=0x00;
    BYTE dataSeqNumber=0x00;
    UINT8 nsduLength=NWK_aMaxFramePayloadSize;
    BYTE nsdu[NWK_aMaxFramePayloadSize];
    BYTE txOption=MAC_TXOPTION_ACKTRANSMISSION;
    
    while(1)
    {
       while((P1IN&0xf0)==0xf0);
         if(!(P1IN&BM(SW1)))
          {
                for(i=0;i<nsduLength;i++)
                {
                      nsdu[i] = 0x11;
                }
          }
          if(!(P1IN&BM(SW2)))
          {
                for(i=0;i<nsduLength;i++)
                {
                      nsdu[i] = 0x22;
                }    
          }
          if(!(P1IN&BM(SW3)))
          {
                for(i=0;i<nsduLength;i++)
                {
                      nsdu[i] = 0x44;
                }    
          }
          if(!(P1IN&BM(SW4)))
          {
                for(i=0;i<nsduLength;i++)
                {
                      nsdu[i] = 0x88;
                }    
          } 
     
     for(int j=0;j<20;j++)
     { for(i=0;i<nsduLength;i++)
          {
                nsdu[i] = 0x11;
          }
          NLDEDATA_request(nwkFrameControlField, destAddr, srcAddr, radiusCounter, dataSeqNumber, nsduLength, nsdu, txOption);
          halWait(65535);
         
          
          for(i=0;i<nsduLength;i++)
          {
                nsdu[i] = 0x22;
          }
          NLDEDATA_request(nwkFrameControlField, destAddr, srcAddr, radiusCounter, dataSeqNumber, nsduLength, nsdu, txOption);
          halWait(65535);
          
          
          for(i=0;i<nsduLength;i++)
          {
                nsdu[i] = 0x44;
          }
          NLDEDATA_request(nwkFrameControlField, destAddr, srcAddr, radiusCounter, dataSeqNumber, nsduLength, nsdu, txOption);
          halWait(65535);
         
          
          for(i=0;i<nsduLength;i++)
          {
                nsdu[i] = 0x88;
          }
          NLDEDATA_request(nwkFrameControlField, destAddr, srcAddr, radiusCounter, dataSeqNumber, nsduLength, nsdu, txOption);
          halWait(65535);  
          halWait(65535);       
          halWait(65535);}
         
    }*/

 
          

  //Rx device
    halWait(1000);
      //_EINT();    
    
   
   /* 
    UINT8 x1,x2,x3,x4,x5;
    x1=0;
    x2=0;
    x3=0;
    x4=0;
    x5=0;*/
    
   
   //   convert_time_format8(1234567,PPP);
     // PT = convert_time_format64(PPP );
    gMACRxFrameInfo.ackReceived = FALSE;
    gMACRxFrameInfo.frameControlField = 0x0000;
    gMACRxFrameInfo.dataSeqNumber = 0x00;
    gMACRxFrameInfo.panId = 0x0000;
    gMACRxFrameInfo.destAddr = 0x0000;
    gMACRxFrameInfo.srcAddr = 0x0000;
    gMACRxFrameInfo.msduLength = 0;
   /* for(i=0;i<MAC_aMaxFramePayloadSize;i++)
    {
          gMACRxFrameInfo.msdu[i] = 0x00;
    }*/
    gMACRxFrameInfo.frameCheckSeq = 0x0000;
    gMACRxFrameInfo.msduStatus = FALSE;
    gPHYRxFrameInfo.psduStatus=TRUE;
    
   
    while(1)
    {
      //////////////////////////////////////////////////////////////////////
        
             //gPHYRxFrameInfo.psduStatus = FALSE;
              while(gPHYRxFrameInfo.psduStatus);
              
              gPHYRxFrameInfo.psduStatus = TRUE;
              
             // UINT8 psduLength;
              FASTSPI_READ_FIFO_BYTE(psduLength);
	      psduLength &= 0x7f;
	      gPHYRxFrameInfo.psduLength = psduLength;
             // UINT8 psdu[127];
              
	      FASTSPI_READ_FIFO_NO_WAIT(gPHYRxFrameInfo.psdu, psduLength);
              //for(int m=0;m<128;m++)
              //gPHYRxFrameInfo.psdu[m]=psdu[m+15];
	      
              
              SET_VREG_INACTIVE()  ;
              FASTSPI_STROBE(CC2420_SFLUSHRX);///清除接收寄存器
	      FASTSPI_STROBE(CC2420_SFLUSHRX);///清除接收寄存器
              
              WORD framecontrolfield;         
              framecontrolfield = (gPHYRxFrameInfo.psdu[1] << 8) | gPHYRxFrameInfo.psdu[0];
              BYTE dataseqnumber;
              dataseqnumber = gPHYRxFrameInfo.psdu[2];
              BYTE framecheckseq[2];        
              framecheckseq[0] = gPHYRxFrameInfo.psdu[gPHYRxFrameInfo.psduLength - 2];
              framecheckseq[1] = gPHYRxFrameInfo.psdu[gPHYRxFrameInfo.psduLength - 1];   
     
              if((gPHYRxFrameInfo.psduLength == MAC_aAckFrameSize) && (framecontrolfield == MAC_FCF_ACKNOWLEDGMENT) && (dataseqnumber == gPHYTxFrameInfo.psdu[2]))
              {
                    if(framecheckseq[1] & MAC_FCS_CRCOK)
                    {
                          gMACRxFrameInfo.ackReceived = TRUE;
                          gPHYRxFrameInfo.psduStatus = FALSE; 
                    }
                    else
                    {
                         gPHYRxFrameInfo.psduStatus = FALSE;      
                    }
              }
              else if(gPHYRxFrameInfo.psduLength < MAC_aDataFrameOverheadSize)
              {
                   gPHYRxFrameInfo.psduStatus = FALSE;
              }
                  else
                 {
                    MCPSDATA_indication();
                    gMACRxFrameInfo.msduStatus = FALSE;
                  }	     
              
         
    
          /*///////////////////////////////////////////// test ////////////
          
           changelocaltime();///校正当前时间
            _NOP();
           // if ( receivedtimeinfo.n<10)
              {
                
                for (int k=10;k>0;k--)
                {
                 
                  receivedtimeinfo.stdtime[k] = receivedtimeinfo.stdtime[k-1];//
                  Timelinearity.offset[k] = Timelinearity.offset[k-1];
                  
                }
                
                receivedtimeinfo.stdtime[0] = convert_time_format64(receivedtimeinfo.time) + Timelinearity.Time_offset ;
                Timelinearity.offset[0] =  Timelinearity.Time_offset ;
              }
              huigui_function(Timelinearity.offset,receivedtimeinfo.stdtime);///做线性回归算回归系数用于下一次时间估计
   *///////////////////////////////////////////// test //////////////////////////////////
        /*   while(!gMACRxFrameInfo.msduStatus);
          WORD gframecontrolfield=(gMACRxFrameInfo.msdu[1] << 8) | gMACRxFrameInfo.msdu[0];
          WORD destAddr=(gMACRxFrameInfo.msdu[3] << 8) | gMACRxFrameInfo.msdu[2];
          WORD srcAddr=(gMACRxFrameInfo.msdu[5] << 8) | gMACRxFrameInfo.msdu[4];
          BYTE radiusCounter=gMACRxFrameInfo.msdu[6];
          BYTE dataSeqNumber=gMACRxFrameInfo.msdu[7];
          UINT8 nsduLength=gMACRxFrameInfo.msduLength - NWK_aDataFrameOverheadSize;
          BYTE nsdu[NWK_aMaxFramePayloadSize];
          for(i=0;i<nsduLength;i++)
          {
                nsdu[i] = gMACRxFrameInfo.msdu[i+8];            
          }    
          gMACRxFrameInfo.msduStatus = FALSE;
      for ( int j=0;j<nsduLength;j++)
         {
            
          TXBUF0=nsdu[j];
          while ((UTCTL0&0x01)==0);
         }
         for (int v=0;v<1;v++)
         {
            TXBUF0=nsduLength;
          while ((UTCTL0&0x01)==0);
         }
   
          for(i=0;i<nsduLength;i++)
          {
                if(nsdu[i] == 0x11) x1++;
                else if(nsdu[i] == 0x22) x2++;
                else if(nsdu[i] == 0x44) x3++;
                else if(nsdu[i] == 0x88) x4++;
                else x5++;    
          }
          if(x1>0) P1OUT |= BM(LED1);
          if(x2>0) P1OUT |= BM(LED2);
          if(x3>0) P1OUT |= BM(LED3);
          if(x4>0) P1OUT |= BM(LED4);
         // if(x5>0) P1OUT |= BIT0+BIT1+BIT2+BIT3;
          halWait(1000);
          P1OUT &= 0xf0;
          x1=0;
          x2=0;
          x3=0;
          x4=0;
          x5=0; */
          
    }
  
    
//    P1OUT |= BIT0+BIT1+BIT2+BIT3;
    //return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -