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
Re: Serial ring buffer and 2 pointer
Posted: Fri Jan 21, 2005 7:45 am
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.
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