Good day Picers
Where can I get a simple explanation or sample how "On Interrupt" works with Serial communication (HSERIN / HSEROUT)?
Good day Picers
Where can I get a simple explanation or sample how "On Interrupt" works with Serial communication (HSERIN / HSEROUT)?
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.
Bookmarks