Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Saturday, September 19, 2015

LCD 16x2 HD44780 Tutorial 3 - Display Address and Shifting

In previous tutorial, we have done displaying a word "AnNyeongHaSeYo!" (Hello in Korean) on LCD 16x2. In this tutorial, I will explain about addressing to DDRAM (Display Data RAM). The function of DDRAM is to store character that displayed on LCD screen. 

HD44780 LCD controller has 128 different addresses for DDRAM, although not all addresses have their own location on LCD screen. Only 80 display locations can be used to store characters. HD44780 is a LCD controller that can be used not just for 16x2 LCD size, but also for other size such as 16x4, 20x2, or 40x2. The display location for all LCD size is also same (80 location). The different is number of location that can displayed on screen. For example, on 16x2 size is only 32 location, but other location still can be used to store character, although not displayed. To displayed that, we can shift the display right or left. This is the address location of DDRAM that displayed on LCD 16x2 size every LCD power on:


When we set the DDRAM address, we also set the LCD cursor. The (0,0) (column, row) location on LCD 16x2 screen is on address 0x00 and (0,1) location is on address 0x40. In fact, we can imagine that the other addresses that not displayed on 16x2 screen is like this:


From picture above, if you noticed, there are missing address from (0x28 - 0x3F) and (0x68 - 0x7F) that can't be use to store characters. Therefore only 80 location of 128 addresses that can be used. From 80 location, we can use display shift, to show location that not show on LCD 16x2 screen (on screen only 32 location is showed). We can do a little experiment to show this LCD behavior.

First, to set LCD cursor/DDRAM address we can use instruction from table on previous post. The instruction is 0x80 + address. So, if we want to set DDRAM to location 0x40, we send 0xC0 or 0b11000000. Don't forget to set RS to LOW and give EN pulse after that.

We can put a character on each location of LCD screen boundary like this:


To shift the display, we can use instruction 0x18 for left scroll or 0xC0 for right scroll. On each EN pulse, the display will be shifted one location. It is important to note that this scrolling is not move characters to new DDRAM addresses location. It just like move whole address block left or right "under" the display screen. The movement of display shift is a complete rotation of display location. Try to move the display until complete rotation left or right, so you can see the result is same as showed on picture above.

If the display locations are not shifted back to original position, then address 0x00 will no longer be at left-hand side of the screen. To get back, we can use the cursor home instruction 0x02 to back to address 0x00 and also shift the address 0x00 to left-hand side of the screen. The clear display instruction does the same as cursor home, but also  clears all the characters from DDRAM.

We can also shift the cursor/DDRAM address by using 0x10 for shift cursor left and 0x14 for shift cursor right. Move cursor is also move the DDRAM/display location address.

1 comment :

  1. DataVan Cubee 615 Display in UAE, 10.4-Inches Second Display in UAE, Second Display in UAE
    https://gccgamers.com/datavan-cubee-615.html
    DataVan 615 Display in UAE, Safe Shopping Multiple Payment Options Express Delivery GCC Gamers Moneyback Guarantee.
    1631687783404-8

    ReplyDelete