GLCD Not Displaying sprintf buffer *SOLVED*

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So here is the code....everything displays properly, except the buffer string, the GLCD shows nothing in that section

it won't let me add my code with code blocks....when i hit submit i get a bad request page

Attachment(s): 

Last Edited: Fri. May 18, 2012 - 02:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

buffer[30];

Huh?

I'd expect

char buffer[30];

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry it is char buffer[30] i just had to retype that section of code inorder to display it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The backslash is used as an escape character in literal strings for putting in things such as tab characters ("\t"). Because of this, to print a backslash you need "\\".

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

While strict reading of C99, 6.4.4.4, especially footnote 65 effectively "forbids" the \% sequence, it appears that gcc (and not only the avr- target) allows it, simply gulping the backslash (even if -std=c99 is used explicitly).

Hummm....

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kuch wrote:
everything displays properly, except the buffer string, the GLCD shows nothing in that section

sprintf(buffer, "\%d/\%d/\%02d \%d:\%02d:\%02d", Month, Day, Year, Hour, Min, Sec);

Try this:

sprintf(buffer, "%d/%d/%02d %d:%02d:%02d", Month, Day, Year, Hour, Min, Sec);

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tried what you suggested ChaunceyGardiner and got nothing....on a side note for some reason I can't quote or place code....still getting bad request error....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We don't see your "GLCD" code, which might be the culprit.

Try what happens when you do

sprintf(buffer, "12/24/12 12:22:33");

JW

PS. The forum for some security reason disallows to post sequences including the % character - there is a workaround through replacing each % by the % sequence, but you might be better off zipping up the files you want to post and add them as attachment

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How are Month, Day, Year, Hour and Min defined?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi They are all defined as char

Wek...Tried but nothing

here is the section of code that puts the strings to the GLCD

void lcd_display_char(char ch_asc, 
                        unsigned int color_front,
                        unsigned int color_background, 
                        unsigned char postion_x, 
                        unsigned char postion_y)
{
	unsigned char i, j, b;
	const unsigned char *p = 0;
	
	LCD_WRITE_COMMAND(0x08,postion_x*8); 	//x start point
	LCD_WRITE_COMMAND(0x0a,postion_y*16); 	//y start point
	LCD_WRITE_COMMAND(0x09,postion_x*8+7);	//x end point
	LCD_WRITE_COMMAND(0x0b,postion_y*16+15);	//y end point

	LCD_WRITE_COMMAND(0x06,postion_x*8);	//RAM X address(0 ~ FF, actually 0 ~ EF)	
	LCD_WRITE_COMMAND(0x07,postion_y*16);	//RAM Y address(0 ~ 1FF, actually 0 ~ 13F)
	
	LCD_WRITE_REG(0x0E);	//RAM Write index(prepare to write data)

	LCD_CS_L();
	LCD_RS_H();

	p = ascii;
	p += ch_asc*16;
	for(j=0;j<16;j++)
	{
		b=*(p+j);
		for(i=0;i<8;i++)
		{
			if( b & 0x80 )
			{
				LCD_WRITE_DATA(color_front);
			}
			else
			{
				LCD_WRITE_DATA(color_background);
			}
			b=b<<1;			
		}	
	}

	LCD_CS_H();
}

/******************************************************************************
* Function Name  : lcd_display_string
* Description    : *str: address of string data. 
					x: the xth row(0~30).
					y: the yth column(0~20).
					color_front, color_background.
* Input          : None
* Output         : None
* Return         : None
******************************************************************************/
void lcd_display_string(char *str, 
						unsigned int color_front, 
						unsigned int color_background, 
						unsigned char x, 
						unsigned char y )
{
	while (*str != 0) 
	{ 
		lcd_display_char( *str, color_front, color_background, x, y);
		if(++x>=30)
		{
			x=0;
			if(++y>=20)
			{
				y=0;
			}
		}
		str ++;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And where is your character bit map? Is it loaded? What library are you using for the GLCD? What controller does it use?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kuch wrote:

lcd_display_string(buffer, YELLOW, BLUE, 0, 20 );//doesnt work
lcd_display_string("Just a Test", GREEN, BLUE, 0, 40 );//Works

A couple of things to try:

lcd_display_string(buffer, GREEN, BLUE, 0, 40);
strcpy(buffer, "Just a Test");
lcd_display_string(buffer, GREEN, BLUE, 0, 40);

I also notice that you have a y wraparound at 20, after output of the first characters. How does that sit with passing in 20 and 40 for y ? Did you intend for x to be 20 and 40 ?

You should also try what wek suggested, and answer the question from js.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd say the source is confusing. The logic seems to indicate that x is the column and y is the row. (That makes sense, but why not call them col and row instead of x and y ? If you can't keep track of what is what, I mean.)

The function header comments seem to indicate that x is the row and y is the column. There is also an indication of valid ranges for x and y, which you clearly violate in both the function calls I quoted above.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js - the GLCD is a LTM022A69B, and yes the character map is loaded as all other strings are being displayed...

The library came with the GLCD and i wanted to see if i could get it running before I scrap it and start fresh

The GLCD is a 2.2" 320x240

ChaunceyGardiner these are libraries I recieved with the GLCD I havent fiddled around with them yet, I Tried

strcpy(buffer, "Just a Test");
lcd_display_string(buffer, GREEN, BLUE, 0, 40); 

And got the following Warnings on compile
../test.c:118: warning: implicit declaration of function 'strcpy'
../test.c:118: warning: incompatible implicit declaration of built-in function 'strcpy'
and the string wasnt displayed

I have also tried what wek said and nothing was displayed
I even tried the following to see if it was somehow a wrap issue but got nothing on the display

sprintf(buffer, "I");
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kuch wrote:
ChaunceyGardiner these are libraries I recieved with the GLCD I havent fiddled around with them yet, I Tried

strcpy(buffer, "Just a Test");
lcd_display_string(buffer, GREEN, BLUE, 0, 40); 

And got the following Warnings on compile
../test.c:118: warning: implicit declaration of function 'strcpy'
../test.c:118: warning: incompatible implicit declaration of built-in function 'strcpy'
and the string wasnt displayed

I have also tried what wek said and nothing was displayed
I even tried the following to see if it was somehow a wrap issue but got nothing on the display

sprintf(buffer, "I");

You have to #include to use strcpy(). But that seems irrelevant now.

You should also try my other suggestion, as you claimed writing to 0, 40 worked.

Anyway, I think you should start by taking a look at what I told you about x and y. Try passing 0 for both and see what happens. If that doesn't work, try passing 1 for both.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

x is the column and Y is the row.....I tried altering the x and y values to see if it would help but nothing all other strings still show up properly except the any string with the Buffer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

okay so I think I have discovered the problem thanks to ChaunceyGardiner
If i do the following i get the proper display

lcd_display_string(buffer, YELLOW, BLUE, 0, 10 );

just not in the location I would expect it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So as it turns out the way the x and y variables work is it broken into character locations...the screen can print 30 chars wide and 20 rows of text...

Thanks everybody!!!!