📄 basicdriver_signal_strength.c
字号:
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;
}
break;
default:
break;
}
goto MRF24J40_SubMenu;
}
/*********************************************************************
* Function: void BoardInit( void )
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: Board is initialized
*
* Overview: This function configures the board for the PICDEM-z
* MRF24J40 usage
*
* Note: This routine needs to be called before the function
* to initialize MiWi stack or any other function that
* operates on the stack
********************************************************************/
void BoardInit(void)
{
#if defined(__18F4620)
// Switches S2 and S3 are on RB5 and RB4 respectively. We want interrupt-on-change
INTCON = 0x00;
// There is no external pull-up resistors on S2 and S3. We will use internal pull-ups.
// The MRF24J40 is using INT0 for interrupts
// Enable PORTB internal pullups
INTCON2 = 0x00;
INTCON3 = 0x00;
// Make PORTB as input - this is the RESET default
TRISB = 0xff;
// Set PORTC control signal direction and initial states
// disable chip select
LATC = 0xfd;
// Set the SPI module for use by Stack
TRISC = 0xD0;
// Set the SPI module
SSPSTAT = 0xC0;
SSPCON1 = 0x20;
// D1 and D2 are on RA0 and RA1 respectively, and CS of TC77 is on RA2.
// Make PORTA as digital I/O.
// The TC77 temp sensor CS is on RA2.
ADCON1 = 0x0F;
// Deselect TC77 (RA2)
LATA = 0x04;
//======================== Bing's adding parameters=======================
//======================== Bing's adding parameters=======================
//inti TRIS A
TRISA0 = 0;
TRISA1 = 0;
//SETTING THE PORT
//RA0 = 1;
LATA0 = 1;
//RA1 = 1;
LATA1 = 1;
//======================== Bing's adding parameters=======================
//======================== Bing's adding parameters=======================
// Make RA0, RA1, RA2 and RA4 as outputs.
TRISA = 0xF8;
PHY_CS = 1; //deselect the MRF24J40
PHY_CS_TRIS = 0; //make chip select an output
RFIF = 0; //clear the interrupt flag
if(RB0 == 0)
{
RFIF = 1;
}
RFIE = 1; //set interrupt enable flag
IPEN = 1;
GIEH = 1;
#else
//WDTCONbits.SWDTEN = 0; //disable WDT
OSCCON = 0b01110110;
OSCTUNE = 0b01000000;
// Switches are on RB1 to RB4 respectively. We don't want interrupt-on-change
INTCON = 0x00;
// There is no external pull-up resistors on S2 and S3. We will use internal pull-ups.
// The MRF24J40 is using INT0 for interrupts
// Enable PORTB internal pullups
INTCON2 = 0x80;
INTCON3 = 0x00;
// Make PORTB as input - this is the RESET default
TRISB = 0xff;
// Make PORTE as output - this drives LEDs
LATE = 0x00;
TRISE = 0x00;
// Set PORTC control signal direction and initial states
// disable chip select
//LATC = 0xfd;
LATD = 0b11111011;
// Set the SPI module for use by Stack
//TRISC = 0xD0;
TRISD = 0b00100000;
// Set the SPI module
SSP2STAT = 0xC0;
SSP2CON1 = 0x20;
// Deselect TC77 (RA2)
//LATA = 0x04;
//PORTA = 0x00;
//LATA = 0x00;
TRISA = 0xFF;
// D1 and D2 are on RA0 and RA1 respectively, and CS of TC77 is on RA2.
// Make PORTA as digital I/O.
// The TC77 temp sensor CS is on RA2.
//ADCON1 = 0x0F;
//ADCON0 = 0xCC;
WDTCONbits.ADSHR = 1;
ANCON0 = 0xDC;
ANCON1 = 0xFF;
WDTCONbits.ADSHR = 0;
ADCON0 = 0x05;
ADCON1 = 0xBA;
//ADCON1 = 0xB9;
//WDTCONbits.ADSHR = 0;
// Make RA0, RA1, RA2 and RA4 as outputs.
//TRISA = 0xF8;
//TRISA = 0xFF;
//DelayMs(1);
//ADCON1bits.ADCAL = 1;
//ADCON0bits.GO = 1;
//while(ADCON0bits.GO);
//ADCON1bits.ADCAL = 0;
PHY_CS = 1; //deselect the MRF24J40
PHY_CS_TRIS = 0; //make chip select an output
RFIF = 0; //clear the interrupt flag
RFIE = 1;
//RCONbits.IPEN = 1;
IPEN = 1;
INTCON2bits.INTEDG0 = 0;
GIEH = 1;
// enable LCD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -