Custom Character Generator for 16×2/Dot Matrix LCD

MAX7219 LED Matrix Custom Char

Around microcontrollers, 16×2 LCD is a great way of displaying information to users. They are the cheapest and easy to use. Moreover, there are tons of libraries available to use these across different microcontrollers. If you want to learn more about 16×2 displays interfacing, you can check out this post. In this post, we will discuss how to show custom characters in a 16×2 LCD and dot matrix displays also. To generate the array bytes for such character generation I have written a small JAVA program, which lets you draw characters and generates an array to use in your code. The application can be downloaded from here.

16×2 LCD:-



display a custom character we must first generate a pattern for it and then save it to the CGRAM. Since we have the library functions with us already, it should be easy to do this with some simple commands. Here is the Library for LCD functions, but here we have copy-pasted all the Library functions in the program itself, so no need to include this header file in our program. Also check this article for Basic LCD working and its Pinouts.

The first step is to generate a pattern or the custom character. As we know each character is a combination of 5*8 dots. We have to select which dot (pixel) should go high and which should stay low. Simply draw a box like below and shade the regions based on your character. My character here is a stick man (hope it looks like one). Once shaded, simple write the equivalent binary value of each byte as shown below.

Simply put a ‘1’ on the shaded region and a ‘0’ on the un-shaded region for each byte, and that is it our custom pattern is ready. Similarly I have made 8 custom pattern codes for our 8 memory spaces present it the CGROM. They are listed in the table below

Programming and Working Explanation:

Now our pattern codes are ready, we just have to load them to the CGRAM of LCD and display them using PIC microcontroller. To load them in to the CGRAM we can form a 5*8 array of elements and load each byte by using a ‘for loop’. The array of pattern code is shown below:

const unsigned short Custom_Char5x8[] = {
  0b01110,0b01110,0b00100,0b01110,0b10101,0b00100,0b01010,0b01010, // Code for CGRAM memory space 1
  0b00000,0b00000,0b01010,0b00100,0b00100,0b10001,0b01110,0b00000, // Code for CGRAM memory space 2
  0b00100,0b01110,0b11111,0b11111,0b01110,0b01110,0b01010,0b01010, // Code for CGRAM memory space 3
  0b01110,0b10001,0b10001,0b11111,0b11011,0b11011,0b11111,0b00000, // Code for CGRAM memory space 4
  0b01110,0b10000,0b10000,0b11111,0b11011,0b11011,0b11111,0b00000, // Code for CGRAM memory space 5
  0b00000,0b10001,0b01010,0b10001,0b00100,0b01110,0b10001,0b00000, // Code for CGRAM memory space 6
  0b00000,0b00000,0b01010,0b10101,0b10001,0b01110,0b00100,0b00000, // Code for CGRAM memory space 7
  0b11111,0b11111,0b10101,0b11011,0b11011,0b11111,0b10001,0b11111  // Code for CGRAM memory space 8

Each memory space is loaded with its respected character pattern. To load this pattern into the HD44780 IC, the data-sheet of HD44780 has to be referred, but it is just lines of command that can be used to set the address of the CGRAM

//*** Load custom char into the CGROM***//////
  Lcd_Cmd(0x04);   // Set CGRAM Address
  Lcd_Cmd(0x00);   // .. set CGRAM Address
  for (i = 0; i <= 63 ; i++)
  Lcd_Cmd(0);      // Return to Home
  Lcd_Cmd(2);      // .. return to Home
  //*** Loading custom char complete***//////

Here, inside the ‘for loop’ each binary value is loaded into the CGROM. Once the pattern is loaded, the custom characters can be made to display by simply calling the location of the pattern using the void Lcd_Print_Char(char data) function as shown below.

    Lcd_Print_Char(0); // Display Custom Character 0
    Lcd_Print_Char(1); // Display Custom Character 1
    Lcd_Print_Char(2); // Display Custom Character 2
    Lcd_Print_Char(3); // Display Custom Character 3
    Lcd_Print_Char(4); // Display Custom Character 4
    Lcd_Print_Char(5); // Display Custom Character 5
    Lcd_Print_Char(6); // Display Custom Character 6
    Lcd_Print_Char(7); // Display Custom Character 7

In this video, I will show you a custom character generator for MAX7219 based 8×8 LED matrix. The app is developed using JAVA. If you are interested in making some updates to it you can check out my repository on GitHub. All links are provided below.





Bikash Panda
Catch Me On

Related posts