📄 basicdriver_1.c
字号:
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)
{
BYTE i;
WORD j;
SetChannel(currentChannel);
currentChannel += 0x10;
PHYSetLongRAMAddr(RFCTRL3,0x00);
PHYSetShortRAMAddr(WRITE_RXMCR, 0b00100001); //promiscuous mode (no address filtering) [bit 0], never send ACKs [bit 5]
GIEH = 1;
PHYSetLongRAMAddr(0x000, 12); /* packet header length */
PHYSetLongRAMAddr(0x001, 16); /* total packet length (not including the FCS/CRC or length) */
PHYSetLongRAMAddr(0x002, 0x00); /* data byte */
PHYSetLongRAMAddr(0x003, 0x01); /* data byte */
PHYSetLongRAMAddr(0x004, 0x02); /* data byte */
PHYSetLongRAMAddr(0x005, 0x03); /* data byte */
PHYSetLongRAMAddr(0x006, 0x04); /* data byte */
PHYSetLongRAMAddr(0x007, 0x05); /* data byte */
PHYSetLongRAMAddr(0x008, 0x06); /* data byte */
PHYSetLongRAMAddr(0x009, 0x07); /* data byte */
PHYSetLongRAMAddr(0x00a, 0x08); /* data byte */
PHYSetLongRAMAddr(0x00b, 0x09); /* data byte */
PHYSetLongRAMAddr(0x00c, 0x0a); /* data byte */
PHYSetLongRAMAddr(0x00d, 0x0b); /* data byte */
PHYSetLongRAMAddr(0x00e, 0x0c); /* data byte */
PHYSetLongRAMAddr(0x00f, 0x0d); /* data byte */
PHYSetLongRAMAddr(0x010, 0x0e); /* data byte */
PHYSetLongRAMAddr(0x011, 0x0f); /* data byte */
for (i=0;i<400;i++)
{
PHYSetShortRAMAddr(WRITE_TXNMTRIG,0b00000001);
for(j = 0; j < 5000; j++) ;
}
}
}
break;
case 'i':
case 'I':
{
BYTE i;
PHYSetLongRAMAddr(0x000,sizeof(PERCommand));
PHYSetLongRAMAddr(0x001,sizeof(PERCommand));
for(i=2;i<(sizeof(PERCommand)+2);i++)
{
PHYSetLongRAMAddr(i, PERCommand[i-2]);
}
if(UseExternal)
{
PHYSetShortRAMAddr(WRITE_GPIO, 0b00000011); //TX
Delay100TCYx(4);
c("Using external PA\r\n");
}
GIEH = 1; //enable interrupts
PHYSetShortRAMAddr(WRITE_TXNMTRIG,0b00000001);
numPacketsRx.Val = 0;
if(UseExternal)
{
PHYSetShortRAMAddr(WRITE_GPIO, 0b00001100);
Delay100TCYx(4);
c("Using external LNA\r\n");
}
numPacketsRx.Val = 0;
while(1)
{
WORD k;
if( RB0 == 0 )
{
INT0IF = 1;
}
for(k = 0; k < 50; k++) {}
#if defined(__18F67J11)
sprintf(buf, (far const rom char*)"%d packets received\r", numPacketsRx.word.LW);
for(i = 0; i < 32; i++)
{
if( buf[i] == 0x00 )
{
break;
}
ConsolePut(buf[i]);
}
#else
printf((far const rom char*)"%d packets received\r",numPacketsRx.word.LW);
#endif
if(ConsoleIsGetReady())
{
ConsoleGet();
break;
}
}
GIEH = 0; //enable interrupts
//print results
#if defined(__18F67J11)
sprintf(buf, (far const rom char*)"%d packets received\r\n", numPacketsRx.word.LW);
for(i = 0; i < 32; i++)
{
if( buf[i] == 0x00 )
{
break;
}
ConsolePut(buf[i]);
}
#else
printf((far const rom char*)"%d packets received\r\n",numPacketsRx.word.LW);
#endif
}
break;
case 'z':
case 'Z':
{
BYTE i,data;
c("-- Short RAM Addresses\r\nAddress\tValue\r\n");
for(i=0x00;i<=0x3F;i++)
{
data = PHYGetShortRAMAddr(i<<1);
c("Register 0x");
PrintChar(i);
c(":\t");
PrintChar(data);
c("\r\n");
if( (i & 0x0F) == 0x0F )
{
c("Press Any Key to Continue>>");
ConsoleInput();
}
}
c("\r\n-- Long RAM Addresses\r\nAddress\tValue\r\n");
for(i=0x00;i<=0x4C;i++)
{
data = PHYGetLongRAMAddr(0x200+i);
c("Register 0x2");
PrintChar(i);
c(":\t");
PrintChar(data);
c("\r\n");
if( (i & 0x0F) == 0x0F )
{
c("Press Any Key to Continue>>");
ConsoleInput();
}
}
c("\r\n");
}
goto MRF24J40_SubMenu;
break;
default:
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -