I'm trying to work with a PIC16F818 to program and operate microchip's MRF49XA transceiver. I've read most of the datasheet and wanted to see some code examples to fill games in my understanding, but it appears microchip only offers a C code example. I only know assembly, so this presents a problem.
Can someone help me understand these lines of code?
The nCS =0/1 I get, but is it calling a function called SPI write? What does (setting>>8) mean?
The if statement above: I'm pretty much lost. What is going on in that IF statement? I'm understanding that the else statement tells it to set those variables (SPI_SDO) to 0 if the above condition isn't met, but what the heck is happening in that "for" loop?
What does the (GENCREG | 0x0040) mean? Why do some names have hex behind them while others dont? Does that mean they are 0x00? What is "RegisterSet" actually doing?
Thanks very much for the help!
Can someone help me understand these lines of code?
Rich (BB code):
void RegisterSet(WORD setting)
{
nCS = 0;
SPIWrite(setting >> 8);
SPIWrite(setting);
nCS = 1;
}
Rich (BB code):
void SPIWrite(BYTE data)
{
BYTE i;
#if defined(HARDWARE_SPI)
PIR1bits.SSP1IF = 0;
i = SSP1BUF;
SSP1BUF = data;
while(PIR1bits.SSP1IF == 0){}
#else
SPI_SDO = 0;
SPI_SCK = 0;
for(i = 0; i < 8; i++)
{
SPI_SDO = ((data & (0x80 >> i)) > 0) ? 1:0;
SPI_SCK = 1;
SPI_SCK = 0;
}
SPI_SDO = 0;
#endif
Rich (BB code):
void MRF49XAInit(void)
{
// configuring the MRF49XA radio
RFIE = 0;
RegisterSet(FIFORSTREG);
RegisterSet(FIFORSTREG | 0x0002); // enable synchron latch
RegisterSet(GENCREG);
RegisterSet(AFCCREG);
RegisterSet(CFSREG);
RegisterSet(DRVSREG);
RegisterSet(PMCREG);
RegisterSet(RXCREG);
RegisterSet(TXCREG);
// antenna tuning on startup
RegisterSet(PMCREG | 0x0020); // turn on the transmitter
delay_ms(5); // wait for oscillator to stablize
// end of antenna tuning
RegisterSet(PMCREG | 0x0080); // turn off transmitter, turn on receiver
RegisterSet(GENCREG | 0x0040); // enable the FIFO
RegisterSet(FIFORSTREG);
RegisterSet(FIFORSTREG | 0x0002); // enable synchron latch
RegisterSet(0x0000); // read status byte (read ITs)
RFIE = 1;
}
Thanks very much for the help!