Skip to main content

Character LCD Basics





 The General purpose 16x2 or 16x1 char LCD are very easy to interface with any microcontroller , and these lcd are really very cheap and thoroughly available in the whole world. Once you learn how to interface it, it will be the easiest and very reliable output device used by you! More, for micro controller based project, not every time any debugger can be used. All the LCD displays use the same, or any one of the IC s based upon the architecture introduced by Hitachi.
This component is specifically manufactured to be used with microcontrollers, which means that it cannot be activated by standard IC circuits. It is used for displaying different messages on a miniature liquid crystal display. The model described here is for its low price and great capabilities most frequently used in practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in two lines with 16 characters each. It can display all the letters of alphabet, Greek letters, punctuation marks, mathematical symbols etc. It is also possible to display symbols made up by the user. Other useful features include automatic message shift (left and right), cursor appearance, LED backlight etc.





Pin Configuration



LCD Memory

LCD display contains three memory blocks:
  • DDRAM Display Data RAM;
  • CGRAM Character Generator RAM; and
  • CGROM Character Generator ROM.

DDRAM Memory

DDRAM memory is used for storing characters to be displayed. The size of this memory is capable of storing 80 characters. Some memory locations are directly connected to the characters on display.
Everything works quite simply: it is enough to configure the display to increment addresses automatically (shift right) and set the starting address for the message to be displayed (for example 00 hex).
Afterwards, all characters sent through lines D0-D7 will be displayed in the message format we are used to- from left to right. In this case, displaying starts from the first field of the first line because the initial address is 00 hex. If more than 16 characters are sent, then all of them will be memorized, but only the first sixteen characters will be visible. In order to display the rest of them, the shift command should be used. Virtually, everything looks as if the LCD display is a window which shifts left-right over memory locations containing different characters. In reality, this is how the effect of the message shifting over the screen has been created.



If the cursor is on, it appears at the currently addressed location. In other words, when a character appears at the cursor position, it will automatically move to the next addressed location.
This is a sort of RAM memory so that data can be written to and read from it, but its content is irretrievably lost when the power goes off.

CGROM Memory

CGROM memory contains a standard character map with all characters that can be displayed on the screen. Each character is assigned to one memory location:





The addresses of CGROM memory locations match the characters of ASCII. If the program being currently executed encounters a command ‘send character P to port’ then the binary value 0101 0000 appears on the port. This value is the ASCII equivalent to the character P. It is then written to an LCD, which results in displaying the symbol from the 0101 0000 location of CGROM. In other words, the character ‘P’ is displayed. This applies to all letters of alphabet (capitals and small), but not to numbers. As seen on the previous map, addresses of all digits are pushed forward by 48 relative to their values (digit 0 address is 48, digit 1 address is 49, digit 2 address is 50 etc.). Accordingly, in order to display digits correctly it is necessary to add the decimal number 48 to each of them prior to being sent to an LCD.
What is ASCII? From their inception till today, computers can recognize only numbers, but not letters. It means that all data a computer swaps with a peripheral device has a binary format even though the same is recognized by the man as letters (the keyboard is an excellent example). In other words, every character matches a unique combination of zeroes and ones. ASCII is character encoding based on the English alphabet. ASCII code specifies a correspondence between standard character symbols and their numerical equivalents.





CGRAM Memory

Apart from standard characters, the LCD display can also display symbols defined by the user itself. It can be any symbol in the size of 5x8 pixels. RAM memory called CGRAM in the size of 64 bytes enables it.
Memory registers are 8 bits wide, but only 5 lower bits are used. Logic one (1) in every register represents a dimmed dot, while 8 locations grouped together represent one character. It is best illustrated in figure below:






Symbols are usually defined at the beginnig of the program by simple writing zeros and ones to registers of CGRAM memory so that they form desired shapes. In order to display them it is sufficient to specify their address. Pay attention to the first coloumn in the CGROM map of characters. It doesn't contain RAM memory addresses, but symbols being discussed here. In this example, ‘display 0’ means - display ‘č’, ‘display 1’ means - display ‘ž’ etc.







Control and display commands

 

 





