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

📄 basicdriver_signal_strength.c

📁 这是一个自动测量zigbee发射信号强度的原代码,可以直接运行,不用修改,测试已成功
💻 C
📖 第 1 页 / 共 5 页
字号:
                    if( PrintMenus )
                    {
                        PrintHeader((rom char *)"RSSI Sample Number");
                        c("    Please enter 2 decimal digits (1-49)\r\n");
                        c("      i.e. - enter 05 for 5 samples\r\n");
                        c(">>");    
                    }
_sampleRSSILoop1:
                    numRSSISamples = 0;                    
                    while(!ConsoleIsGetReady()){}                
                    input = ConsoleGet();
                    switch(input)
                    {
                        case '4':
                            numRSSISamples += 10;
                            //fall through
                        case '3':
                            numRSSISamples += 10;
                            //fall through
                        case '2':
                            numRSSISamples += 10;
                            //fall through
                        case '1':
                            numRSSISamples += 10;
                            //fall through
                        case '0':
                            break;
                        default:
                            goto _sampleRSSILoop1;
                    }
                    
                    ConsolePut(input);
                    
_sampleRSSILoop2:                    
                    while(!ConsoleIsGetReady()){}
                
                    input = ConsoleGet();
                    switch(input)
                    {
                        case '9':
                            numRSSISamples += 1;
                            //fall through
                        case '8':
                            numRSSISamples += 1;
                            //fall through
                        case '7':
                            numRSSISamples += 1;
                            //fall through
                        case '6':
                            numRSSISamples += 1;
                            //fall through                                                                                                              
                        case '5':
                            numRSSISamples += 1;
                            //fall through
                        case '4':
                            numRSSISamples += 1;
                            //fall through
                        case '3':
                            numRSSISamples += 1;
                            //fall through
                        case '2':
                            numRSSISamples += 1;
                            //fall through
                        case '1':
                            numRSSISamples += 1;
                            //fall through
                        case '0':
                            break;
                        default:
                            goto _sampleRSSILoop2;
                    }
                    
                    ConsolePut(input);
                    
                    if(numRSSISamples == 0)
                    {
                        if(PrintMenus)
                        {
                            c("\r\n\r\ndivide by 0 not allowed.  setting number of samples to 1.\r\n");
                        }
                        
                        numRSSISamples = 1;
                    }
                    
                    c("\r\n\r\n");
                    
                    goto MRF24J40_SubMenu;
                    
                case 'g':
                case 'G':
MRF24J40_Turbo_Mode_submenu:                
                    if( PrintMenus )
                    {
                        PrintHeader((rom char *)"Turbo Mode");
                        c("    (a) Enable Turbo Mode\r\n");
                        c("    (b) Disable Turbo Mode\r\n");
                        c(">>");  
                    }
                    input = ConsoleInput();
                    switch(input)
                    {
                        case 'a':
                        case 'A':
                            PHYSetShortRAMAddr(WRITE_BBREG0, 0x01);
                            PHYSetShortRAMAddr(WRITE_BBREG3, 0x38);
                            PHYSetShortRAMAddr(WRITE_BBREG4, 0x5C);
                            
                            PHYSetShortRAMAddr(WRITE_RFCTL,0x04);
                            PHYSetShortRAMAddr(WRITE_RFCTL,0x00);
                            if( PrintMenus )
                            {
                                c("\r\nDevice set to turbo mode.\r\n");
                            }
                            break;
                           
                       case 'b':
                       case 'B':
                            PHYSetShortRAMAddr(WRITE_BBREG0, 0x00);
                            PHYSetShortRAMAddr(WRITE_BBREG3, 0xD8);
                            PHYSetShortRAMAddr(WRITE_BBREG4, 0x9C);
                            
                            PHYSetShortRAMAddr(WRITE_RFCTL,0x04);
                            PHYSetShortRAMAddr(WRITE_RFCTL,0x00);
                            if( PrintMenus )
                            {
                                c("\r\nDevice set to normal mode.\r\n");
                            }
                            break;
                          
                        default:
                            if( PrintMenus )
                            {
                                c("Incorrect Menu Choice: ");
                                ConsolePut(input);
                                nl(); nl(); 
                            }
                            goto MRF24J40_Turbo_Mode_submenu;
                    }
                    break;
                    
                default:
                    goto MRF24J40_SubMenu;
            }
            break;
            
            
        case '2':
        
        
        
                    PHYSetShortRAMAddr(WRITE_RXMCR,0x23);
                    PHYSetShortRAMAddr(WRITE_RXFLUSH,0x01);
                    
                    if( UseExternal )
                    {
                        PHYSetShortRAMAddr(WRITE_GPIO, 0b00001100); //RX
                        Delay100TCYx(4);
                        c("Using external LNA\r\n");
                    }
                    
                    if(PrintMenus)
                    {
						nl();
                        c("Testing Signal Strength......\r\n");
                        c("\r\n");
                //        nl();
                    }
                    GIEH = 1;       //enable interrupts
                    
                    ReceivingMode = TRUE;
                
                    while(1)
                    {
                        if(ConsoleIsGetReady())
                        {
                            GIEH = 0;
                            ReceivingMode = FALSE;
                            if(PrintMenus)
                            {
                                goto MRF24J40_SubMenu;
                            }
                            else
                            {
                                goto MRF24J40_NewOption;
                            }
                        }
                    }
                    
                    break;
                    
                    
                    
                    
   //     case '2':
 //           if(PrintMenus)
 //           {
 //               PrintHeader((rom char *)"Testings......");
 //               c("    (a) Set the Radio in Receiving Mode\r\n");
 //               c("    (b) Transmit Precoded Packet Continuously\r\n");
 //               c("    (c) Transmit Packet Defined by User\r\n");
 //               c("    (d) Test Low Power Mode\r\n");
 //               c("    (e) Energy Detection on All Channels\r\n");
 //               c("    (f) Test Simple Local Oscillator\r\n");
 //               c("    (g) Test Single Tone Modulation\r\n");
 //               c("    (h) Test Sequential Transmit Mode for All Channels\r\n");
