CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Serial ring buffer and 2 pointer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
y



Joined: 29 Dec 2003
Posts: 3

View user's profile Send private message

Serial ring buffer and 2 pointer
PostPosted: Fri Jan 21, 2005 7:13 am     Reply with quote

Hi all

I need to have some code that reads whatever data there is on the serial input and looks for a unique number of charters.

I've learned that it has to be a ring buffer and with 2 pointer (one for placing the data in the buffer and one for reading the data)

Lets say I want to have a LED turned ON when 'LED' is read - how is it done?

ISR for data on serial port - place data in buffer,- but also a ISR for 'LED' search?

Hope for some good inputs/code!

Rgds

Jesper
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Serial ring buffer and 2 pointer
PostPosted: Fri Jan 21, 2005 7:45 am     Reply with quote

y wrote:
Hi all

I need to have some code that reads whatever data there is on the serial input and looks for a unique number of charters.

I've learned that it has to be a ring buffer and with 2 pointer (one for placing the data in the buffer and one for reading the data)
Simple enough. Plenty of examples have been posted here.

Quote:

Lets say I want to have a LED turned ON when 'LED' is read - how is it done?

Don't understand what you are saying. Are you saying that when you receive the characters 'L' 'E' 'D' that you want to turn on an LED? If that is the case, then you will be searching through the string looking for the characters. There are standard C functions for this (strcmp) or you could just look for an 'L' then see if the next character is an 'E' and so on.

Quote:

ISR for data on serial port - place data in buffer,- but also a ISR for 'LED' search?

You are going to use an ISR for the LED search. You could use a timer and search every so often but that's kind of silly. No I am going to assume that you are connecting to a PC and someone is typing in commands. This is what I would do. The user must use the 'ENTER' key to start a command. The PIC would use a ring buffer to receive data. The PIC will also "echo" the data back to the user. This lets the user know the data is being received. In the main loop, there is an array of say 80 bytes long (remember those 80 column terminals!). This would be the maximum length of a command. Data is read from the ring buffer and placed into the command_buffer. If the data is the carriage return (Enter) then the string is parsed for the command which in your case is "LED" and the proper action is taken. The command_buffer index is reset and the process continues.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group