Outline
Now the instruction can be divided mainly in four kinds
1)      Function set instructions
2)      Address set instructions
3)      Data transfer instructions with internal RAM
4)      Others
Details of the Instructions
1)      Read Data from RAM
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1
1
D7
D6
D5
D4
D3
D2
D1
D0
Read 8bit binary data from DDRAM/CGRAM
The selection of RAM is set by the previous address set instruction. If the address set instruction of RAM is not performed before this instruction, the data that is read first is invalid, because the direction of AC is not determined. If the RAM data is read several times without RAM address set instruction before read operation, the correct RAM data from the second, but the first data would be incorrect, as there is no time to transfer RAM data. In case of DDRAM read operation, cursor shift instruction plays the same role as DDRAM address set instruction; it also transfers RAM data to the output data registers.
After read operation, the data address counter is automatically increased or decreased by 1 according to the entry mode. After CGRAM read operation, display shift may not be executed properly.
*In case of RAM write operation, AC is increased or decreased by 1 like that of the read operation. In this time AC indicates the next address position, but the previous data can only by the read instruction.
2)      Write data to ram
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1
0
D7
D6
D5
D4
D3
D2
D1
D0
Write binary 8bit data to DDRAM/CGRAM. The selection of CGRAM or DRAM is set by the previous address set instruction; DDRAM address set, CGRAM address set. RAM set instruction can also determine the AC direction to RAM.
After write operation, the address is automatically increased or decreased by 1 according to the entry mode.
3)      Read Busy Flag and Address
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
1
BF
AC6
AC5
AC4
AC3
AC2
AC1
AC0
By making this read out operation, it can be determined if the LCD is performing some internal operation or not. If Busy Flag (BF) is high, some internal operation is going inside the LCD at that particular moment. To perform further operation the data source (e.g. micro controller) must wait for the BF to go low. Here, the address counter value can also be read.
4)      Set DDRAM Address
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
1
AC6
AC5
AC4
AC3
AC2
AC1
AC0
Set DDRAM address to AC, this instruction makes DDRAM data available from MPU. In 1-line display mode, DDRAM address rangers from “00H” to “4FH”. In 2-line display mode, DDRAM address in the first line ranges from “00H” to “27H”, and DDRAM address in the 2nd line is from “40H” to “67H”.
5)      Set CGRAM address
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
1
AC5
AC4
AC3
AC2
AC1
AC0
Set CGRAM address to AC. This instruction makes CGRAM data available from MPU.
6)      Function Set
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
1
DL
N
F
X
X
DL: Interface data length control bit
DL=’1’ means 8bit mode of data transfer.
DL=’0’ means 4bit mode of data transfer
When 4 bit mode is activated, the data needs to be transferred in two parts, first higher 4bits, and then lower 4 bits.
N: display line number control bit
N=’1’ will allows to characters to display in 2-lines
N=’0’ will allows to characters to display in the first line only
F: display font control bit
F=’0’ will use 5×8 dots format display mode
F=’1’ will use 5×11 dots format display mode
7)      Cursor or display Shift
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
1
S/C
R/L
X
X
Without writing or reading the display data, shifting right/left cursor position or display.
This instruction is made to correct or search or display data. During 2-line display mode, cursor moves to the 2nd line after the 40th digit of the 1st line.
When displayed data is shifted repeatedly, each line shifts individually.
When display shift is performed, the contents of the address counter are not changed.

8)      Display On/Off Control
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
1
D
C
B
This instruction controls Display, Cursor and cursor blink.
D: Display On/Off control bit
D=’1’ means entire display is turned on
D=’0’ means entire display is turned off. But Display data remains in DDRAM.
C: cursor On/Off control bit
C=’1’ turns on the cursor
C=’0’ turns off the cursor. But I/D register retains the data
B: Cursor blink On/Off control bit
B=’1’ makes cursor blink periodically.
B=’0’ stops the cursor to blink and cursor looks steady if the Cursor is turned on.

9)      Entry Mode Set
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
1
I/D
SH
This instruction sets the moving direction of cursor and display.
When I/D= ’1’ cursor moves to the right and DDRAM address is increased by 1.
When I/D= ’0’ cursor moves to the left and DDRAM address is decreased by 1.
CGRAM operates in the same way in this setting.

10)   Return Home
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
0
1
X
This instruction sets the address counter to ‘00H’, and returns the cursor to the first column of first line. And if display is shifted previously, this instruction shifts this too. The DDRAM contents don’t change in this instruction.
11)   Clear display
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
0
0
0
0
0
0
0
0
0
1
Clear all the display data by writing “20H” (ASCII code of ‘space’ character) to all DDRAM address, AND set value DDRAM address counter (AC) to “00H”. It returns the cursor to the first column of first line and sets the entry mode to increment mode (I/D=’1’).