//                c("    (i) PER Test between Two Devices\r\n");
 //               c("    (z) Dump Values of Transceiver's Registers\r\n");
 //               c(">>");
//            }
//            input = ConsoleInput();
            
            switch(input)
            {
                case 'a':
                case 'A':
                    PHYSetShortRAMAddr(WRITE_RXMCR,0x23);
                    PHYSetShortRAMAddr(WRITE_RXFLUSH,0x01);
                    
                    if( UseExternal )
                    {
                        PHYSetShortRAMAddr(WRITE_GPIO, 0b00001100); //RX
                        Delay100TCYx(4);
                        c("Using external LNA\r\n");
                    }
                    
                    if(PrintMenus)
                    {
						nl();
                        c("Placing transceiver in receive mode\r\n");
                        c("Please reset the board to return to menu\r\n");
                        nl();
                    }
                    GIEH = 1;       //enable interrupts
                    
                    ReceivingMode = TRUE;
                
                    while(1)
                    {
                        if(ConsoleIsGetReady())
                        {
                            GIEH = 0;
                            ReceivingMode = FALSE;
                            if(PrintMenus)
                            {
                                goto MRF24J40_SubMenu;
                            }
                            else
                            {
                                goto MRF24J40_NewOption;
                            }
                        }
                    }
                    
                    break;
                
                case 'b':
                case 'B':
                    if(PrintMenus)
                    {
						nl();
                        ConsolePutROMString((rom char*)"Entering transmit mode.\r\n");
                        c("Press Any key to return to menu\r\n");
                        nl();
                    }
                    {
                        BYTE i;
                        
                        PHYSetLongRAMAddr(0x000,sizeof(PredefinedPacket));
                        PHYSetLongRAMAddr(0x001,sizeof(PredefinedPacket));
                        
                        for(i=2;i<(sizeof(PredefinedPacket)+2);i++)
                        {
                            PHYSetLongRAMAddr(i, PredefinedPacket[i-2]); 
                        }
                    }

                    if(UseExternal)
                    {
                        PHYSetShortRAMAddr(WRITE_GPIO, 0b00000011); //TX
                        Delay100TCYx(4);
                        c("Using external PA\r\n");
                    }
                    PHYSetShortRAMAddr(WRITE_TXNMTRIG,0b00000001);  //transmit packet without ACK requested 

        
                    while(1)
                    {
                        unsigned int j;
                        DWORD k;
                        
                        if(ConsoleIsGetReady())
                        {
                            if(PrintMenus)
                            {
                                goto MRF24J40_SubMenu;
                            }
                            else
                            {
                                goto MRF24J40_NewOption;
                            }
                        }
                        
                        k = ((DWORD)packetDelay)*((DWORD)packetDelay);
                        
                        do
                        {
                            for(j=0;j<200;j++)
                            {
                            }
                        }
                        while(k--);

                        PHYSetShortRAMAddr(WRITE_TXNMTRIG,0b00000001);  //transmit packet without ACK requested 
                    }

                    break;
                
                
                case 'c':
                case 'C':
                    if(PrintMenus)
                    {
                        c("Please enter the packet you want to transmit.\r\n");
                        c("Use all uppercase HEX values starting from the frame control (no length)\r\n");
                        c(" Press '=' when you are done.\r\n");
                        c(">>");
                    }
                    {
                        BYTE pingPong;
                        BYTE txPtr;
                        BYTE A,B;
                        
                        txPtr = 0;
                        pingPong = 0;
                        
                        while(1)
                        {
MRF24J40_read_tx:
                            while(!ConsoleIsGetReady()){}    

⌨️ 快捷键说明

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