Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/05/03 16:49
Read: times


 
#50125 - RE: 5x7 character mapping
Responding to: ???'s previous message
This may be considered somewhat unsuitable in the sense that the character generation method I'm sharing is not necessarily the best way to do it for entire character sets. It's not that it wouldn't work, it's just that for large numbers of characters or elaborate fonts, automated tools are probably better.

This method allows one to "draw" a character by hand and the macros convert it to a binary array. References to "LCD" do not mean that this method is limited to LCDs; it works for any kind of character or glyph generation, printers included.
/* cgCharBits[][] holds LCD character generator patterns for
 * user-defined characters (UDCs).  Module initialization writes these
 * to LCD CGRAM Characters are defined using 8x8 glyph-building
 * macros.
 *
 * This glyph building method is from the book "Expert C Programming"
 * by Peter van der Linden, of Sun Microsystems' compiler and OS
 * kernel group, who says that Sun got the tip from the Usenet's
 * comp.lang.c newsgroup many years ago.
 *
 * Template for 8-bit glyphs:
 *  {
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _
 *  },
 *
 * For 16x16, use:
 *
 *  #define s ((((((((((((((((0
 *
 * For example:
 *
 *  U16 stopwatch[] =
 *  {
 *      s _ _ _ _ _ X X X X X _ _ _ X X _,
 *      s _ _ _ X X X X X X X X X _ X X X,
 *      s _ _ X X X _ _ _ _ _ X X X _ X X,
 *      s _ X X _ _ _ _ _ _ _ _ _ X X _ _,
 *      s _ X X _ _ _ _ _ _ _ _ _ X X _ _,
 *      s X X _ _ _ _ _ _ _ _ _ _ _ X X _,
 *      s X X _ _ _ _ _ _ _ _ _ _ _ X X _,
 *      s X X _ X X X X X _ _ _ _ _ X X _,
 *      s X X _ _ _ _ _ X _ _ _ _ _ X X _,
 *      s X X _ _ _ _ _ X _ _ _ _ _ X X _,
 *      s _ X X _ _ _ _ X _ _ _ _ X X _ _,
 *      s _ X X _ _ _ _ X _ _ _ _ X X _ _,
 *      s _ _ X X X _ _ _ _ _ X X X _ _ _,
 *      s _ _ _ X X X X X X X X X _ _ _ _,
 *      s _ _ _ _ _ X X X X X _ _ _ _ _ _,
 *      s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 *  };
 */
#define X   )*2+1
#define _   )*2
#define s   ((((((((0

static const U8 cgCharBits[][8] =   /* Up to 8 UDC's for HD44780 */
{
    /* UDC# 0x00 is not used because 0x00 == '' == NUL-terminator. */
    {   /* UDC# 0x01 = Backslash */
        s _ _ _ _ _ _ _ _,
        s _ _ _ X _ _ _ _,
        s _ _ _ _ X _ _ _,
        s _ _ _ _ _ X _ _,
        s _ _ _ _ _ _ X _,
        s _ _ _ _ _ _ _ X,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _
    },
    {   /* UDC# 0x02 = Degree symbol */
        s _ _ _ _ X X X _,
        s _ _ _ _ X _ X _,
        s _ _ _ _ X X X _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _
    },
#if 0
    {   /* TBD */
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _
    },
#endif
};

/* Undefine glyph-building macros. */

#undef X
#undef _
#undef s
#endif  /* DISP_GLYPHS */

The example above show a more or less "standard" character orientation. The same technique can be used when the character generator takes bytes in a "rotated" form. Here's an example of the orientation for a VFD I recently used.
/* Template (rotated left 90 degrees) for 8-bit glyphs:
 * {
 *     s _ _ _ _ _ _ _ _,              // Blank for character spacing
 *     s _ _ _ _ _ _ _ _,
 *     s _ _ _ _ _ _ _ _,
 *     s _ _ _ _ _ _ _ _,
 *     s _ _ _ _ _ _ _ _,
 *     s _ _ _ _ _ _ _ _
 *  // ^
 *  // |__ TOP LEFT PIXEL
 * },
 */

static const UC code cgCharBits[][6] =
{
    /* The characters are loaded into the display from the bottom-up.
     */
    {   /* UDF# 0x82 = Degree symbol */
        s _ _ _ _ _ _ _ _,
        s _ _ _ _ _ _ _ _,
        s X X X _ _ _ _ _,
        s X _ X _ _ _ _ _,
        s X X X _ _ _ _ _,
        s _ _ _ _ _ _ _ _
    }
};



List of 14 messages in thread
TopicAuthorDate
5x7 character mapping            01/01/70 00:00      
   RE: 5x7 character mapping            01/01/70 00:00      
   RE: 5x7 character mapping            01/01/70 00:00      
   RE: 5x7 character mapping            01/01/70 00:00      
      RE: 5x7 character mapping            01/01/70 00:00      
   RE: 5x7 character mapping            01/01/70 00:00      
      RE: 5x7 character mapping            01/01/70 00:00      
         RE: 5x7 character mapping            01/01/70 00:00      
            RE: 5x7 character mapping            01/01/70 00:00      
            RE: 5x7 character mapping            01/01/70 00:00      
               RE: 5x7 character mapping            01/01/70 00:00      
            RE: 5x7 character mapping            01/01/70 00:00      
               RE: 5x7 character mapping            01/01/70 00:00      
                  RE: 5x7 character mapping            01/01/70 00:00      

Back to Subject List