Thursday, August 11, 2011

A simple 3x5 binary font generator

Hi!

In my LED-matrix-project, I needed some kind of possibility to display text.
Since the flash memory of an AVR, especially from the ATTiny series, is somewhat limited,
I had to find a good way to store the characters without using up to much of the space.
After a small discussion on www.mikrocontroller.net, I had everything I needed to make it.
 Well, everything but the font.
As recommended, I'm using a 16-bit mono-color font, which means, I'm storing all the information needed in just two bytes. This makes it a bit hard to understand by just looking at the binary, so I wrote a small program
to generate the chars for me.

Using this and a routine from the forum-user "Peter Dannegger", I can now display the characters on the matrix. Here is the function, which is meant to be used together with the code I posted earlier:

void writeSign(uint8_t px, uint8_t py, uint16_t pattern, uint8_t color){
   for (int x = 0; x < 3; x++) {
      for (int y = 0; y < 5; y++) {
         if (pattern & 1) // LSB first
            ht1632_plot(px +x, py +y, color);
         else
            ht1632_plot(px +x, py +y, BLACK);  
         pattern >>= 1; // next bit
      }
   }
}



You can download the program to generate the 16-bit fonts here:
http://sourceforge.net/projects/binaryfontmaker/

Apexys

No comments:

Post a Comment