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 port buffering and 16x2 LCD display

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



Joined: 17 Apr 2010
Posts: 43

View user's profile Send private message

Serial port buffering and 16x2 LCD display
PostPosted: Sat Apr 17, 2010 4:25 pm     Reply with quote

Hi!

I'm facing a simple problem that is giving my a LOT of doubts:

I'm using a 16F688 and it's UART to control a simple device which is accepting text commands (the openLog from Sp***fun, not sure if I can write the full name of the company).

The serial is configured as:
Code:
#use rs232(uart1,baud=9600,stream=sdcard,ERRORS,PARITY=N,BITS=8,STOP=1)

And I'm using simple fputc and fprintf functions to write to the device:
Code:
fprintf(sdcard,"size test.txt");
fputc(0x0D,sdcard);

Now the tricky part: I've attached to the PIC a simple 16x2 LCD, controlled by the LCD.C standard library by CCS - it's for debugging, but will stay there in the final project because it's proving to be really usefull.

To receive chars I use:
Code:
#use delay(clock=8000000)
#int_RDA
void  RDA_isr(void)
{
   ch=getch(); // take the char
   if (ch<0x20) ch=" "; // substitute any non printable char with a space
   
   if (ch=='>') {printf(lcd_putc,"\f%c",ch);i=0;} // the prompt signal
                                                                     // clear LCD
   else printf(lcd_putc,"%c",ch); // just a char, put it on the display
   
   i++;
   if (i==16) {
                   lcd_gotoxy(1,2); // 1st row has ended, go to 2nd line
                  }
   
   if (i==32) { // 2nd row full
                  delay_ms(1000); // wait for user to read the display
                  i=0; // reset the counter
                  printf(lcd_putc,"\f"); // clear the disply
             }
  }

The module is outputting a ">" to indicate the prompt, so when parsing the incoming stream as I found it I reset the display; otherwise I put the character on the display taking care of going to the second row at the 16th char OR clearing the display when 32th char is being displayed (plus s delay to allow the reading of the display 2 rows at a time). As extra features at the beginning I substitute with a "space" any non printable char.

..the bottom line is this procedure is terrible! I really don't like it!

_ a delay inside an INT is a (really) wrong thing to do
_ printfs are raising warnings inside an interrupt (other delays from the library)
_ it works.. but don't ask how well..

I was wondering what would be a better approach to solve the problem. I'd like to find the correct way to implement the LCD as a dump device to display system messages (well, I'm not going to display the data being stored on the device) running of the RS232, but detached from the main loop operations; I cannot use the main loop to control the display and delay. I need the main to parse the data in the stream, issue command, wait for buttons, and so on.

Any suggestion on the architecture? (I was thinking about buffering before displaying).

Thanks ;)
_________________
Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Apr 17, 2010 5:44 pm     Reply with quote

Never do printf in an isr. This must have been pointed out a thousand times already.
Rs232 is asynchronous you can't hold it hostage to printf delays.
Use a circular buffer...This is important use a circular buffer.
The buffer will capture an incoming char that is all. Again that is all you should do except set a flag or pointer to indicate to your main routine that there is data. Do your printf in the main routine only.
foxOnTheRun



Joined: 17 Apr 2010
Posts: 43

View user's profile Send private message

PostPosted: Sun Apr 18, 2010 3:34 am     Reply with quote

Yes, I knew about printfs and INT issues because they contain delays and the LCD is a slow device.

I was already playing with buffers, the only problem is to deal with limited space (can only play with a char[80] and then?) and giving time to the user to actually read the LCD display; where do I put the data while the user is reading?

Am I obliged to upgrade the PIC that I'm using for this small project?

I see the 16F688 has 256 bytes of RAM, how can I access almost all of them? maybe allocating them using plain arrays in not an efficient way?
_________________
Listen, why don't you relax? Take a pill, bake a cake or go and read the encyclopedia.
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