Go Down

Topic: The Muti-tasking Arduino (Read 7931 times) previous topic - next topic

Delta_G

Here, I banged this out real quick as a modification of the one in the post above.  It compiles, but is totally untested as I don't have an LCD set up right now to test it.  I think it should work, or at least get close.  Test it out and let me know what happens.  It implements a 64 byte circular buffer to hold the data and drives the data out using the SPI_STC (serial transfer complete) interrupt to load the next character out of the buffer if there is one or turn the transmission off when the buffer is full.  It should run "in the background" rather nicely.  

The only drawback is that if you want to send any commands to the LCD, like changing the cursor position, then it has to block until the buffer is empty before it can send it.  Otherwise it would send the cursor change in the middle of the last word you tried to print and it wouldn't look right.  In order to queue the commands in with the data you'd have to have some way of marking the bytes in the buffer whether they were commands or data bytes and I haven't figured out a good way to do that without having to use more memory.  I thought about restricting the data to the 127 regular ascii characters which gives me bit 7 unused and use it to mark them, but the commands themselves still need 8 bits so I can't squeeze the marker into that.  

Either way you're welcome to try it and play with it.  I make no guarantees.  I just banged this out real quick in Eclipse.  It's written as .h and .cpp files because I'm writing in Eclipse.  You should be able to create a new sketch in Arduino and copy all four files into the same folder with it.  Then you can have as the ONLY line in the .ino

Code: [Select]
#include "Example.h"

Nothing else goes in the .ino because setup and loop and all that are defined in Example.cpp

If you get it working you can remove the Example.h and Example.cpp files and make a proper library out of it.  



|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

BTW:  The answer to the blocking command issue lies in letting commands take up two bytes each in the buffer.  One marks that the next byte is a command and the next is the command itself.  This restricts things a little though as we have to give up at least one non-printable character to serve as the marker, 0x00 or 0xFF maybe.  Will that affect creating custom characters?  Should that be done in a blocking fashion before the real program starts? 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up