Thanh navigation

Hiển thị các bài đăng có nhãn LCD. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn LCD. Hiển thị tất cả bài đăng

Thứ Hai, 13 tháng 3, 2023

LCD Hitachi HD66710 controller

https://www-elektroda-pl.translate.goog/rtvforum/topic1099191.html?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en

https://kbiva.wordpress.com/2012/12/30/hp-laserjet-4500-front-panel/

https://kbiva.wordpress.com/2012/12/30/hp-laserjet-4500-front-panel/

https://playground.arduino.cc/Code/HpLaserJetLcd/

https://learn.sparkfun.com/tutorials/retired---using-the-logic-level-converter 

https://forums.adafruit.com/viewtopic.php?t=22226

Thứ Ba, 9 tháng 8, 2022

16×2 lcd in 4-bit and 8-bit mode (LCD: Part 3)

 After making many microcontroller projects with character lcd’s(16×1,16×2) and interfacing them with variety of microcontrollers (arduino, microchip pin microcontroller,8051 series,stm32 etc). I still get emails from students about what is the difference between character lcd interfacing in 4-bit and 8-bit mode. So i decided why not to write a post on difference between lcd 4-bit and 8-bit mode interfacing. 

In this short tutorial i will try to explain the basic difference between the two modes and the advantages/disadvantages in using the either of the two. This post will help the newbies putting their step in embedded field to easily understand the two modes. Character lcd’s come in many sizes 8×1 , 8×2 , 10×2 , 16×1 , 16×2 , 16×4 , 20×2 , 20×4 ,24×2 , 30×2 , 32×2 , 40×2 etc. Each character lcd has 8-bit data port to connect with external controllers.  All the character lcds can be used in 8-bit as well as 4-bit mode.

I assume that you have an introduction to character lcds and know about their internal structure, pin out, registers, commands etc. If you don’t I recommend to first take the introduction tutorial and then resume with this post.

lcd 4bit and 8bit mode – Major difference

The major difference in 4 bit and 8 bit mode lies in data pins used and lcd initializing commands.

Since character lcd’s has 8 data pins so they accept only 8-bit data. Character datatype is 8-bit wide. So character values can easily be send to lcd. This mode is know as 8-bit mode in which we send an 8-bit value such as character or ASCII value to lcd. 

In 4 bit mode only four data pins are used. Character 8-bit ASCII value is divided in to two 4-bit nibbles. High nibble is sent first following by the lower nibble. So in theory two strokes are needed to send a character(8-bit) to lcd when we are using lcd in 4-bit mode. 

In contrast in 8-bit communication mode, 8-bit ASCII value of character is send in a single stroke to lcd.

Thus the 4-bit mode generates latency. Although 4-bit mode generates latency it on the other hand saves 4 gpio(general purpose input out pins) of the external controller sending data to lcd. Which can be utilized else where.   

The gif animation below explains the difference between 4-bit and 8-bit mode very beautifully.

16x2 lcd in 4 bit and 8 bit mode with microcontroller

16×2 lcd in 4 bit and 8 bit mode with microcontroller

Lcd in 4-bit mode

Commands used to initialize the 4-bit lcd mode 

  • To initialize character lcd in 4 bit mode we send value hex 0x20 to command register of lcd. 0x20 tells the lcd controller that we want to communicate in 4-bit mode. Lcd is 1 line (has 1 row) and we want character shape displayed in 5×7 matrix.
  • If our character lcd has 2 lines (rows) we will send 0x28 instead of 0x20. It tells the lcd controller that we want 4 bit communication and character size is between 5×7 dot matrix.
  • 4-bit mode make use of only just four data pins D4-D5-D6-D7.
  • In 4-bit mode character is displayed on lcd in two pulse signals. First the higher four nibbles of a character are sent to the lcd with an enable stroke. Than the lower four nibbles are send with enable stroke.
  • Since two pulse (enable) signals are required to display a single character so 4-bit mode latency time is high.

Some Projects made using character lcd in 4-bit mode.

Lcd in 8-bit mode

Commands used to initialize the 8-bit lcd mode are

  • To initialize character lcd in 8-bit mode we send vale hex 0x30 to command register of lcd. 0x30 tells lcd that we want to communicate in 8-bit mode. Lcd is 1 line (has 1 row) and we want character shape displayed in 5×7 matrix. 
  • If our character lcd has 2 lines (rows) we will send 0x38 instead of 0x20. It tells the lcd controller that we want 4 bit communication and character size is between 5×7 dot matrix.
  • In 8-bit mode only one pulse signal is required to display a character on lcd.
  • Thus it is faster than 4-bit mode.

Some Projects made using character lcd in 8-bit mode.

  https://www.engineersgarage.com/lcd-in-4-bit-mode-and-8-bit-mode/

16×2 lcd working and internal structure (LCD: Part 0)

 

NxN(8×1 , 8×2 , 10×2 , 16×1 , 16×2 , 16×4 , 20×2 , 20×4 ,24×2 , 30×2 , 32×2 , 40×2) Character lcd working, Pinout and description
 
Lcd stands for liquid crystal display. Character and graphical lcd’s are most common among hobbyist and diy electronic circuit/project makers. Since their interface serial/parallel pins are defined so its easy to interface them with many microcontrollers. Many products we see in our daily life have lcd’s with them. They are used to show status of the product or provide interface for inputting or selecting some process. Washing machine, microwave,air conditioners and mat cleaners are few examples of products that have character or graphical lcd’s installed in them. In this tutorial i am going to discuss about the character lcd’s. How they work? their pin out and initialization commands etc.

Lcd sizes

​Character lcd’s come in many sizes 8×1, 8×2, 10×2, 16×1, 16×2, 16×4, 20×2, 20×4, 24×2, 30×2, 32×2, 40×2 etc . Many multinational companies like Philips, Hitachi, Panasonic make their own custom type of character lcd’s to be used in their products. All character lcd’s performs the same functions(display characters numbers special characters, ascii characters etc).Their programming is also same and they all have same 14 pins (0-13) or 16 pins (0 to 15). 
In an mxn lcd. M denotes number of columns and n represents number of rows. Like if the lcd is denoted by 16×2 it means it has 16 columns and 2 rows. Few examples are given below. 16×2, 8×1 and 8×2 lcd are shown in the picture below. Note the difference in the rows and columns.
 
16x2 Character Lcd Rows and Coulombs

16×2 Character Lcd Rows and Colulmns
8x1 Character Lcd Rows and Coulombs

 8×1 Character Lcd Rows and Columns

8x2 Character Lcd Rows and Coulombs 

8×2 Character Lcd Rows and Columns

How character is made on lcd?

On a character lcd a character is generated in a matrix of 5×8 or 5×7. Where 5 represents number of columns and 7/8 represent number of rows. Maximum size of the matrix is 5×8. You can not display character greater then 5×8 dimension matrix. Normally we display a character in 5×7 matrix and left the 8th row for the cursor. If we use the 8th row of the matrix for the character display, then their will be no room for cursor. The picture below shows the 5×8 dot matrix pixels arrangement.

16x2 lcd single character rows and coulombs

16×2 lcd single character rows and columns

 

To display character greater than this dimension you have to switch to graphical lcd’s. To learn about graphical lcds here is a good tutorial Graphical Lcd’s Working and Pin out.

Lcd 16×2 Pin out

All character lcd’s have 

  • Eight(8) data pins D0-D7
  • Vcc (Apply +5 volt here)
  • Gnd (Ground this pin)
  • Rc (Register select)
  • Rw (read – write)
  • En (Enable)
  • V0 (Set Lcd contrast)

16×2 lcd pin out diagrammatically is shown below. 

16x2 lcd pinout 

16×2 lcd pinout
The picture above shows the pin out of the character lcd. Almost all the character lcd’s are composed of the same pin out. Lcd’s with total pin count equal to 14 does not have back light control option. They might have back light always on or does not have a back light. 16 total pin count lcd’s have 2 extra A and K pins. A means anode and K cathode, use these pins to control the back light of lcd.

Character lcd controller – HD44780

Character Lcd’s have a controller build in to them named HD44780. We actually talk with this controller in order to display character on the lcd screen. HD44780 must be properly handled and initialized before sending any data to it. HD44780 has some registers which are initialized and  manipulated for character displaying on the lcd. These registers are selected by the pins of character lcd. 

Lcd Rs(Register select) Pin

Register select selects the HD44780 controller registers. It switches between Command and data register.                      

  • Command Register
  • Data Register
Command Register
When we send commands to lcd these commands go to Command register and are processed their. Commands with their full description are given in the picture below. When Rs=0 command register is selected.
Data Register
When we send Data to lcd it goes to data register and is processed their. When Rs=1 data register is selected.

Lcd RW(Read/Write) Pin

Rw pin is used to read and write data to HD44780 data and command registers. When Rw=1 we can read data from lcd. When Rw=0 we can write to lcd.

Lcd En(Enable) Pin

When we select the register Rs(Command and Data) and set Rw(read –  write) and placed the raw value on 8-data lines, now its time to execute the instruction. By instruction i mean the 8-bit data or 8-bit command present on Data lines of lcd. For sending the final data/command present on the data lines we use this enable pin. Usually it remains en=0 and when we want to execute the instruction we make it high en=1 for some mills seconds. After this we again make it ground en=0.

Lcd V0 of contrast set pin

To set lcd display sharpness use this pin. Best way is to use variable resistor such as potentiometer a variable current makes the character contrast sharp. Connect the output of the potentiometer to this pin. Rotate the potentiometer knob forward and backward to adjust the lcd contrast. 
NOTE: we can not send an integer, float, long, double type data to lcd because lcd is designed to display a character only. Only the characters that are supported by the HD44780 controller. See the HD44780 data sheet to find out what characters can we display on lcd.  The 8 data pins on lcd carries only  Ascii 8-bit code of the character to lcd. How ever we can convert our data in character type array and send one by one our data to lcd. Data can be sent using lcd in 8-bit or 4-bit mode. If 4-bit mode is used, two nibbles of data (First high four bits and then low four bits) are sent to complete a full eight-bit transfer. 8-bit mode is best used when speed is required in an application and at least ten I/O pins are available. 4-bit mode requires a minimum of seven bits. In 4-bit mode, only the top 4 data pins (4-7) are used. 

Standard Lcd Commands with their functions are described below.

nxn lcd initialization commands 

 nxn lcd initialization commands

Command 0x30 means we are setting 8-bit mode lcd having 1 line and we are initializing it to be 5×7 character display.Now this 5×7 is some thing which every one should know what it stands for. usually the characters are displayed on lcd in 5×8 matrices form. where 5 is total number of columns and is number of rows.Thus the above 0x30 command initializes the lcd to display character in 5 columns and 7 rows the last row we usually leave for our cursor to move or blink etc.

Lcd command meanings and functions

  • The command 0x38 means we are setting 8-bit mode lcd having two lines and character shape between 5×7 matrix.
  • The command 0x20 means we are setting 4-bit mode lcd having 1 line and character shape between 5×7 matrix.
  • The command 0x28 means we are setting 4-bit mode lcd having 2 lines and character shape between 5×7 matrix.
  • The command 0x06 is entry mode it tells the lcd that we are going to use.
  • The command 0x08 dispalys cursor off and display off but with out clearing DDRAM contents.
  • The command 0x0E displays cursor on and dispaly on.
  • The command 0x0c dispaly on cursor off(displays cursor off but the text will appear on lcd)
  • The command 0x0F dispaly on cursor blink(text will appear on screen and cursor will blink).
  • The command 0x18 shift entire dispaly left(shift whole off the text on the particular line to its left ).
  • The command 0x1C shift entire dispaly right(shift whole off the text on the particular line to its right).
  • The command 0x10 Moves cursor one step left or move cursor on step a head to left when ever new character is displayed  on the screen.
  • The command 0x14  Moves cursor one step right or move cursor on step a head to righ when ever new character is displayed on the screen. 
  • The command 0x01 clear all the contents of the DDRAM and also clear the lcd removes all the text from the screen.
  • The command 0x80 initialize the cursor to the first position means first line first matrix(start point) now if we add 1 in 0x80+1=0x81 the cursor moves to second matrix.

NOTE: You can send commands in hexadecimal or decimal form which one do you like the result is same because the microcontroller translate the command in 8-bit binary value and sends it to the lcd.

Difference between 4-bit and 8-bit Lcd Mode

Character Lcd’s can be used in 4-bit and 8-bit mode. Before you send commands and data to your lcd. Lcd must first be initialized. This initialization is very important for lcd that are made by Hitachi because they use HD44780 driver chip sets. Hd44780 Chip set  first has to be initialized before using it. If you don’t initialize it properly you will see nothing on your lcd.

For 8-bit mode, this is done as follows:

1. Wait more than 15 mill secs after power is applied.
2. Write command 0x30 to LCD and wait 5 milli seconds for the instruction to complete.
3. Write command 0x30 to LCD and wait 160 micro seconds for instruction to complete.
4. Write command 0x30 AGAIN to LCD and wait 160 micro seconds or Poll the Busy Flag.

In 4-bit mode the high nibble is sent first before the low nibble and the En pin is toggled each time four bits is sent to the LCD. To initialize in 4-bit mode:

1. Wait more than 15 mill secs after power is applied.
2. Write command 0x03 to LCD and wait 5 msecs for the instruction to complete.
3. Write command 0x03 to LCD and wait 160 usecs for instruction to complete.
4. Write command 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag).
Write 0x02 to the LCD to Enable 4-Bit Mode

To learn more about the difference between 4-bit and 8-bit character lcd mode and operation with demo example visit the tutorial link given below. Demo examples are very easy to understand and one can make changes easily in the code. Please also give us your feed back on the post.

 Part 0: https://www.engineersgarage.com/16x2-lcd-working/

Thứ Hai, 8 tháng 8, 2022

Making and displaying Custom characters on lcd with Arduino Uno and 16×2 lcd (LCD: Part 2)

 

This project is about displaying custom characters on 16×2 character lcd using arduino uno microcontroller. With ardunio uno its very easy to display custom characters on lcd. In arduino their is built in structure to generate custom character like many other features which make it perfect board for embedded system projects or diy(do it yourself) projects etc. 

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

Example of custom characters displayed on 16x2 lcd 

Example of custom characters displayed on 16×2 lcd

How custom characters are made and displayed on 16×2 lcd?

Before beginning any further i recommend you to please take the 16×2 lcd display introduction tutorial. Taking the tutorial will let you know about the pin out and internal structure of 16×2 lcd

16×2 lcd has an internal ​CG-RAM(character generated ram) in which we can generate or place our custom character. CG-RAM size 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 coulombs and 8 represents the number of rows. 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.

5x8 pixel dimension of custom character display 

5×8 pixel dimension of custom character display

For each 5×8 matrix with custom character in it we have to translate it in to its equivalent bits. For example the binary value of rows in 5×8 matrix is shown below. Against each binary value its HEX code is also given.

  • Each switched on pixel binary value is ‘1‘.
  • Each switched off pixel binary value is ‘0‘.

  16×2 custom character smiley binary bits

 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.

I almost explained every thing above, about generating custom characters in 16×2 lcd CG-RAM and displaying them on lcd screen. But still their are few things which are not part of this tutorial. Like custom character address in CG-RAM. Its because the arduino ide has pre-defined library which places the custom characters in CG-RAM and call it when needed for display. If you want to know about whats happening behind the library then  i recommend you to please learn about the custom character generation in internal hardware level first before proceeding.

Arduino custom characters displayed on 16×2 lcd – Circuit diagram

For this project you only need a 16×2 character lcd and arduino uno microcontroller/board. You can use any other character lcd according to your wish but remember to change the lcd.begin(no of coulombs of lcd, no of rows of lcd) command in code and insert the dimensions of the lcd you are interfacing with arduino uno. Almost all the character lcd’s have same pin out and uses same hd44780 lcd controller. So their will be no difference in circuit diagram or remaining code. Hd44780 lcd controller is responsible to display characters on character lcd, communicate with external devices and CG-RAM also resides in HD44780 lcd controller.  

In this project i am using 16×2 lcd in 4-bit mode so you have to make pin connections according to the 4-bit mode. Its not very hard just connect in the order given below.

  • LCD RS pin to digital pin 13 of arduino uno
  • LCD Enable pin to digital pin 12 of arduino uno
  • LCD D4 pin to digital pin 11 of arduino uno
  • LCD D5 pin to digital pin 10 of arduino uno
  • LCD D6 pin to digital pin 9 of arduino uno
  • LCD D7 pin to digital pin 8   of arduino uno

 Custom characters displayed on 16x2 lcd using arduino uno

 

Arduino custom character display – Project code

The code of the project is simple. I am going to display 8 custom character on 16×2 lcd. First the required characters byte array are declared in code. Byte arrays are declared in binary as well as hexadecimal format.

The createChar() command in ardunio ide is very important. It creates/puts the character matrix/array against an addres in CG-RAM of 16×2 lcd. In other microcontrollers we have to write the memory address where we want to place our newly created custom character but in ardunio the createChar() command creates the required character automatically and place it against an address in CG-RAM. createChar() function is part of LiquidCrystal library. If we open the library and see the function statements they are communicating with the HD44780 lcd controller and CG-RAM address are defined in the function.

Arduino code steps to create and display custom characters on 16×2 lcd

byte a[8]={B00000,B01010,B00100,B00100,B00000,B01110,B10001,};
The above statement is a byte array of a custom character in binary format.
lcd.createChar(2 , a);
The above command places the a[] byte array custom character against address 2 in CG-RAM. Real address is different its not 2 see library for real address.
lcd.write(2);
The above command displays the custom character placed against the address 2 in CG-RAM.


#include<LiquidCrystal.h>     

LiquidCrystal lcd(13 ,12, 11, 10, 9, 8); //16x2 lcd arduino interface pins
 
//Custom characters byte arrays
byte customchar[8]={B00000,B01010,B00000,B00000,B00000,B00000,B11111,};
byte a[8]={B00000,B01010,B00100,B00100,B00000,B01110,B10001,};
byte s[8]={B00100,B01010,B10001,B10001,B01010,B00100,};
byte s1[8]={B01110,B01010,B11111,B11011,B11111,B01010,B01110,};
byte s2[8]={B01010,B00100,B00100,B01010,B10001,B00100,B10001,};
byte s3[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};
byte s4[8]={0x1F,0x11,0x11,0x11,0x11,0x11,0x1F,};
byte s5[8]={B11111,B11101,B11011,B11101,B11111,B10000,B10000,B10000,};
//Custom characters byte arrays

void setup()
{
lcd.begin(16 ,2); //Initialize 16x2 lcd
lcd.clear(); //Clear lcd display screen

lcd.createChar(1 , customchar); //Creating custom characters in CG-RAM
lcd.createChar(2 , a);
lcd.createChar(3 , s);
lcd.createChar(4 , s1);
lcd.createChar(5 , s2);
lcd.createChar(6 , s3);
lcd.createChar(7 , s4);
lcd.createChar(8 , s5); //Creating custom characters in CG-RAM
}
void loop()
{
int rand,i;
lcd.setCursor(0 ,0); //Place lcd cursor on first row and first coulomb of 16x2 lcd
lcd.print("Cust Character!!"); //Display this test on first row on 16x2 lcd
lcd.setCursor(0 ,1); //Place lcd cursor on second row of 16x2 lcd first coulomb

for(rand=0;rand<10;rand++){ //For loop will display custom characters one by one
i=random(10);
lcd.setCursor(i ,1);
lcd.write(i); //-->>>PRINTING/DISPLAYING CUSTOM CHARACTERS
delay(500);
}
lcd.clear(); //Clear lcd and start again
}

Numerous custom character generators are available online i usually use maxpromer its easy to use and biggest advantage of it is. It can generate whole arduino code in just seconds. Just give it a try i bet you gone love it.

maxpromer custom character generator online 

More projects regarding custom characters, arduino and other microcontroller. All the projects are open source. Each and every statement with circuit diagram of the projects are well explained in the tutorials. 

Part 2: https://www.engineersgarage.com/making-custom-characters-on-lcd-using-arduino/ 

How to generate and display self made Custom characters on 16×2 lcd (LCD: Part 1)

 

 

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.

It requires only knowledge of CG-RAM(character generated ram) of character lcd and the lcd chip set controller to build and display self made characters on 16×2 lcd display. Most of the lcds contains HD4478 controller in them. HD4478 controller is build by Hitachi and its the most popular controller used in the character lcd’s. Almost all of the character lcd’s resides one, but new competitors are also present in market.

By custom characters i mean characters that are not present in the ASCII character set of lcd controller. Like heart symbol, smiley 😀 🙁 😉 etc. We have to declare these custom characters in CG-RAM of lcd by our own. This tutorial will teach you how to declare custom characters in CG-RAM and then call display them one by one to display on 16×2 lcd screen.

What is CG-RAM ?

CG-RAM is the main component in making custom characters. CG stands for custom generated and RAM you all know random access memory. This CG-RAM stores our custom characters once we declare them in our code. I will come on it later. As you know once we write any type of code we need a memory to store it and a controller to run it. In the 16×2 lcd custom character case its same. We write code(arrays) of character’s which we want to display on lcd. Then we store them in a memory on lcd. In our case this memory is named as CG-RAM(Character generated RAM). 

CG-RAM size is 64 Bytes. You can create 8 characters at a time and load them in cg-ram. Each character occupies 8-bytes. Eight characters each of eight byte (8-characters * 8-Bytes) is equal to 8×8=64 Bytes. CG-RAM address in lcd memory starts from 0x40(Hexadecimal) or 64 in decimal.

You can place your first character in address ranging from 0x40 to 0x47. The address moves on by 8 bytes for each character for 2nd character address starts from 0x48 and goes to 0x4F. Last eight’t character address starts from 0x78 and goes to 0x7F.

