I hate to do this given the amount of serial questions/answers out there, but I've been spinning my wheels and I could use a little help.
I'm trying to send serial data from a Visual Basic program on my PC to my PIC. The data is in words, so I split it into high and low bytes.
For illustrative purposes, I'm currently sending the values directly. In this case, I'm sending a decimal 258 which is b00000001 in the high byte and 00000010 in the low byte.
My problem is with the PIC end I think. To visualize the actual values of the received data, I have an LED blink the value of the number. When I count the blinks, I get the high byte OK (in this case the LED blinks once) but I end up with double the low byte (4 blinks). Now I realize that this is simply a bit shift left of the low byte, but why is it happening, and why only on the second value?
Here's the PIC code with the unimportant stuff removed. Oh, and I'm using a 16F628A with internal oscillator.
Code:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
define OSC 4
Baud CON 19697 ' 300 baud, inverted, N,8,1
LED4 var PORTB.3
serialData VAR byte
serialHigh VAR byte
serialLow VAR byte
MAIN:
'------------------------------
'Check for setup mode
'------------------------------
SERin2 PROG,Baud,100,START,[wait(253)] 'wait 100ms see a 255
goto Program_Mode
START:
'Do normal program stuff
goto MAIN
Program_mode:
SERin2 PROG,Baud,200,START,[wait(253) ] 'wait for the second of two 253s to start transmission
'------------------------------------------------------------
'Here is where the values are read in
'------------------------------------------------------------
SERin2 PROG,Baud,100,START,[serialHigh]
tempword.Highbyte = serialHigh
SERin2 PROG,Baud,100,START,[serialLow ]
tempword.Lowbyte = serialLow
'------------------------------------------------------------
'Here is where the values are blinked out
'------------------------------------------------------------
if serialHigh = 0 then gohere
for i = 1 to serialHigh
high led4
pause 20
low led4
pause 400
next i
pause 1000
gohere:
for i = 1 to serialLow
high led4
pause 20
low led4
pause 400
next i
goto main
Can anyone help? Since it appears to be a bit operation, it seems it must have something to do with stop bits or the way the PIC is receiving the data. I just don't know.
Oh, and there's been mention of a "binary mode" and "character mode" for serial communications... is there truly such a thing, and could this be part of my problem? Could I be receiving 7 bits instead of 8? I couldn't find any reference to these "modes" in the PBP manual.
Thanks in advance for your help.
-Jeff
Bookmarks