PDA

View Full Version : Trying to learn HSERX usage



elcrcp
- 13th November 2014, 10:00
Hi guys, I didn't use serial communication before ad now I'm trying to learn basics with a simple circuit. I wandered on forums and read most of topics but can't find where my mistake is.
I'm trying to establish a serial communication between 2 16f877a. First one has switches on portb, reading then sending them via serial with hserout. Second one has leds on portb, receiving data from serial and then writing on portb.
Altough its a very simple circuit, I cannot make it work. I simulate circuit on protheus, it looks like data is transmitting from first one but can't proccess it on second I think. Can't find the problem, can you help me please? here are my codes.
Note; I commented out some lines from original code to make things simplier for trying.

Transmitter Code


TRISB=111111
TRISC=000000
TRISD=000001
define OSC 16
DEFINE HSER_RCSTA 90h '(alma yazmacının Enable edilmesi)
DEFINE HSER_TXSTA 20h '(gönderme yazmacının Enable edilmesi)
DEFINE HSER_BAUD 9600 '(Haberlesme hızının belirlenmesi)
PORTB=0
PORTC=0
PORTD=0
veri var byte
lastveri var byte
symbol bt0=PORTD.0
clear


basla:
'if bt0=0 then
veri=PORTB
'endif
'if veri!=lastveri then
' lastveri=veri
hserout [veri]
while not TXSTA.1 : WEND

'endif
goto basla
end


Receiver Code


TRISB=000000
TRISC=000000
define OSC 16
DEFINE HSER_RCSTA 90h '(alma yazmacının Enable edilmesi)
DEFINE HSER_TXSTA 20h '(gönderme yazmacının Enable edilmesi)
DEFINE HSER_BAUD 9600 '(Haberlesme hızının belirlenmesi)
PORTB=0
PORTC=0
veri1 var byte
lastveri1 var byte
clear


basla1:
hserin [veri1]
while not PIR1.5 : wend
'if veri!=lastveri then
' lastveri=veri
PORTB=veri1


'endif
goto basla1
end

elcrcp
- 13th November 2014, 11:04
I found the problem, it looks like both of transmit and receive pins must be set as inputs. Otherwise it doesn't work. Hope this helps other beginners =)