We generate and put our self made custom characters at these addresses. Once we generate our characters at these address now we can print them on lcd at any time by just sending simple commands to lcd controller. 
Below is the table in which characters addresses and their printing commands are given.
CG_RAM character addresses and commands

 CG-RAM character addresses and commands

In the diagram above you can see starting addresses for each characters with their displaying commands. First character is generated at address 0x40 to 0x47 and is printed on lcd by just sending simple command 0 to lcd. Second character is generated at address 0x48 to 0x55 and is printed by sending 1 to lcd. You can see all character addresses and commands in the above diagram.
 

How to Generate and place Custom Characters in CG-RAM?

Character lcd’s displays each character in 5×7 or 5×8 matrix. Where 5 represents number of coulombs and 8 are number of rows. We create our custom character in 5×7 matrix format. The eighth row is not used because it is dedicated for cursor. In the below picture you can see each individual and dedicated slot of character is a square matrix of pixels. Pixels are arranged in 5×8 format.     

Lcd 5x8 Matrix Display

Lcd 5×8 Matrix Display

Declaring character bits against CG-RAM addresses

Here is a simple example on how to generate pixels array for letter ‘b‘ and then place it in CG-RAM of character 16×2 lcd display.

The Array for generating letter ‘b‘ is
char b[7]={0x10,0x10,0x16,0x19,0x11,0x11,0x1E};

We now have some online websites through which you can get array of your desired image in 5×7 or 5×8 format. One of the most popular is maxpromer. You can graphically input your desired image on a matrix in maxpromer and then with a single button press you get the array of the image. The array can further be used in your code.

 
maxpromer custom character generator

In the above picture you can see the interface of maxpromer. Pretty simple and easy to use. In just seconds you can generate the matrix array for your input character. Array can be generated in binary as well as hexadecimal format. 

What individual bits represent in array really needs to be understood. ‘0‘ represents pixel is off and ‘1‘ represent pixel is on. Like for the letter ‘b‘ whose array was highlighted above. Its representation is given below. For each row we have a binary or hexadecimal representation. In binary representation we ignore the 3 MSB or most significant bits, because the coulombs of the matrix are 5. So 5 LSB least significant bits are considered. Also in hexadecimal representation the 3 MSB don’t matter. In the below picture the array of letter ‘b‘ is placed against address ranging from 0x40 to 0x47. Row-1 is placed at address 0x40, row-2 is placed at 0x41, then row-3 is placed at 0x42 and so on until row-7 against address 0x47.

CG-RAM address with Character commands

CG-RAM address with Character commands
 
In the above figure byte address is the address of particular byte of character. Since each custom character is made up of 8 bytes. So each byte address with the value loaded in it is given. The above method is universal. You can generate self made characters in character lcd of any size using the same above method.
 

Sample c++ code to generate custom character in cg-ram


lcdcommand(0x40); //Notifying CG-RAM for incoming custom character and its address

while(i!=7) //Placing 'b' By sending 'b' pattern to cg-ram
{
lcddata(b[i]);
i++;
}

lcdcommand(0); //We placed 'b' at first address of CG-RAM so in order to print it send 0 to lcd
char b[7]={0x10,0x10,0x16,0x19,0x11,0x11,0x1E}; //'b' character pattern placed in code

The above task is just a simple demo. We properly have to select the data and command registers of lcd in order to place the custom image in CG-RAM. 

Important: Just to let you know that commands(like 0x40 address of cg-ram) are send to command register of lcd and data like ‘b‘ pattern is send to data register of lcd.

The above code can be divide in to steps

 

  • Send cg-ram character starting address where you want to create character. I send 0x40 in the above code which means i am placing character in first location.
  • Now put your character at this address. Send the ‘b‘ character array string defined above one by one to data register of lcd.
  • To print the generated character at 0x40. Send command 0 to command register of lcd.

 

Part 1: https://www.engineersgarage.com/making-custom-characters-on-16x2-lcd/


 

 


Thứ Hai, 20 tháng 12, 2021

Special symbols on LCD 16x02, Arduino

Objectives

    • We are going to connect a 16×2 LCD display to our Arduino.
    • We will see how to show information on the display
    • We will see how to define some special characters

Bill of materials

Arduino UNO

Arduino Uno or equivalent. This chapter accepts any other Arduino board.

Breadboard

A solderless Breadboard.

Jumper wires

Some jumper wires.

10 K Potentiometer

A Potentiometer.

16x2 LCD Display

A 16×2 or 16×4 LCD display.

LCD displays

