rikaine
- 2nd May 2014, 08:49
Hello everyone,
This is my first post here. I would appreciate if you could show my mistakes.
I am trying to form a serial communication between 2 PICs: 18F4620 (Let's call this one A) and 10F202 (B)
18F4620(A) | 10F202 (B)
------------------------
AN0 -------|------ GP0
AN1 -------|------ GP1
PIC A has an LCD attached to it, so I can check what is going on, no such thing on B.
What I am trying to do is send data from A to B, then receive it back: First A -> B then B -> A
For test purposes I sent data from B to A and confirmed it is working.
Here is my code for A (18F4620)
include "modedefs.bas"
TRISA = 0 'Set PORTA to all outputs - NOT SURE IF THESE ARE REQUIRED
TRISB = 0 'Set PORTB to all outputs
DEFINE OSC 20
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
RW var portb.1:output portb.1:rw=0 ' LCD RW
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
Pause 1000
DEFINE HSER_BAUD 9600
ADCON1 = 15 ' ANALOGS to DIGITAL
SI VAR PORTA.0:input PORTA.0
SO VAR PORTA.1:output PORTA.1
GG VAR WORD:GG=18
TT var byte:TT=4
lcdout $FE,130,"SEROUT:[",#gg,"]"
SERout rout,N9600,[gg]
SERIN SI,1000,loop,N9600,tt
lcdout $FE,214,"SERIN:[",#tt,"]"
end
My code for B (10F202)
include "modedefs.bas"
TRISA = 0 'Set PORTA to all outputs ' Are these necessary?
TRISB = 0 'Set PORTB to all outputs
DEFINE OSC 4
ADCON1 = 7 ' ANALOGS to DIGITAL ?
ROUT var GPIO.0:output GPIO.0
RIN VAR GPIO.1:INPUT GPIO.1
RR var word
SERIN rin,N9600,rr
pause 1000
SERout rout,N9600,[rr]
END
I am quite new to PicBasic Pro, just put together some stuff I found but it is not working. I tried the above with loops as well, but since SERIN waits there till it receives something it looks fine to me this way.
Thanks in advance
This is my first post here. I would appreciate if you could show my mistakes.
I am trying to form a serial communication between 2 PICs: 18F4620 (Let's call this one A) and 10F202 (B)
18F4620(A) | 10F202 (B)
------------------------
AN0 -------|------ GP0
AN1 -------|------ GP1
PIC A has an LCD attached to it, so I can check what is going on, no such thing on B.
What I am trying to do is send data from A to B, then receive it back: First A -> B then B -> A
For test purposes I sent data from B to A and confirmed it is working.
Here is my code for A (18F4620)
include "modedefs.bas"
TRISA = 0 'Set PORTA to all outputs - NOT SURE IF THESE ARE REQUIRED
TRISB = 0 'Set PORTB to all outputs
DEFINE OSC 20
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
RW var portb.1:output portb.1:rw=0 ' LCD RW
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
Pause 1000
DEFINE HSER_BAUD 9600
ADCON1 = 15 ' ANALOGS to DIGITAL
SI VAR PORTA.0:input PORTA.0
SO VAR PORTA.1:output PORTA.1
GG VAR WORD:GG=18
TT var byte:TT=4
lcdout $FE,130,"SEROUT:[",#gg,"]"
SERout rout,N9600,[gg]
SERIN SI,1000,loop,N9600,tt
lcdout $FE,214,"SERIN:[",#tt,"]"
end
My code for B (10F202)
include "modedefs.bas"
TRISA = 0 'Set PORTA to all outputs ' Are these necessary?
TRISB = 0 'Set PORTB to all outputs
DEFINE OSC 4
ADCON1 = 7 ' ANALOGS to DIGITAL ?
ROUT var GPIO.0:output GPIO.0
RIN VAR GPIO.1:INPUT GPIO.1
RR var word
SERIN rin,N9600,rr
pause 1000
SERout rout,N9600,[rr]
END
I am quite new to PicBasic Pro, just put together some stuff I found but it is not working. I tried the above with loops as well, but since SERIN waits there till it receives something it looks fine to me this way.
Thanks in advance