I've a task for my self. I need to read a stream of serial data and when a special/unique number of charaters are present - lets say turn on a led.
Eg. 00 0D 45 56 78 = LED ON
Can that be done?
The serial stream is 9600 baud
Do I need to use interrupt (input on B0 on a 18f452)
Rgds
Jesper
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
Serial Stream
Posted: Mon Dec 29, 2003 3:14 pm
Yes, it can be done very easily. You can use the UART or bit bang in software as you choose. For a simple application like this either should work.
As the characters come in (I assume you know what the first char of the desired string is) compare each char to one you define as the start char. Once you see it set a start_char_seeen flag then compare each succeeding char until you complete the desired sequence. If you get a mismatch in the middle of the sequence you reset the start_char_seen flag and then sit and wait for the begining char to show again.
There are several examples of receive routines in the CCS examples you can use for getting started. Search on the word "queue" in this forum for a lot of good info as well.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum