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 support@ccsinfo.com

bad CHARACTER

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







bad CHARACTER
PostPosted: Thu Nov 04, 2004 3:53 pm     Reply with quote

Why apear extrange character at the end of the line???
Please help me...

#include <16F877.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include <HDM64GS12.c>
#include <graphics.c>


void main()
{

int i;
CHAR const my_string[]="hola amigos";
CHAR const my_string2[]="aca estoy";
CHAR const my_string3[]="todo lison";
CHAR const my_string4[]="entrar aqui";



char buffer[];

glcd_init(ON);

for (i=0;i<=20;i++)
buffer[i]=my_string[i];
glcd_text57(5, 1,buffer, 1, ON);


for (i=0;i<=20;i++)
buffer[i]=my_string2[i];
glcd_text57(5, 9,buffer, 1, ON);

for (i=0;i<=20;i++)
buffer[i]=my_string3[i];
glcd_text57(5, 17,buffer, 1, ON);

for (i=0;i<=20;i++)
buffer[i]=my_string4[i];
glcd_text57(5, 25,buffer, 1, ON);



#ifdef FAST_GLCD
glcd_update();
#else
delay_ms(100); // Reduces flicker by allowing pixels to be on
// much longer than off





}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 04, 2004 4:15 pm     Reply with quote

You didn't declare the size of buffer[].

I guess the "glcd_text57()" function checks for a NULL. We don't know what the parameters are.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Nov 05, 2004 10:33 am     Reply with quote

Thatīs because the display is showing you all the variables in the
boundaries of your stored string.

To display the string[]="hola amigos" you use
for (i=0;i<=20;i++)
where the string "pointer" has a range i<= 20
while your message is only 10 characters long.

Try putting a null at the end of your string and
break the for cycle when detected.

HTH

Humberto
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Nov 05, 2004 10:38 am     Reply with quote

Quote:
CHAR const my_string[]="hola amigos";


This should put a NULL on the end of the string.

Quote:
Thatīs because the display is showing you all the variables in the
boundaries of your stored string.


He is indeed copying more than needed but hopefully the printing routine checks for the NULL as it should. Doesn't really matter if he copies more data so long as he is not overwriting other vars.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Nov 05, 2004 11:45 am     Reply with quote

Mark,

I know that but he didnīt post the function definition for

glcd_text57(5, 1,buffer, 1, ON);

so we didnīt know for sure if he is looking for a NULL as end of char string recognition.

Humberto
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Nov 05, 2004 12:34 pm     Reply with quote

Didn't I already say that?

Quote:
I guess the "glcd_text57()" function checks for a NULL. We don't know what the parameters are.


Regardless, a NULL is in there from the declaration so there is no need to
Quote:
Try putting a null at the end of your string


Quote:
break the for cycle when detected.

All this will do is save a little time doing the copying. It still does not address the problem at hand. Now if you said to use a counter in there and break on NULL and pass the length to the function, then I'd agree with you. I am pretty sure that the function checks for a NULL. If not, that is where the problem is. However, not declaring the size of buffer[] is a definite problem since he is copying data into it. Any variables adjacent to it will overwrite the data and cause him problems not to mention the copying into buffer[] will most likely overwrite other variables as well.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Nov 05, 2004 12:56 pm     Reply with quote

Mark,

I know what the problem is and how to solve it. FYI it is not my inquiry,
it is a thread posted by ccmcca and I just put the spot on the subject
I think the problem is and I hope this were solved by ccmcca.

Quote:

Now if you said to use a counter in there and break on NULL and pass the length to the function, then I'd agree with you.


Yes, I mean that. Sorry if the post wasn't clear enough.

Quote:

I am pretty sure that the function checks for a NULL


Iīm not pretty sure for that.

Anyway I would like to listen to our common friend ccmcca


Humberto
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Nov 05, 2004 1:06 pm     Reply with quote

Actually this is CCS driver file

Code:
/////////////////////////////////////////////////////////////////////////
// Purpose:       Write text on a graphic LCD
// Inputs:        (x,y) - The upper left coordinate of the first letter
//                textptr - A pointer to an array of text to display
//                size - The size of the text: 1 = 5x7, 2 = 10x14, ...
//                color - ON or OFF
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_text57(int16 x, int16 y, char* textptr, int8 size, int1 color)
#else
void glcd_text57(int8 x, int8 y, char* textptr, int8 size, int1 color)
#endif
{
   int8 j, k, l, m;                       // Loop counters
   int8 pixelData[5];                     // Stores character data

   for(; *textptr != '\0'; ++textptr, ++x)// Loop through the passed string
   {
      if(*textptr < 'S') // Checks if the letter is in the first font array
         memcpy(pixelData, FONT[*textptr - ' '], 5);
      else if(*textptr <= '~') // Check if the letter is in the second font array
         memcpy(pixelData, FONT2[*textptr - 'S'], 5);
      else
         memcpy(pixelData, FONT[0], 5);   // Default to space

      // Handles newline and carriage returns
      switch(*textptr)
      {
         case '\n':
            y += 7*size + 1;
            continue;
         case '\r':
            x = 0;
            continue;
      }

      if(x+5*size >= GLCD_WIDTH)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 7*size + 1;                 // Set y at next position down
      }
      for(j=0; j<5; ++j, x+=size)         // Loop through character byte data
      {
         for(k=0; k < 7; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j], k)) // Check if the pixel should be set
            {
               for(l=0; l < size; ++l)    // These two loops change the
               {                          // character's size
                  for(m=0; m < size; ++m)
                  {
                     glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
                  }
               }
            }
         }
      }
   }
}

#endif
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