8-bit and 4-bit interfacing of LCD

Now the question is how to display data in the LCD or give command to it. There is two modes of data transfer are supported by LCD displays. One is 4bit mode, another is 8 bit mode. To transfer data In 8 bit mode, first put your data in the 8bit bus, then put command in the command bus and then pulse the enable signal.
                To send data in 4bit mode; first put upper 4bit in the 4 bit data bus connected to 4MSB pins of LCD display, then put control signals in the control bus, then pulse the E pin once. Next put the lower 4 bit in the data bus and pulse the E pin again. Here is a flowchart simply describing it.

LCD Connection

Depending on how many lines are used for connecting an LCD to the microcontroller, there are 8-bit and 4-bit LCD modes. The appropriate mode is selected at the beginning of the operation in the process called 'initialization'. The 8-bit LCD mode uses outputs D0- D7 to transfer data as explained on the previous page.
The main purpose of the 4-bit LCD mode is to save valuable I/O pins of the microcontroller. Only 4 higher bits (D4-D7) are used for communication, while others may be left unconnected. Each piece of data is sent to the LCD in two steps- four higher bits are sent first (normally through the lines D4-D7), then four lower bits. Initialization enables the LCD to link and interpret received bits correctly.



Data is rarely read from the LCD (it is mainly transferred from the microcontroller to the LCD) so it is often possible to save an extra I/O pin by simple connecting the R/W pin to the Ground. Such a saving has its price. Messages will be normally displayed, but it will not be possible to read the busy flag since it is not possible to read the display either. Fortunately, there is a simple solution. After sending a character or a command it is important to give the LCD enough time to do its job. Owing to the fact that the execution of a command may last for approximately 1.64mS, it will be sufficient to wait about 2mS for the LCD.

Comments

  1. We are LCD module manufacturer in China and we are supplying Graphic LCD display Module & Character LCDdisplay Module, Dot Matrix LCD display Module etc.

    ReplyDelete
  2. Great article, thanks for sharing such a nice article. Am a great fan of your blog, I Appreciate you to write more interesting articles about bar lcd.

    ReplyDelete
  3. Character Lcd Basics >>>>> Download Now

    >>>>> Download Full

    Character Lcd Basics >>>>> Download LINK

    >>>>> Download Now

    Character Lcd Basics >>>>> Download Full

    >>>>> Download LINK QS

    ReplyDelete

Post a Comment

Popular posts from this blog

PIC 16F877A Microcontroller Based Electronic Lock 16x2LCD 4x3 Keypad

 Circuit Diagram Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller. The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the

Electronic Voting Machine Using 8051 Microcontroller (AT89C51)

  Circuit Electronic voting machine has now replaced the traditional mechanism of voting due to several advantages like security, automatic counting etc. This project presents a way to develop an electronic voting machine which displays the count of votes on a 16x2 LCD interface. A user can get his/her vote register through a set of switches (one for each candidate). After every cast of vote, the subsequent count can be seen on LCD. The circuit uses AT89C51 microcontroller and the code for the project has been written in C. This LCD based electronic voting machine is designed for four candidates. The input part consists of a set of six tactile switches. The switches and 16x2 LCD are interfaced to microcontroller AT89C51 for various operations and displays. The provision of casting votes for the candidates has been provided through four of these switches. These switches are made active high and connected to pins 2-5 (P1^1 – P1^4) of the controller. The remaining two

89C51 Based Digital Thermometer Using DS1820

Introduction The hardware configuration when using multiple 1-Wire temperature sensors like the DS1820 is very simple, as illustrated in the block diagram below. A single-wire bus is used for communication between the microcontroller and the temperature sensor. It is also possible to power the devices direclty via this 1-Wire bus. An almost unlimited number of 1-WireTM devices can be connected to the bus because each device has a unique 64-bit ROM code identifier which is used to address each sensor   Temperature measurement using DS1820 sensor. Use of ‘1-wire’ protocol... Temperature measurement is one of the most common tasks performed by the microcontroller. A DS1820 sensor is used for measurement here. It is capable of measuring temperature in the range of -55 °C to 125 °C with 0.5 °C accuracy. For the purpose of transferring data to the microcontroller, a special type of serial communication called 1-wire is used. Due to a simple and wide use of these sensors, commands us