📄 basicdriver_signal_strength.c
字号:
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();
}
Sleep();
}
break;
case 'e':
case 'E':
if(PrintMenus)
{
c("Waking up the MRF24J40\r\n");
}
RC1 = 1;
break;
default:
if( PrintMenus )
{
c("Incorrect Menu Choice: ");
ConsolePut(input);
nl(); nl();
}
goto MRF24J40_Low_Power_submenu;
}
break;
case 'e':
case 'E':
{
BYTE currentChannel = 0;
BYTE i, j;
WORD k;
BYTE maxRSSI;
c("Please wait!\r\n");
c("Spectral energy values will be displayed for each channel in RSSI units:\r\n");
nl(); nl();
for(i = currentChannel; i <= 15; i++)
{
BYTE RSSIcheck;
BYTE r[2] = {0x54, 0x00};
maxRSSI = 0;
// set channel
j = i << 4;
SetChannel(j);
for(k = 0; k < 0xFFF; k++);
for(j = 0; j < 200; j++)
{
// set RSSI request
PHYSetShortRAMAddr(WRITE_BBREG6, 0x80);
// check RSSI
RSSIcheck = PHYGetShortRAMAddr(READ_BBREG6);
while((RSSIcheck & 0x01) != 0x01 || (RSSIcheck & 0x80))
{
RSSIcheck = PHYGetShortRAMAddr(READ_BBREG6);
}
RSSIcheck = PHYGetLongRAMAddr(0x210);
if( RSSIcheck > maxRSSI )
{
maxRSSI = RSSIcheck;
}
for(k = 0; k < 0xFFF; k++);
}
ConsolePutROMString((ROM char *)"Channel ");
if(i>=9)
{
ConsolePut('2');
}
else
{
ConsolePut('1');
}
{
unsigned a;
a = 0x30 + ((i+1)%10);
ConsolePut(a);
}
//PrintChar(i+11);
ConsolePutROMString((ROM char *)": ");
j = maxRSSI/5;
for(k = 0; k < j; k++)
{
ConsolePut('-');
}
c(" ");
PrintChar(maxRSSI);
ConsolePutROMString((ROM char *)"\r\n");
}
c("Press any key to return to the main menu\r\n");
while(!ConsoleIsGetReady()){}
input = ConsoleGet();
goto MRF24J40_SubMenu;
}
break;
case 'f':
case 'F':
if(PrintMenus)
{
c("Running in CW mode\r\n");
c("Reset board to return to the main menu\r\n");
nl();
}
PHYSetLongRAMAddr(0x000, 22); /* packet header length */
PHYSetLongRAMAddr(0x001, 23); /* total packet length (not including the FCS/CRC or length) */
PHYSetLongRAMAddr(0x002, 0b01100001); /* first byte of packet (the LSB of the frame control p112 of IEEE 802.15.4-2003) -- Data packet, no security, no frame pending, ACK requested, intra-pan transmission */
PHYSetLongRAMAddr(0x003, 0xCC); /* first byte of packet (the MSB of the frame control p112 of IEEE 802.15.4-2003), use long addresses for both cases */
PHYSetLongRAMAddr(0x004, 0x01); /* IEEE sequence number */
PHYSetLongRAMAddr(0x005, 0xFF); /* PANID - broadcast */
PHYSetLongRAMAddr(0x006, 0xFF); /* PANID - broadcast */
PHYSetLongRAMAddr(0x007, 0x01); /* Dest Address LSB */
PHYSetLongRAMAddr(0x008, 0x23); /* Dest Address */
PHYSetLongRAMAddr(0x009, 0x45); /* Dest Address */
PHYSetLongRAMAddr(0x00a, 0x67); /* Dest Address */
PHYSetLongRAMAddr(0x00b, 0x89); /* Dest Address */
PHYSetLongRAMAddr(0x00c, 0xab); /* Dest Address */
PHYSetLongRAMAddr(0x00d, 0xcd); /* Dest Address */
PHYSetLongRAMAddr(0x00e, 0xef); /* Dest Address MSB */
PHYSetLongRAMAddr(0x00f, EUI_0); /* Source Address LSB */
PHYSetLongRAMAddr(0x010, EUI_1); /* Source Address */
PHYSetLongRAMAddr(0x011, EUI_2); /* Source Address */
PHYSetLongRAMAddr(0x012, EUI_3); /* Source Address */
PHYSetLongRAMAddr(0x013, EUI_4); /* Source Address */
PHYSetLongRAMAddr(0x014, EUI_5); /* Source Address */
PHYSetLongRAMAddr(0x015, EUI_6); /* Source Address */
PHYSetLongRAMAddr(0x016, EUI_7); /* Source Address MSB */
PHYSetLongRAMAddr(0x017, 0x55); /* data byte */
PHYSetLongRAMAddr(0x018, 0xAA); /* data byte */
PHYSetShortRAMAddr(WRITE_RFCTL,0b00000010); //force transmit
while(1)
{
if(ConsoleIsGetReady())
{
if(PrintMenus)
{
goto MRF24J40_SubMenu;
}
else
{
goto MRF24J40_NewOption;
}
}
}
break;
case 'g':
case 'G':
{
BYTE currentChannel = CHANNEL_11;
c("\r\nEntering Single Tone Test Mode. Reset device to return to the main menu.");
while(1)
{
SetChannel(currentChannel);
currentChannel += 0x10;
PHYSetLongRAMAddr(RFCTRL3,0x00);
PHYSetShortRAMAddr(WRITE_RFCTL,0b00000010);
PHYSetLongRAMAddr(TESTMODE,0x0d);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
break;
case 'h':
case 'H':
{
BYTE currentChannel = CHANNEL_11;
c("\r\nEntering Sequential Transmit Mode. Reset device to return to the main menu.");
while(1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -