This tutorial is about making/building your own characters/special images and then displaying them on character 16×2 lcd. Generating custom characters or special character images and displaying on lcds of any sizes (16×1,16×2,8×1,8×2,20×1,20×2,40×1,40×2 etc) is not a very hard task. One must go through the internal structure of lcd control set in order to know how the character lcd works? Once you know how the lcd works and what features it offers. Then you can easily build and display characters of your desire on lcd screen in a defined matrix.
What are custom characters?
Custom characters are self made characters which we design by our self. We have full control on designing them with some constraints which i will discuss later. Like if we want to display a smiley on 16×2 lcd. We don’t have an ASCII character for smiley to display it on 16×2 lcd. Example of custom characters is below.
How custom characters are displayed on 16×2 lcd?
Before beginning any further i recommend you to please take the 16×2 lcd display introduction tutorial. Tutorial will let you know about the pinout and internal structure of 16×2 LCD. (Click below)
16 × 2 LCD has an internal CG-RAM (Character Generated RAM) in which we can generate or create our custom character. The size of CG-RAM is 64 bytes. We can generate / place 8 characters of size 5 × 8 at a time in CG-RAM. We can also place 5 × 10 size characters in CG-RAM but only 4.
5 × 8 represents the dimension of the matrix in which a particular character can be displayed. 5 represents the Number of Columns and 8 represents the Number of Rows in a matrix. 5 × 8 combined is a matrix size. Matrix is composed of pixels which we turn on and off to represent or make a character. For example to display a smiley in 5 × 8 dimension individual pixels on and off will be same like below.
The above Binary or Hex values are then arranged in a byte array. Byte array is then placed in to CG-RAM of 16 × 2 LCD. Now when we want to display this smiley character on LCD screen we just call its address in CG-RAM and finally the character will appear on 16 × 2 LCD screen.
Circuit Diagram
How to Generate Byte Code for Custom Characters
- Visit https://maxpromer.github.io/LCD-Character-Creator/
- Create the Character You Want
- Copy the byte char array code. Example : byte customChar[] = { B00000, B00000, B01010, B10101, B10001, B01010, B00100, B00000 };
- Paste the code accordingly in my source code and change the name accordingly.
Source Code
/*
Custom Characters
16 x 2 LCD Display with Arduino
HarshTronics
For More :
https://www.harshtronic.blogspot.com
https://www.instagram.com/harshtronics
*/
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
int contrast = 100;
byte s1[8]= // Array of bytes
{
B00000, // B stands for binary formatter and the 5 numbers are the pixels
B00000,
B01010,
B10101,
B10001,
B01010,
B00100,
B00000
};
byte s2[8]={B00100,
B01110,
B01110,
B01110,
B11111,
B00000,
B00100,
B00000,};
byte s3[8]=
{
0b01110,
0b01110,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010,
0b01010,};
byte s4[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};
byte s5[8]=
{ B00000,
B01110,
B10001,
B10001,
B10001,
B01010,
B11011,
B00000,
};
byte s6[8] =
{
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000,
};
void setup() {
analogWrite(6,contrast);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
lcd.createChar(1, s1); // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported
lcd.createChar(2, s2);
lcd.createChar(3, s3);
lcd.createChar(4, s4);
lcd.createChar(5, s5);
lcd.createChar(6, s6);
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Custom Character");
for(int i=5;i<11;i++)
{
lcd.setCursor(i,1);
lcd.write(i-4);
delay(500);
}
delay(50000);
}
No comments:
Post a Comment