The 7-segment LED displays, we saw in the previous chapter, are fine, they are cheap and practical, but have the disadvantage that they can not display text messages, only numbers.

But we can miss some system to display simple text messages, and so the LCD displays were built. They are easy to find in different formats: 16 × 2 (16 columns x 2 rows) or 16 × 4 (16 columns x4 rows).

  • LCD stands for Liquid Crystal Display.
 They are a very simple option and also give a very pro touch to your projects, so, in recent years, the LCD displays have gained wide acceptance in commercial products of all kind.

Basically because:

  • They are cheap.
  • They are available in several sizes and configurations.
  • They are low consumption devices.
  • They are very practical, if you only have to show alphanumeric characters (and perhaps some special characters).

In this chapter we will see how to connect them to your Duinos and how to use them to send messages to the outside world.

BEFORE STARTING

Although, lately, these displays are usually sold with the pin strip welded, there are still many places that sell them as a kit, with the pin strip unwelded.

  • At some point we will have to talk about how to weld components, but that day has not yet arrived..
16x2 lcd display with pin header

 

The first thing you have to know is that you do have to weld them, you can not just stick them together more or less wildly. You do have to weld them. Get used to it. Any other solution would end up malfunctioning or directly burning out the display.

When you have it ready, stick the display on the breadboard, leaving room for other components and wires. Remember that there will be many of them, so be generous with the room you leave.

CIRCUIT WIRING DIAGRAM

Here you have the circuit wiring diagram:

Chapter 41, schematic diagram

And this is the wiring diagram for the solderless breadboard:

Chapter 41, wiring diagram

The connection is not complicated, but you have to be careful. So let’s go step by step connecting the different cables. Start connecting Vcc and GND to the breadboard.

Chapter 41, wiring diagram - step 1

Let’s now power up the LCD panel. Connect the pin16 of the LCD to Ground and the pin 15 to 5V

Chapter 41, wiring diagram - step 2

If you connect now the USB cable to your Duino, the LCD should light, if not, check your wires before proceeding.

Let’s connect now the adjustment potentiometer. Connect one end of the pot to GND, the other end to 5V and the center pin to the pin 3 of the LCD.

We will also take advantage to turn on the LCD panel, so connect the pin 1 to GND and the Vcc to pin 2:

Chapter 41, wiring diagram - step 3

If all went well, we can turn the display and test it. Connect the USB to your Arduino and let’s see. If you’re turning the potentiometer, at some point you have to see some squares on the screen, otherwise check the connections. Do not go ahead if you do not see it.

16x2 LCD display squares

If you see the arrays of dots on the screen, we can continue.

We will now connect the data and control pins. Without going into many details, we will not use all available pins because we do not need them. We will only use two control pins, RS (Register Select) and EN (Enable), and the 4 data pins D7, D6, D5 and D4. We do not need more for now.

Let’s keep on with the control connections:

RW, LCD pin 5             GND
RS, LCD pin 4             Arduino pin 7
EN, LCD pin 6             Arduino pin 8

And now the data wires.

DB7, LCD pin 14          Arduino pin 12
DB6, LCD pin 13          Arduino pin 11
DB5, LCD pin 12          Arduino pin 10
DB4, LCD pin 11          Arduino pin  9
chapter 41, wiring diagram - step 4

 

THE CONTROL PROGRAM

Let’s use a library to control the LCD display, which is included in our Arduino. Go to:

\\Sketch\Add library...\LiquidCrystal

And now we can import one of the examples or write our own sketch, commenting the code. when we import the library we will see the following line:

#include <LiquidCrystal.h>

Then, you must initialize the library. To do it we create an LiquidCrystal object instance, called LCD, and pass it as parameters the pins that have defined:

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //    ( RS, EN, d4, d5, d6, d7) 
  • Be careful because the pins that have used do not correspond to the pins used in the examples of the LiquidCrystal library. You can change them, given the case, but ensure that you also change the pins in the definition, or the sketch will not run..

The rest is easy.

void setup()  
   {
       lcd.begin(16, 2);            // Set the number of rows and columns 
       lcd.print("Prometec.org");   // Send the message
   }

void loop() 
   {
       lcd.setCursor(0, 8);         // Set the cursor to column 0, line 1
       lcd.print(millis() / 1000);  // Print the number of seconds since reset:
   }
 Watch out: as always the first line, the one on the top, is the line 0 and the second is the line 1.

These display are hard to wire, but very simple to use.

Let’s try to make a clock (very simple so far). If you remember the functions we have used in recent chapters, we can recover some of them to show the value of the millis() function as if it were a clock.

