PDA

View Full Version : HSERIN and HSEROUT problems



amindzo
- 29th August 2006, 23:34
Hi,
i wrote this program to give serial information by jserin and hserout instructions.i want to send
"C" charactor and then send B0 and B1 valude and in reciver first i should get the "C" charactor
anf then get serial data and put them in B0 and B1 variables and show them on lcd.
when i turn on reciver after 1 or 2 seconds some randim numbers is shown on lcd without turning on transmitter.
could you help me with this problem?

transmitter program:
define OSC 4
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 1200
' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25
B0 var byte
B1 var byte
B0=125
B1=225
hserout ["C"]
hserout [bin B0,B1]
end

reciver program:
define OSC 4
'
'lcd defines
'

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
' Set baud rate
DEFINE HSER_BAUD 1200
' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25
n var byte
B0 var byte
B1 var byte
ArrayVar var byte
C var byte
n=1
hserin [STR ArrayVar\n\C]
hserin [bin B0,B1]
lcdout $fe,1,#B0," ",#B1
end

Dave
- 31st August 2006, 00:51
amindzo, You should use the "WAIT" qualifier in your hserin statement and then make the qualifier string something like the word "data" and then send the data bytes. Your receiver's data slicer is probably decoding noise and this noise is being interpreted by the UART as data bytes. The qualifier used in the hserin statement will WAIT for the qualifier string (in this case "data") to br received before receiving any further bytes. It's in the manual.....

Dave Purola,

Ioannis
- 31st August 2006, 06:51
Try this:

transmitter program:
define OSC 4
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 1200
' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25
B0 var byte
B1 var byte
B0=125
B1=225
hserout ["C"]
hserout [B0,B1]'<<<<<<<<<< NO BIN qualifier here!!!
end

reciver program:
define OSC 4
'
'lcd defines
'

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
' Set baud rate
DEFINE HSER_BAUD 1200
' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25
n var byte
B0 var byte
B1 var byte
ArrayVar var byte
C var byte
hserin [wait("C")]'<<<<<<<<<< Use wait
hserin [B0,B1]'<<<<<<<<<<<< No Bin here!
lcdout $fe,1,$80,bin B0,$fe,$c0 bin B1
end

Hope it helps
Ioannis