PDA

View Full Version : Accurate serin usage?



sccoupe
- 7th July 2009, 16:56
I have a project running with a 12f675 that ive been working on for a while using an rs232 input. My problem is that it isnt totally reliable, close, but not perfect. I have a 4 digit string coming through rs232 and accept this data via the code below...



serin 3,2,digit1
serin 3,2,digit2
serin 3,2,digit3
serin 3,2,digit4


To make sure that I am getting a value that isnt corrupted, I try to check everthing in a range and go back to main to get more serial data if it doesnt look right with the following code...



check3:
if digit1 = 48 then goto main
if digit1 = 46 then goto main
if digit4 = 46 then goto main
if digit1 < 46 then goto main
if digit1 > 57 then goto main
if digit2 < 46 then goto main
if digit2 > 57 then goto main
if digit3 < 46 then goto main
if digit3 > 57 then goto main
if digit4 < 46 then goto main
if digit4 > 57 then goto main
if digit1 = 47 then goto main
if digit2 = 47 then goto main
if digit3 = 47 then goto main
if digit4 = 47 then goto main
return


Often, the display keeps old data that is behind the rs232 stream by a few seconds, im sure because it isnt seeing what it likes and continues to loop thought the serin's until it gets something that it see's as appropriate. Is there a better way to do this?

Thanks

EarlyBird2
- 10th July 2009, 08:36
Is the decimal point always in the same place in your data?

What I do is to trap a known character in a known location in the data stream and then I am able to work out where in the data stream I am. If you are generating the data stream youself then you can include a start character that you trap.

Steve