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

Adding new characters to graphics.c

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



Joined: 16 Sep 2009
Posts: 21

View user's profile Send private message

Adding new characters to graphics.c
PostPosted: Wed Feb 10, 2010 7:17 am     Reply with quote

Hi,

I want to add a custom/new character to graphics.c file. How can i do that?

I've added a new line to the second array and made it one line bigger:

const int8 FONT2[45][5]

the character is :
0x08, 0x14, 0x2A, 0x14, 0x22, // «

But i couldnt find out where does this comparison occur. How does this "for" loop compares the array of chars with the character entered? :

Code:

#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


[b]
   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
[/b]
      // 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
                  }
               }
            }
         }
      }
   }
}


Everything works fine except the new character.

And also how do i add a custom character of 5x7 to the graphics.c file?

Thanks for your help...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 10, 2010 5:26 pm     Reply with quote

The text57 code compares the input string characters to the tilde '~'
character. The tilde is the last character in the FONT2 array in the
graphics.c file. The ASCII hex value for the tilde character is 0x7E.
I've marked in bold the code that does the test for the tilde character:
Quote:

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

You have added one new character to the end of the FONT2 array.
Therefore, its code will be 0x7F. To use the new character, you need
to modify that line so it tests for the new maximum character in the
array, as shown below. Use 0x7F instead of '~' (0x7E):
Quote:

else if(*textptr <= 0x7F)
salgulsen



Joined: 16 Sep 2009
Posts: 21

View user's profile Send private message

PostPosted: Thu Feb 11, 2010 7:47 am     Reply with quote

Ok! It worked like a charm! I've also modified the main program to make this work :

char message1[20];

switch (menustat){

case 0: message1="Sy=20cc ";
message1[13]=0x7F; //to call the custom character

Thank you for your help PCM Programmer...
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