http://www.picbasic.co.uk/forum/ could also be helpful.
____________
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bruce, thank you very much for your sample file.
I have tried to create an easier implementation, just to see if it is working on my circuit.
I have a TX circuit and an RX circuit, using RS485.
Below is my code. The LED on the TX is blinking, but not on the RX side.
Any idea what I am doing wrong?
<b>TX Code</b>
<hr>
<code>
Include "Modedefs.bas"
DEFINE OSC 4
DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
LEDPIN VAR PORTD.2 ' LED to confirm PIC is running
DATARECEIVED VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
ADCON1 = 7
RCIF VAR PIR1.5& nbsp; ' Alias RCIF (USART Receive Interrupt Flag)
OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag)
CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable)
Main:
HIGH DE_OR_RE ' Make ready for RX
HSEROUT ["1"] &n bsp; ' Send R1
HIGH LEDPIN
PAUSE 5000
LOW LEDPIN
PAUSE 5000
GOTO MAIN
END
</code>
<b>RX Code</b>
<hr>
<code>
Include "Modedefs.bas"
DEFINE OSC 4
DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176 (RS485)
LEDPIN VAR PORTD.2 ' LED Pin
i &nbs p; VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
ADCON1 = 7
RCIF VAR PIR1.5& nbsp; ' Alias RCIF (USART Receive Interrupt Flag)
OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag)
CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable)
LOW DE_OR_RE &n bsp; ' Make ready for RX
INTCON = %11000000   ; ' Enable interrupts
ON INTERRUPT GoTo serialin ' Declare interrupt handler routine
PIE1.5 = 1 & nbsp; ' Enable interrupt on USART
DoSomeStuff:
For i = 0 to 10
Pause 2
Next i
GOTO DoSomeStuff
serialin:   ; & nbsp;' Buffer the character received
GOSUB BLINK
RESUME
BLINK:
HIGH LEDPIN
PAUSE 1000
LOW LEDPIN
PAUSE 1000
RESUME
END
</code>
Lookup disable in your manual under ON INTERRUPT. Then lookup RETURN under GOSUB. That will get you started.
You're welcome, but you'll want to consider a few other things here too.
1. RCIF is only cleared after a read of RCREG. To clear RCIF, you will want to read this data
with HSERIN or X = RCREG until RCIF is cleared.
2. Values you use in hardware USART defines are not loaded into USART registers if there is
not at least one instance of HSERIN or HSEROUT used somewhere within your program.
Just inserting these defines is not configuring the hardware USART for you. Just FYI.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks