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

printF issue

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



Joined: 26 Dec 2010
Posts: 4
Location: Connecticut

View user's profile Send private message Visit poster's website

printF issue
PostPosted: Sun Jan 23, 2011 10:58 am     Reply with quote

At the end of the mail is my code,

I am using and LCD and am connect through TTL level RS232 and am having an issue with the printF function. I have 3 methods to send a data line to the LCD. The line I am sending is in a very large font (1/2 the LCD height) at the top of the LCD.

If I use method 1 (ShowNoReading1()). This works but if sent repetitively the LCD display corrupts intermittently. I assume this is because I am not monitoring any handshaking and I am over running the input buffer of the LCD. This could be because the large font takes time to paint to the graphic LCD.

So to start to implement monitoring the buffer near overrun character from the LCD, I changed to method 2 (ShowNoReading2()). This uses LCDSendString() to send the characters one at a time and allow me to count how many times I get the handshaking character from the LCD to stop sending data. This works and the display shows data, though I have not implemented check the handshaking character, only counting any character sent from the LCD

I then figured out I would be actually sending formated numerical data so I changed to method 3 (ShowNoReading3()). This was to use printf to format string data and later formated numerical data. Now what I get is whatever data exists in LCD_Out_Buffer before the printf is executed. So it appears that the printf is not writing any data to LCD_Out_Buffer.

I have had this type of issue before and I think it may be from a misunderstanding I have about string manipulation rules. Can someone steer me to the proper method to use printf to format data into a string for single character transmission so I can check for the handshaking between characters?

Thanks,

Brandon
Code:

#use rs232(STREAM=LCD_LINK, baud=19200,parity=N, bits=8, stop=1, Errors, UART2)

int       LCD_Out_Count;                             //Number of Characters in LCD_Out_Buffer
char      LCD_Out_Buffer[40];                        //LCD Output Character Buffer
int       P_LCD_Buffer_Limit_Hit_Count;              //LCD Input Buffer Limit Hit Count

void  LCDSendString(void)
{
  int iI;
  char CH;
  If (LCD_Out_Count>0){
    For (iI=0;iI<=LCD_Out_Count-1;++iI){
      //Check for LCD Response Character
        If (kbhit(LCD_LINK)){
          //Read Character
            CH = fgetc(LCD_LINK); 
            P_LCD_Buffer_Limit_Hit_Count++;
        }//If (kbhit(LCD_LINK))       
      fPutC(LCD_Out_Buffer[iI],LCD_LINK);
      Delay_ms(LCD_CHAR_DELAY_MS);
    }//For
  }//If (LCD_Out_Count>0)
}//LCDSendString

void  ShowNoReading1(void)
{
  //Set Large Font
    LCDSetFont(LCD_LARGE_FONT);
  //Set Position 
    LCDSetPosition(READING_COL,READING_ROW);
    printf (LCD_LINK, "      -----    ");
}//ShowNoReading2

void  ShowNoReading2(void)
{
  //Set Large Font
    LCDSetFont(LCD_LARGE_FONT);
  //Set Position 
    LCDSetPosition(READING_COL,READING_ROW);
  //Output 
    strcpy(LCD_Out_Buffer,"      -----    ");
    LCD_Out_Count=15;
    LCDSendString();
}//ShowNoReading2

void  ShowNoReading3(void)
{
  //Set Large Font
    LCDSetFont(LCD_LARGE_FONT);
  //Set Position 
    LCDSetPosition(READING_COL,READING_ROW);
    printf (LCD_Out_Buffer, "      -----    ");
    LCD_Out_Count=15;
    LCDSendString();
}//ShowNoReading3
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 12:23 pm     Reply with quote

You should post the make/model of the serial LCD you're using.
Sounds like a 'timing' issue...
Perhaps it can't accept data,continuously at 19,200 baud?
I'd hope in it's datasheet it would say something about 'handshaking' protocol(xon/xoff, hardware,max speed)

If it worked for simple 'hello world' tests, at least you've got it wired up right !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 23, 2011 1:34 pm     Reply with quote

Quote:

char LCD_Out_Buffer[40];

void ShowNoReading3(void)
{
//Set Large Font
LCDSetFont(LCD_LARGE_FONT);
//Set Position
LCDSetPosition(READING_COL,READING_ROW);
printf (LCD_Out_Buffer, " ----- ");
LCD_Out_Count=15;
LCDSendString();
}//ShowNoReading3

You can't use printf to write to a buffer. Use sprintf for this.
This is in the manual.
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