Topics

► Games

► Sound & Music

► Clocks

► GPS

► Tools

► Tutorials

By processor

► ATtiny85

► ATtiny84

► ATtiny841

► ATtiny2313

► ATtiny861

► ATmega328

► ATmega1284

About me

  • About me

Feeds

RSS feed

Big Text for Little Display

11th May 2017

This article describes a small addition to my ATtiny85 Graphics Display to allow you to plot double-sized characters, alongside the other text and graphics supported by the previous version. This is useful if you're using the display for a digital readout where the values need to be clearly visible:

BigText.jpg

Displaying double-sized characters on the 64x48 OLED graphics display.

With double-sized characters the display allows 3 lines of five characters per line.

Bitmap doubling

The key routine is Stretch(), which takes an 8-bit bit pattern, and stretches it to 16 bits with each bit repeated twice:

int Stretch (int x) {
  x = (x & 0xF0)<<4 | (x & 0x0F);
  x = (x<<2 | x) & 0x3333;
  x = (x<<1 | x) & 0x5555;
  return x | x<<1;
}

This nice algorithm is from Hacker's Delight [1]. It works as follows:

Starting from the bit pattern abcdefgh, successive lines of the routine generate:

0000abcd0000efgh
00ab00cd00ef00gh
0a0b0c0d0e0f0g0h
aabbccddeeffgghh

The routine to plot the double-size characters calls this for each column of the dot-matrix character definition, and then plots it twice horizontally:

void PlotBigText(int x, int y, PGM_P s) {
  int p = (int)s;
  int page = (47 - y - yOrigin)>>3;
  while (1) {
    char c = pgm_read_byte(p++);
    if (c == 0) return;
    for (uint8_t col = 0 ; col < 6; col++) {
      int bits = Stretch(pgm_read_byte(&CharMap[c-32][col]));
      for (int i=2; i--;) {
        Buffer[(page-1)*64 + x + xOrigin] = bits;
        Buffer[page*64 + x + xOrigin] = bits>>8;
        x++;
      }
    }
  }
}

I've also updated the Graphics Display program to use the PGM_P macro to define strings in program memory; to specify a string you now specify it using the PSTR macro, so the demo program to give the display shown above is:

void DoubleSizeCharacters () {
  xOrigin = 0; yOrigin = 0;
  ClearBuffer();
  PlotBigText(0, 32, PSTR("4.98V"));
  PlotBigText(0, 16, PSTR("0.15A"));
  PlotText(0, 0, PSTR("10:27:59am"));
  DisplayBuffer();
}

Here's the whole updated ATtiny85 Graphics Display program with the examples: ATtiny85 Graphics Display Program V2.


  1. ^ Warren Jr., Henry S. (2013) [2002]. Hacker's Delight (2 ed.). Addison Wesley - Pearson Education, Inc., p. 139-141.

blog comments powered by Disqus