Page 1 of 1

USART - testing the received data

Posted: Sat Feb 19, 2011 8:24 pm
by Dr_Zeus
Dear All,

I'm very new to flowcode and have been away from basic programming for a long time, I'm working on a simple project with my pic (877A) to supplement a measurement on an oscilloscope on a K Line interface.

I'm using the 16F877A USART to receive BYTES and process them looking for a particular BYTE value of A7, anything else that comes along I will discard. When I see 0xA7 I want the PIC to wait for approx 500mS and then toggle an output HIGH. I am lucky in that A7 comes in with 3 other BYTES all of which I believe always a particular value e.g. 10 1A A7 20

I can't decide how to handle the data and sift through it, I have considered defining a string variable to receive the 4 BYTES, converting it to an Integer and subtracting it from static variable. If the result is zero then I know the sequence of BYTES contains the one I'm looking for and then I can proceed as required, if the result is not zero then I continue looking.

If I try this how do I ensure I don't miss any BYTES on the "line" while I'm performing the calculation?

Is there a better way of performing the function?

Thank you

Carl :)

Re: USART - testing the received data

Posted: Mon Feb 21, 2011 12:49 pm
by Benj
Hello Carl,

The best way to do this would be a byte at a time so you don't miss any of the bytes. If you are doing a comparison of 4 bytes at a time then you have a 1 in 4 chance of starting on a wrong byte. If your using the UART hardware (RS232 component in hardware mode) then there shouldn't be any chance of missing data.

Re: USART - testing the received data

Posted: Wed Feb 23, 2011 9:47 am
by Dr_Zeus
Many thanks Ben

Carl