Sketch 41.1
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() 
   {
       lcd.begin(16, 2);           // Set the number of rows and columns 
       lcd.print("Prometec.org");  // Send the message
   }

void loop()
   {
       lcd.setCursor(6, 1);        // Locate the position in the row 1, column 6
       String s = clock();
       lcd.print(s) ;
   }
String reloj()
   {
       int n = millis() / 1000 ;    // We convert it to seconds
       int seconds = n % 60  ;
       int minutes =  n / 60  ;

       String S = String(minutes) + ":" + String(seconds);
       return (S);
   }

It is worth commenting some things in this code. First, in the clock function we have calculated the minutes and seconds from the Arduino internal clock in milliseconds, there is nothing new here. But look, we have defined clock as a String variable:

String clock()

That means that we will return a String type parameter. At some point the function will have to use a return (String) statement.

Notice that we have defined a string called s within the function:

String S = String(minutes) + ":" + String(seconds);

In this line you should not confuse (though they are written exactly the same), the String type used to define the string variable S on the left, with the String(n) function, that converts a number n in a text string, so we can concatenate the number of minutes and seconds into a text string using a semicolon character.

At the end we add a couple of blank spaces, to avoid dragging ghosts on the screen

  • Remove the blank spaces and look what happens when minutes change. How would you solve it, without using the trick of putting those blank spaces at the end? Think about it.

Inside the loop() function, we have used the following statement to show the text string:

lcd.print(s) ;

Everything that you already know of the Serial.print() function is equally valid for this instruction. And finally, we have the following line:

lcd.setCursor(6, 1);    // Ponte en la line 1, posicion 6

What it does is to position the cursor on the display, in the column 6 of the second line to write the time centered. Here you have a mini video with the result.

The LCD library includes several interesting examples that you should try. Remember, you have simply to change the definitions of the pins in order to work properly..

A particularly interesting example is CustomCharacter, which defines a set of special characters and moves them around the screen, depending on the values read from a potentiometer.

Without going into too much sophistication, it is very interesting to see how to define some special characters, because in the character’s table of the LCD are not included symbols as ñ, accents, degrees or even €. So, just in case, it could be interesting to know how to define your own symbols.

DEFINING OUR OWN CHARACTERS

Let’s define our own character, the degree symbol, for example.

The first thing you have to know is that the characters are defined as an 8 × 8 array (yes, again), as if you draw it in a grid of that size, filling the full little square.

For example, in order to draw the degree symbol we will define it this way:

Degree symbol
byte degree[8] =
 {
    0b00001100,     // We define them as binary numbers 0bxxxxxxx
    0b00010010,
    0b00010010,
    0b00001100,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000
 };

To load the character in the character’s table of the LCD we will use the following statement:

lcd.createChar(0, euro);
lcd.createChar(1, degree);

And now it is already available. Please note that we can only define eight special characters in a given time (although we can define 30 arrays of characters, create them and destruct them on the fly).

Here is an example of the sketch:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

byte degree[8] =
 {
     0b00001100,
     0b00010010,
     0b00010010,
     0b00001100,
     0b00000000,
     0b00000000,
     0b00000000,
     0b00000000
 };

void setup() 
  {
      lcd.begin(16, 2); // We initialize the LCD
      lcd.createChar(1, degree);
      lcd.setCursor(0, 0); 
      lcd.print("Temperature 25"); 
      lcd.write(1);
      lcd.print("C");
} 

void loop() { }

And here you have a photograph showing the result:

Grados

Finally, and to close the chapter (everything comes in life), I have to tell you again that we have assembled this display in the hard way, connecting a lot of wires.

All this work can only be justified because one day I swallowed the bait and bought a one of these displays (actually two. I have also a 16 × 4 display), but if you are going to buy an LCD display, for God’s sake, buy one I2C display or something like that, your mental health will improve a lot and you will only have to use 4 wires.

In the next chapter we will assemble one of them for you to see the difference.

SUMMARY

    • We have seen the 16×2 LCD displays.
      • It has been hard enough to understand that, as an exercise, it is fine, but we’ll see other less laborious ways to use these kind of displays.
    • There exist also 16×4 displays (16 columns and 4 lines), just in case you need more room in the display.
    • They are very comfortable to use because we can print alphanumeric texts directly, like a serial port.
    • We can (and we will have to do it, surely) also define characters and symbols not included in the display.

Sources: http://prometec.org/displays/lcd-displays/