|
|
View previous topic :: View next topic |
Author |
Message |
Nora
Joined: 23 Mar 2008 Posts: 50
|
Continuing...:) |
Posted: Fri Mar 04, 2011 3:37 pm |
|
|
So here's the actual code.
My questions are:
How do I know anything is transmitting since the nIRQ pin seems to be LOW all the time. But maybe it jumps HIGH too fast for me to see it? Or am I being wishful....
What should be "natural" state of nIRQ and how can I get it there?
What should come out of DO pin?
Also here are my hardware connections:
C5 is DO on PIC, DI on RFM
C4 is D1 on PIC, DO on RFM
C3 is SCLK on PIC, SCK on RFM
CO is NSEL
C1 is NIRQ
Thanks in advance
N_N
Code: | // Write preamble
// Turn on TX
// TX data transmission starts.
// When the transmission of the byte completed, the nIRQ pin goes low.
// The nIRQ pulse shows that the first 8 bits (the first byte, by default ) has transmitted. There are still 8 bits in the transmit register.
// Wait for nIRQ to pull Low
output_low(PIN_C0); // chip select
spi_write(0b10101010); // preamble
spi_write(0b10101010); // preamble
spi_write(0x2D); // Synchron pattern from power on reset FIFO and Reset Mode command
spi_write(0xD4); // Synchron pattern from power on reset FIFO and Reset Mode command
while(1)
{
if (input(PIN_C1)) //nIRQ pin goes high, then write data
{
spi_write(0b10000010); // turn on TX from Power Management register, first byte
spi_write(0b01110001); // turn on TX from Power Management register, second byte
for (i=1;i<20;i++){
output_low(Pin_A5);
delay_ms(1);
spi_write(0b11110000);
}
}
else //nIRQ pin goes low, data is finished transmitting
{
output_high(Pin_A5);
delay_ms(100);
spi_write(0b10000010); // turn off TX from Power Management register, first byte
spi_write(0b01010001); // turn off TX from Power Management register, second byte
}
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 04, 2011 9:31 pm |
|
|
Quote: | What should be "natural" state of nIRQ and how can I get it there? |
Download the data sheet:
http://www.hoperf.com/upfile/RFM12B.pdf
Look at the table of RFM12B pin descriptions on page 2.
It says:
Quote: | nIRQ DO Interrupts request output. Active low.
|
This means the idle state is 'active high'. Also, the signal name
has 'n' in front of it. This is a common notation to tell you that
it's an active low signal.
The RFM12B data sheet doesn't say it, but quite often, IRQ pins are
"open drain" and require a pull-up resistor. Just to be safe, add a
4.7K pullup resistor on the nIRQ pin. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sat Mar 05, 2011 7:10 pm |
|
|
Thanks PCM.
Added pullup and the NIRQ was still stuck in low, I sent 2 bytes of 0s into the Status Read command register which seemed to fix it.
Now the NIRQ is always high.
Are these signals (NIRQ) too fast for an oscilloscope (this one can read a 10MHz signal and no faster) to catch?
My SPI is at 9600 baud and the NIRQ is supposed to pull low after each byte. If this is 1/9600, then 100us should be fine and the scope is not catching it because.... it's not there to catch.
And this is an RFM or electrical question, but how can I tell that it's transmitting?
I don't have an RS232 set up on this board. Any advice how I can troubleshoot the actual RF signal?
Thanks in advance
N_N |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 05, 2011 7:50 pm |
|
|
To easily see a pulse on a scope, it has to repeat at a regular interval.
Write a test program that will attempt to do this. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 06, 2011 8:05 am |
|
|
Yes, have done so and no joy.
NIRQ is always high.
Code: | //******************************************************
// Test TX program.C
// Date: February 17, 2011
// get blink
// 2/17/11 test SPI function- send parameters
// 2/26/11 get LED to blink when data is transmitting
// 3/5/11 NIRQ pin is HIGH
//***********************************************************
#include <18F452.h>
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock = 20000000)
#include <stdlib.h>
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//========================================
void main()
{
int i;
output_high(PIN_C0); // chip select
delay_us(500);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
output_low(PIN_C0); // RFM12B chip select, ready to rock and roll
output_low(PIN_C0); // chip select
spi_write(0x00); // reset parameters especially NIRQ
spi_write(0x00);
output_high(PIN_C0); // chip select
//1. Configuration settting. Enable TX register, select 915 band
spi_write(0b10000000); // cmd byte
spi_write(0b10110000); // parameter byte
delay_us(100);
output_high(PIN_C0); // chip select high
delay_us(500);
output_low(PIN_C0); // chip select
//2. Power management. Enable base band block, transmitter,synthesizer, low batt detect, disable crystal output
spi_write(0b10000010); // cmd byte
spi_write(0b00100001); // parameter byte
delay_us(100);
output_high(PIN_C0); // chip select high
delay_us(500);
output_low(PIN_C0);
//3. Frequency setting. 915-900/ 0.0075 = 2000 = 0b0111 11010000
spi_write(0b10100111); // cmd byte
spi_write(0b11010000); // parameter byte
delay_us(100);
output_high(PIN_C0);
output_low(PIN_C0);
/*4. Data Rate. 9600 Baud rate to start with. TX and RX must be setup to same Baud Rate!
R[6:0] where BR = 10Mhz / 29 / (R + 1) / (1 + bit7*7)
For 9600 baud rate BR = 10Mhz / 29 / (R + 1) / (1 + 0*7) = 10000000 / 29 / (35 + 1) = 9578.5 ~ 9600 */
spi_write(0b11000110); // cmd byte
spi_write(0b00100011); // parameter byte
delay_us(100);
output_high(PIN_C0);
output_high(Pin_A5);
delay_ms(1000);
// output_low(Pin_A5);
// delay_ms(1000);
//5. Receiver control. Default power up sets Interrupt input, 200kHz baseb and bandwidth, no LNA gain, DRSSI = -103 dBm
// LNA is low noise amplifier, BB is upper end of signal, -103 dBm is super sensitive
//6. Data filter command. Default power up disable clock recovery auto-lock, Disable clock recovery fast mode, Enable Digital filter,
//Set DQD threshold default settings 4 = 0b100
/*7. FIFO and Reset Mode command this is left to default
Set FIFO interrupt level bits[7:4] to 0b1000 which is 8bit, length of the synchron pattern is 2DD4h,
FIFO fill start condition when Sync-word, Disable FIFO fill, Enable hi sensitivity reset mode by pin6 nRES.
FFIT and FFOV are applicable when the RX FIFO is enabled
RGIT and RGUR are applicable only when the TX register is enabled
To identify the source of the IT, the status bits should be read out.
(0b1100 1010/ 0b1000 0000);*/
/* 10. AFC Command this is left to default
AFC auto-mode Keeps independently from VDI, range limit +3 -4, Enable AFC hi accuracy mode, Enable AFC output register, Enable AFC funcition
(0b11000100/ 0b11110111)*/
/* 11. TX Configuration Control Command this is left to default
Modulation polarity set to 0, output power to 0dBm, and frequency deviation to 15Khz
(0b10011000/ 0b00000000) */
// 12. PLL Setting Command is left to default
// Microcontroller output clock buffer rise and fall time control set to 2.5Mhz or less,
// select low power mode of the crystal oscillator to Crystal start-up time 1ms and Power consumption 620uA
// phase detector delay disable, disables the dithering in the PLL loop,
// PLL bandwidth select to Max bit rate 256 [kbps] and Phase noise at 1MHz offset [dBc/Hz] to -102
// (0b11001100/ 0b01100111);
// 14. Wake-Up Timer Command, this is left to default: where R is set to 0b00001 which is 1 and M is set 0b10010110 which is 150
// The wake-up period is determined by: T = M * 2^R [ms], where M[7:0] and R[12:8] = 150 * 2^1 msec = 300 msec
// For continual operation, bit must be cleared and set in Power Management Command Register
// (0b11100001/ 0b10010110);
// Low Duty-Cycle Command this is left to default
// D.C.= (D * 2 +1) / M *100% where D[7:1], Disable low duty cycle mode
// (0b11001000/ 0b00001110);
// Low Battery Detector and Microcontroller Clock Divider Command this is left to default
// Select frequency of CLK pin at 1Mhz, Set threshold voltage of Low battery detector to 2.2V
// CLK signal is derive form crystal oscillator and it can be applied to MCU clock in to save a second crystal.
// If not used, please set 'dc' bit to disable CLK output
// To integrate the load capacitor internal can not only save cost, but also adjust reference frequency by software
// Set threshold voltage of Low battery detector: Vlb=2.2+V*0.1 [V] where V[3:0]
// (0b11000000/ 0b00000000);
// Write preamble
// Turn on TX
// TX data transmission starts.
// When the transmission of the byte completed, the nIRQ pin goes low.
// The nIRQ pulse shows that the first 8 bits (the first byte, by default ) has transmitted. There are still 8 bits in the transmit register.
// Wait for nIRQ to pull Low
output_low(PIN_C0); // chip select
for (i=0; i<=50; i++){
if(input(PIN_C1)) // NIRQ is high
{
output_high(PIN_A5); // LED on
spi_write(0xAA); // preamble
spi_write(0xAA); // preamble
spi_write(0x2D); // Synchron pattern from power on reset FIFO and Reset Mode command
spi_write(0xD4); // Synchron pattern from power on reset FIFO and Reset Mode command
spi_write(0x82); // turn on TX from Power Management register, first byte
spi_write(0x38); // turn on TX from Power Management register, second byte
// 13. Transmitter Register Write Command POR B8AA, so need to start every transmission with 0XB8
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xB8); // this command byte is used to write a data byte to the RF12
spi_write(0xF0); // this information should get transmitted with the previous byte
spi_write(0xAA); // preamble, clear buffer
spi_write(0xAA); // preamble, , clear buffer
spi_write(0x82); // turn off TX from Power Management register, first byte
spi_write(0x11); // turn off TX from Power Management register, second byte
}
else{
output_low(PIN_C1);
delay_ms(20000);
}
output_low(PIN_A5); // LED off
delay_ms(1000);
output_high(PIN_A5);
delay_ms(1000);
}
//}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 06, 2011 2:25 pm |
|
|
The RFM12B data sheet says this is the power supply range:
Quote: | 2.2V – 3.8V power supply
|
What voltage are you using for the RFM12B ? Is it 3.3v ?
What's the Vdd voltage on the 18F452 ? Is it 5v ?
If so, you're going to have problems with the hardware SPI interface.
The PIC requires a minimum Vih of .8 x Vdd on the SDI input pin.
So if the PIC is running at +5v, it requires 4.0v minimum for Vih.
But the RFM12B with a Vdd of +3.3v, can't do that. You would need
a level shifter, such as a 74AHCT125 between the SDO pin of the
RFM12B and the SDI pin of the PIC. Run the 74AHCT125 at +5v.
It will accept the 3.3v CMOS levels from the RFM12B and convert them
to +5v CMOS levels for the PIC.
Or you could use the "LF" version of the 18F452 and run it at +3.3v.
Then you wouldn't need a level converter.
Also, is this a real hardware project, or is it Proteus ? |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 06, 2011 3:37 pm |
|
|
Hello-
Thanks for your comments PCM Programmer!
This is a real hardware project.
I am running the RFM at 3.3V and the PIC at 5V. I had read on another forum that this was OK to do and worked fine without level shifters.
I killed one of the RFMs electrically ... it started to draw a lot of current and then stopped working. I wonder if that was why.
When I send the 0x00 command in, the RFM DO pin reads data at 3.3V.
From data sheet it looks like SDO sends MSB first?
So the path from PIC to RFM is working but not the path from RFM to PIC?
Good suggestions, I unfortunately soldered in the 40 pin PIC directly to board (no socket) so adding the HCT will be easier for prototyping.
I am still confused though about how the wireless data leaves the RFM. Is it from a pin? Is it from the antenna? Is there a way to read the data before it leaves the RFM ie: is it mirrored on the SDO or SDI line?
N_N |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 06, 2011 4:33 pm |
|
|
Search Google for this:
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 06, 2011 4:38 pm |
|
|
Quote: | I am running the RFM at 3.3V and the PIC at 5V. I had read on another forum that this was OK to do and worked fine without level shifters. |
Was it this post ?
Quote: |
Re: Level shifting - arduino to RFM12b (3.3v > 5v > 3.3v)
by Zener » Wed Sep 22, 2010 6:49 pm
However, 3.3 is usually high enough to register as a high level into 5V logic |
Bzzzt ! Wrong for PIC hardware modules.
Read the PIC data sheet:
Quote: |
22.2 DC Characteristics: PIC18FXX2 (Industrial, Extended)
PIC18LFXX2 (Industrial)
VIH Input High Voltage
D041 with Schmitt Trigger buffer, RC3 and RC4 = 0.8 x VDD |
The hardware SPI input pin (SDI) is pin C4. It requires a 4v minimum
high level (Vih) when the PIC runs at +5v Vdd. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 06, 2011 5:46 pm |
|
|
No, it wasn't that forum. Nothing to do with Arduino, was a camera forum.
Nora |
|
|
davidd
Joined: 30 Sep 2010 Posts: 38
|
|
Posted: Mon Mar 07, 2011 7:34 am |
|
|
Nora,
you should enable the wake up timer on the RFM12b, then put it to sleep.
Then see if it generates an interrupt on wake up. This is an easy way to test the modules.
I have had problems with modules not working for some reason.
Dave |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Mon Mar 07, 2011 8:52 am |
|
|
Davidd,
In what way have you had trouble with the modules not working? Electrically or software? It seems as though many people have trouble getting these to work, but the company Hope RF is selling lots of them.
Nora |
|
|
davidd
Joined: 30 Sep 2010 Posts: 38
|
|
Posted: Mon Mar 07, 2011 7:52 pm |
|
|
Nora,
I was unable to get interrupts to generate. Maybe they were somehow damaged from my experimentation, But that is a way to check the hardware and software. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Thu Mar 10, 2011 5:28 pm |
|
|
That was a good idea Dave. I can generate interrupts with the wake up timer, although it doesn't seem to actually generate at the exact time that I tell it to.
I made a circuit with 2 transistors to shift the logic level while I wait (and wait and wait) for the IC to arrive. This changes the logic on the RFM DO pin (3.3) to PIC SDI (5V). So I can see more on the DO pin.
Nora |
|
|
kgabor93
Joined: 03 May 2011 Posts: 1
|
rfm12b |
Posted: Tue May 03, 2011 11:13 am |
|
|
Hi
I'm new to these rfm12b modules and i'm trying to make them work.
I have got two PIC16f871 and a pair of the modules. I'm also new to programming, but I wrote a one in assembly. I just tried to translate the code which was in the datasheet, but it doesn't work and I can't find the mistake.
Here are my codes:
Transmitter
Code: |
MAIN CALL RFM12B
CALL FINISH
;---------------------------------------
RFM12B CALL INITPIC
CALL INITRFM12BTX
MOVLW H'FF'
MOVWF MESSAGEBYTE
IDE000001 CALL SENDPACKET
GOTO IDE000001
RETURN
;---------------------------------------
CHECKBYTE MOVLW H'FF'
SUBWF RECEIVEDBYTE,0
BTFSC STATUS,Z
GOTO IDE0001
GOTO IDE0002
IDE0001 BANKSEL PORTD
BSF PORTD,7
IDE0002 RETURN
;---------------------------------------
INITPIC
MESSAGE1 EQU 0X20
MESSAGE2 EQU 0X21
SPIBIT EQU 0X22
MEMPACKET EQU 0X23
DELAY1 EQU 0X24
MESSAGEBYTE EQU 0X25
RECEIVEDBYTE EQU 0X26
BANKSEL TRISD
BCF TRISD,2 ;MEM
BSF TRISD,3 ;NIRQ
BCF TRISD,7 ;LED
BANKSEL TRISC
BCF TRISC,4 ;NSEL
BCF TRISC,5 ;MOSI
BCF TRISC,6 ;CLOCK
BSF TRISC,7 ;MISO
BANKSEL PORTC
BSF PORTC,4
RETURN
;--------------------------------------
INITRFM12BTX BANKSEL PORTC
BSF PORTC,4
BSF PORTC,5
BCF PORTC,6
MOVLW H'80' ;1
MOVWF MESSAGE1
MOVLW H'E7'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'82' ;2
MOVWF MESSAGE1
MOVLW H'08'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'A6' ;3
MOVWF MESSAGE1
MOVLW H'40'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C6' ;4
MOVWF MESSAGE1
MOVLW H'47'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'94' ;5
MOVWF MESSAGE1
MOVLW H'C0'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C2' ;6
MOVWF MESSAGE1
MOVLW H'AC'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA' ;7
MOVWF MESSAGE1
MOVLW H'80'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C4' ;8
MOVWF MESSAGE1
MOVLW H'9B'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'98' ;9
MOVWF MESSAGE1
MOVLW H'20'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'E0' ;10
MOVWF MESSAGE1
MOVLW H'00'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C8' ;11
MOVWF MESSAGE1
MOVLW H'0E'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C0' ;12
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'CC' ;13
MOVWF MESSAGE1
MOVLW H'17'
MOVFW MESSAGE2
CALL WRITECMD
RETURN
;--------------------------------------
INITRFM12BRX BANKSEL PORTC
BSF PORTC,4
BSF PORTC,5
BCF PORTC,6
MOVLW H'80' ;1
MOVWF MESSAGE1
MOVLW H'E7'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'82' ;2
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'A6' ;3
MOVWF MESSAGE1
MOVLW H'40'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C6' ;4
MOVWF MESSAGE1
MOVLW H'47'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'94' ;5
MOVWF MESSAGE1
MOVLW H'C0'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C2' ;6
MOVWF MESSAGE1
MOVLW H'AC'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA' ;7
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CE' ;8
MOVWF MESSAGE1
MOVLW H'D4'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C4' ;9
MOVWF MESSAGE1
MOVLW H'9B'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'98' ;10
MOVWF MESSAGE1
MOVLW H'20'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CC' ;11
MOVWF MESSAGE1
MOVLW H'17'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'E0' ;12
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'C8' ;13
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'C0' ;14
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
RETURN
;--------------------------------------
SENDPACKET
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'28'
MOVWF MESSAGE2
CALL WRITECMD
CALL DELAY
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'38'
MOVWF MESSAGE2
CALL WRITECMD
NOP
NOP
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'2D'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'D4'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW D'16'
MOVWF MEMPACKET
IDE03 DECFSZ MEMPACKET,F
GOTO IDE01
GOTO IDE02
IDE01 MOVFW MESSAGEBYTE
MOVWF MESSAGE2
CALL SENDMESSAGE
GOTO IDE03
IDE02 MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'08'
MOVWF MESSAGE2
CALL WRITECMD
CALL DELAY
CALL DELAY
CALL DELAY
RETURN
;---------------------------------------
RECEIVEBYTE
BANKSEL PORTD
IDE00001 BTFSC PORTD,3
GOTO IDE00001
CALL RDFIFO
CALL FIFORESET
RETURN
;---------------------------------------
RDFIFO BANKSEL PORTC
BCF PORTC,6
BCF PORTC,5
BCF PORTC,4
MOVLW D'16'
MOVWF SPIBIT
IDE003 DECFSZ SPIBIT,F
GOTO IDE001
GOTO IDE002
IDE001 BSF PORTC,6
NOP
NOP
BCF PORTC,6
NOP
NOP
GOTO IDE003
IDE002 MOVLW D'8'
MOVWF SPIBIT
IDE009 DECFSZ SPIBIT,F
GOTO IDE004
GOTO IDE005
IDE004 BTFSS PORTC,7
GOTO IDE006
GOTO IDE007
IDE006 BCF STATUS,C
GOTO IDE008
IDE007 BSF STATUS,C
IDE008 RLF RECEIVEDBYTE,1
BSF PORTC,6
NOP
NOP
BCF PORTC,6
NOP
NOP
GOTO IDE009
IDE005 BSF PORTC,4
RETURN
;---------------------------------------
FIFORESET MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
RETURN
;---------------------------------------
SENDMESSAGE
MOVLW H'B8'
MOVWF MESSAGE1
BANKSEL PORTC
LOOP BCF PORTC,6
BCF PORTC,4
BCF PORTC,5
BSF PORTC,6
BTFSS PORTC,7
GOTO IDE111
GOTO IDE112
IDE111 BCF PORTC,6
BSF PORTC,5
BSF PORTC,4
CALL WRITECMD
GOTO IDE113
IDE112 BCF PORTC,6
BSF PORTC,5
BSF PORTC,4
GOTO LOOP
IDE113 RETURN
;---------------------------------------
DELAY MOVLW D'255'
MOVWF DELAY1
COUNTDOWN DECFSZ DELAY1,F
GOTO COUNTDOWN
RETURN
;---------------------------------------
WRITECMD
BANKSEL PORTC
BCF PORTC,6
BCF PORTC,4
MOVLW D'8'
MOVWF SPIBIT
IDE0 RLF MESSAGE1,1
BTFSS STATUS,C
GOTO IDE2
GOTO IDE1
IDE1 CALL WRITE1
GOTO IDE3
IDE2 CALL WRITE0
GOTO IDE3
IDE3 DECFSZ SPIBIT,F
GOTO IDE0
MOVLW D'8'
MOVWF SPIBIT
IDE4 RLF MESSAGE2,1
BTFSS STATUS,C
GOTO IDE6
GOTO IDE5
IDE5 CALL WRITE1
GOTO IDE7
IDE6 CALL WRITE0
GOTO IDE7
IDE7 DECFSZ SPIBIT,F
GOTO IDE4
BCF PORTC,6
BSF PORTC,4
RETURN
;--------------------------------------
WRITE1
BANKSEL PORTC
BSF PORTC,5
BCF PORTC,6
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTC,6
NOP
NOP
RETURN
;--------------------------------------
WRITE0
BANKSEL PORTC
BCF PORTC,5
BCF PORTC,6
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTC,6
NOP
NOP
RETURN
;------------------------------------------
FINISH
END |
Receiver
Code: |
MAIN CALL RFM12B
CALL FINISH
;---------------------------------------
RFM12B CALL INITPIC
CALL INITRFM12BRX
IDE000001 CALL RECEIVEBYTE
CALL CHECKBYTE
GOTO IDE000001
RETURN
;---------------------------------------
CHECKBYTE MOVLW H'FF'
SUBWF RECEIVEDBYTE,0
BTFSC STATUS,Z
GOTO IDE0001
GOTO IDE0002
IDE0001 BANKSEL PORTD
BSF PORTD,7
IDE0002 RETURN
;---------------------------------------
INITPIC
MESSAGE1 EQU 0X20
MESSAGE2 EQU 0X21
SPIBIT EQU 0X22
MEMPACKET EQU 0X23
DELAY1 EQU 0X24
MESSAGEBYTE EQU 0X25
RECEIVEDBYTE EQU 0X26
BANKSEL TRISD
BCF TRISD,2 ;MEM
BSF TRISD,3 ;NIRQ
BCF TRISD,7 ;LED
BANKSEL PORTD
BCF PORTD,7
BANKSEL TRISC
BCF TRISC,4 ;NSEL
BCF TRISC,5 ;MOSI
BCF TRISC,6 ;CLOCK
BSF TRISC,7 ;MISO
BANKSEL PORTC
BSF PORTC,4
MOVLW H'00'
MOVWF RECEIVEDBYTE
RETURN
;--------------------------------------
INITRFM12BTX BANKSEL PORTC
BSF PORTC,4
BSF PORTC,5
BCF PORTC,6
MOVLW H'80' ;1
MOVWF MESSAGE1
MOVLW H'E7'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'82' ;2
MOVWF MESSAGE1
MOVLW H'08'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'A6' ;3
MOVWF MESSAGE1
MOVLW H'40'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C6' ;4
MOVWF MESSAGE1
MOVLW H'47'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'94' ;5
MOVWF MESSAGE1
MOVLW H'C0'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C2' ;6
MOVWF MESSAGE1
MOVLW H'AC'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA' ;7
MOVWF MESSAGE1
MOVLW H'80'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C4' ;8
MOVWF MESSAGE1
MOVLW H'9B'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'98' ;9
MOVWF MESSAGE1
MOVLW H'20'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'E0' ;10
MOVWF MESSAGE1
MOVLW H'00'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C8' ;11
MOVWF MESSAGE1
MOVLW H'0E'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C0' ;12
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'CC' ;13
MOVWF MESSAGE1
MOVLW H'17'
MOVFW MESSAGE2
CALL WRITECMD
RETURN
;--------------------------------------
INITRFM12BRX BANKSEL PORTC
BSF PORTC,4
BSF PORTC,5
BCF PORTC,6
MOVLW H'80' ;1
MOVWF MESSAGE1
MOVLW H'E7'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'82' ;2
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'A6' ;3
MOVWF MESSAGE1
MOVLW H'40'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C6' ;4
MOVWF MESSAGE1
MOVLW H'47'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'94' ;5
MOVWF MESSAGE1
MOVLW H'C0'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C2' ;6
MOVWF MESSAGE1
MOVLW H'AC'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA' ;7
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CE' ;8
MOVWF MESSAGE1
MOVLW H'D4'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'C4' ;9
MOVWF MESSAGE1
MOVLW H'9B'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'98' ;10
MOVWF MESSAGE1
MOVLW H'20'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CC' ;11
MOVWF MESSAGE1
MOVLW H'17'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'E0' ;12
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'C8' ;13
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
MOVLW H'C0' ;14
MOVWF MESSAGE1
MOVLW H'00'
MOVFW MESSAGE2
CALL WRITECMD
RETURN
;--------------------------------------
SENDPACKET
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'28'
MOVWF MESSAGE2
CALL WRITECMD
CALL DELAY
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'38'
MOVWF MESSAGE2
CALL WRITECMD
NOP
NOP
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'2D'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'D4'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW D'16'
MOVWF MEMPACKET
IDE03 DECFSZ MEMPACKET,F
GOTO IDE01
GOTO IDE02
IDE01 MOVFW MESSAGEBYTE
MOVWF MESSAGE2
CALL SENDMESSAGE
GOTO IDE03
IDE02 MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'AA'
MOVWF MESSAGE2
CALL SENDMESSAGE
MOVLW H'82'
MOVWF MESSAGE1
MOVLW H'08'
MOVWF MESSAGE2
CALL WRITECMD
CALL DELAY
CALL DELAY
CALL DELAY
RETURN
;---------------------------------------
RECEIVEBYTE
BANKSEL PORTD
IDE00001 BTFSC PORTD,3
GOTO IDE00001
CALL RDFIFO
CALL FIFORESET
RETURN
;---------------------------------------
RDFIFO BANKSEL PORTC
BCF PORTC,6
BCF PORTC,5
BCF PORTC,4
MOVLW D'16'
MOVWF SPIBIT
IDE003 DECFSZ SPIBIT,F
GOTO IDE001
GOTO IDE002
IDE001 BSF PORTC,6
NOP
NOP
BCF PORTC,6
NOP
NOP
GOTO IDE003
IDE002 MOVLW D'8'
MOVWF SPIBIT
IDE009 DECFSZ SPIBIT,F
GOTO IDE004
GOTO IDE005
IDE004 BTFSS PORTC,7
GOTO IDE006
GOTO IDE007
IDE006 BCF STATUS,C
GOTO IDE008
IDE007 BSF STATUS,C
IDE008 RLF RECEIVEDBYTE,1
BSF PORTC,6
NOP
NOP
BCF PORTC,6
NOP
NOP
GOTO IDE009
IDE005 BSF PORTC,4
RETURN
;---------------------------------------
FIFORESET MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'81'
MOVWF MESSAGE2
CALL WRITECMD
MOVLW H'CA'
MOVWF MESSAGE1
MOVLW H'83'
MOVWF MESSAGE2
CALL WRITECMD
RETURN
;---------------------------------------
SENDMESSAGE
MOVLW H'B8'
MOVWF MESSAGE1
BANKSEL PORTC
LOOP BCF PORTC,6
BCF PORTC,4
BCF PORTC,5
BSF PORTC,6
BTFSS PORTC,7
GOTO IDE111
GOTO IDE112
IDE111 BCF PORTC,6
BSF PORTC,5
BSF PORTC,4
CALL WRITECMD
GOTO IDE113
IDE112 BCF PORTC,6
BSF PORTC,5
BSF PORTC,4
GOTO LOOP
IDE113 RETURN
;---------------------------------------
DELAY MOVLW D'255'
MOVWF DELAY1
COUNTDOWN DECFSZ DELAY1,F
GOTO COUNTDOWN
RETURN
;---------------------------------------
WRITECMD
BANKSEL PORTC
BCF PORTC,6
BCF PORTC,4
MOVLW D'8'
MOVWF SPIBIT
IDE0 RLF MESSAGE1,1
BTFSS STATUS,C
GOTO IDE2
GOTO IDE1
IDE1 CALL WRITE1
GOTO IDE3
IDE2 CALL WRITE0
GOTO IDE3
IDE3 DECFSZ SPIBIT,F
GOTO IDE0
MOVLW D'8'
MOVWF SPIBIT
IDE4 RLF MESSAGE2,1
BTFSS STATUS,C
GOTO IDE6
GOTO IDE5
IDE5 CALL WRITE1
GOTO IDE7
IDE6 CALL WRITE0
GOTO IDE7
IDE7 DECFSZ SPIBIT,F
GOTO IDE4
BCF PORTC,6
BSF PORTC,4
RETURN
;--------------------------------------
WRITE1
BANKSEL PORTC
BSF PORTC,5
BCF PORTC,6
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTC,6
NOP
NOP
RETURN
;--------------------------------------
WRITE0
BANKSEL PORTC
BCF PORTC,5
BCF PORTC,6
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTC,6
NOP
NOP
RETURN
;------------------------------------------
FINISH
END |
Help me please |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|