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

📄 basicdriver_1.c

📁 这是一个自动测量zigbee发射信号强度的原代码,可以直接运行,不用修改,测试已成功
💻 C
📖 第 1 页 / 共 5 页
字号:
                        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 'b':
        case 'B':
            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()){}    
                            input = ConsoleGet();
                            
                            switch(input)
                            {
                                case '0':
                                case '1':
                                case '2':
                                case '3':
                                case '4':
                                case '5':
                                case '6':
                                case '7':
                                case '8':
                                case '9':
                                    ConsolePut(input);
                                    B = (input - '0');
                                    break;
                                case 'A':
                                case 'B':
                                case 'C':
                                case 'D':
                                case 'E':
                                case 'F':
                                    ConsolePut(input);
                                    B = (input - 'A' + 0x0A);
                                    break;
                                case '~':
                                    if(PrintMenus)
                                    {
                                        c("Device Reset");
                                    }
                                    {WORD i; for(i=0;i<30000;i++){}}
                                    Reset();
                                    break;
                                case '=':
                                    if(PrintMenus)
                                    {
                                        c("\r\n\r\nTransmitting Packet.\r\nReturning to the main menu.\r\n\r\n");
                                    }
                                    {
                                        BYTE i;
                                        
                                        for(i=0;i<txPtr;i++)
                                        {
                                            PHYSetLongRAMAddr(i+2, testData.txData[i]); /* Dest Address  */
                                        }
                                    }
                                    PHYSetLongRAMAddr(0x000,txPtr);
                                    PHYSetLongRAMAddr(0x001,txPtr);
                                    
                                    if(UseExternal)
                                    {
                                        PHYSetShortRAMAddr(WRITE_GPIO, 0b00000011); //TX
                                        Delay100TCYx(4);
                                        c("Using external PA\r\n");
                                    }
                                    
                                    PHYSetShortRAMAddr(WRITE_TXNMTRIG,0b00000001);  //transmit packet without ACK requested 
                                                                        
                                    goto MRF24J40_SubMenu;
                                    break;
                                default:
                                    goto MRF24J40_read_tx;
                                    break;
                            }
                            if(pingPong == 1)
                            {
                                testData.txData[txPtr++] = A+B;
                                pingPong = 0;
                            }
                            else
                            {
                                A = B<<4;
                                pingPong = 1;
                            }
                        }
                    }
                    goto MRF24J40_SubMenu;
                
                case 'd':
                case 'D':
MRF24J40_Low_Power_submenu:                
                    if( PrintMenus )
                    {
                        PrintHeader((rom char *)"Test Low Power Mode");
                        c("    (a) Disable Pullups\r\n");
                        c("    (b) Place MRF in sleep mode\r\n");
                        c("    (c) Place MRF in reset\r\n");
                        c("    (d) Place Controller to sleep\r\n");
                        c("    (e) Wake up the MRF from sleep mode \r\n");
                        c(">>");
                    }
                    input = ConsoleInput();
                    switch(input)
                    {
                        case 'a':
                        case 'A':
                            if(PrintMenus)
                            {
                                nl();
								c("Pullups disabled\r\n");
								c("Reset the device to get out of disabled pullups\r\n");
								nl();
                                RBPU = 1;
                            }
                            break;
                        
                        case 'b':
                        case 'B':
                            if(PrintMenus)
                            {
                                c("MRF24J40 in sleep mode\r\n");
								c("Reset the device to get out of sleep mode\r\n");
                            }
                            
                            RC1 = 0;
                            TRISC1 = 0;
                            
                            PHYSetShortRAMAddr(WRITE_RFCTL,0x00);
                            
                            PHYSetShortRAMAddr(WRITE_TXBCNINTL,0x80);
                            PHYSetShortRAMAddr(WRITE_RXFLUSH,0b01100000);
                            PHYSetShortRAMAddr(WRITE_SLPACK,0x80);
                            break;
                        
                        case 'c':
                        case 'C':
                            if(PrintMenus)
                            {
                                c("MRF24J40 in reset mode\r\n");
                            }
                            
                            PHY_RESETn = 0;
                                
                            break;
                        
                        case 'd':
                        case 'D':
                            if(PrintMenus)
                            {
								nl();
                                c("Placing controller in sleep\r\n");
                                c("Reset the device to get out of sleep mode\r\n");
                            }
                            {
                                unsigned int i;
                                
                                for(i=0;i<60000;i++)
                                {
                                    Nop();
                                }

⌨️ 快捷键说明

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