This is the best I can come up with right now for a sample program. I am using 18f452 for the receiver and the transmiter. I want the receiver to use a PBP Interupt handler so that the microcontroller can do its thing and not half to wait idle for data from the transmiter.
Transmiter code is :
DEFINE LOADER_USED 1
DEFINE OSC 4
DEFINE HSER_RCSTA 90h ' enable serial port,
' enable continuous receive
'
define HSER_TXSTA 24h ' enable transmit,
' BRGH=1
'
define HSER_SPBRG 103 ' set baudrate to 2400
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
TrisB.0 = 0
Counter Var word
DataIn Var Word
DataOut Var Word
Dataout = 10
Counter = 0
DataIn = 0
Loop:
PortB.0 = 1 'Led on
hserout [DataOut] 'Serial Out PortC.6 Once every 5 seconds
pause 3000
PortB.0 = 0 'Led Off
pause 2000
GoTo Loop
The Reciever code is:
DEFINE LOADER_USED 1
DEFINE OSC 4
DEFINE HSER_RCSTA 90h ' enable serial port,
' enable continuous receive
'
define HSER_TXSTA 24h ' enable transmit,
' BRGH=1
define HSER_SPBRG 103 ' set baudrate to 2400
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
TrisB.0 = 0
Counter Var word
DataIn Var Word
Counter = 0
DataIn = 0
on interrupt goto Reader
'For Visual purposes to simulate doing something.
'Flashing an LED on for half sec off for half sec.
Main_Program:
Counter = 0
PortB.0 = 1
While Counter < 500
Counter = Counter + 1
Pause 1
wend
Counter = 0
PortB.0 = 0
While Counter < 500
Counter = Counter + 1
Pause 1
wend
GoTo Main_program
disable ' Disable interrupts
Reader:
rcsta.4 = 0 ' Clears Rx register overrun error,sets SREN off
rcsta.4 = 1 ' Sets SREN on
hserin [DataIn] 'PortC.7 serial In
Serout PortB.1,6,[12,#DataIn] 'Display data on LCD
pause 1000 'This pause should give a noticable
'diference in Led flashing
Serout PortB.1,6,[12] 'Clear LCD Display
resume ' Leave interrupt routine
enable
Everything seems to be working except the reciever module never goes into the interupt routine. Also the Transmiter TX line seems to be always high. I came up with this test code from the PBP manual and many post here.
Bookmarks