Home » PIC Microcontroller » Source Code Examples » Simple LCD Display Using A Lookup Table
 















What Is It:
This circuit and source code is a very basic introduction to using LCD's using 'Lookup' Tables.
Basic knowledge on how to use Character LCD's for this example is recommended.
Picture:
How It Works:
Before I start, I need to make anyone reading this aware that I am using a 2x16 LCD with a Hitachi 44780 Driver. Majority of character LCD's use this driver so you shouldn't have a problem with this information.

This Source Code Example focuses on using 'Lookup Tables' for LCD's. It doesn't explain in depth how the LCD works or how to interface to it.
Lookup Tables can be very useful in shrinking a program size down slightly, especially when many different words need to be displayed.

To display anything on an LCD, firstly the LCD has to be initialised or configured.
(Referring to the ASM program listed below under 'Source Files') After the I/O pins have been configured on the PIC (SETIO routine), and we have moved to the MAIN_PROGRAM routine, the INITIALISE_LCD routine is called.
Within this routine, 2 Commands are sent to the LCD after the RS (register select) line has been lowered (Command Mode). These Commands are "8-Bit Mode, 2 Line, 5x7 Dot Matrix" and "Display On, Cursor Underline Off, Blink Off".
With the LCD now configured, we can enter Character Mode and send some characters to the display.

But first!
Before my program displays characters, you will notice the first character (H) is not at position 0x00 on the LCD. I used a Cursor Address Command to move the cursor to position 0x05 and this is done with the MOVE_CURSOR_05 routine.

My program then goes to the TYPE_HELLO routine. All this routine does is store a variable in a General Purpose Registers (GPR) and calls the TYPE_IT routine. This value is the Line Number of the Lookup Table the program will start printing from.

The TYPE_IT routine is a little more complicated.
Basically the TYPE_IT routine calls the Lookup Table and returns a value (in this case an ASCII Character) depending on the value in the GPR. Then it moves this character to PORTB.
But before it prints this character on the LCD, the program tests whether the character (or value) returned is a '0'.
If a '0' is returned, we have already printed all the required characters in the text string and the routine finishes.
If a '0' is NOT returned, which means a character we wish to print is present on PORTB, we print it and go back to do it again.
This is the purpose of loading a '0' as the last character of the string in the Lookup Table. It indicates that it has finished printing.
In other words:
1. Get character from the Lookup Table according to value in the GPR and move it to PORTB.
2. Test if the character that is returned is '0'.
If yes, GOTO 5.
If no, continue.
3. Print character.
4. Increment GPR ready for next character, GOTO 1.
5. Finished printing word, RETURN.

This is how the Lookup Table works:
(To see the Lookup Table in the software, click on the ASM link below and look for the CHARACTER_TABLE routine)
Basically a Lookup Table is used to return a specific value.
To do this, before the Table is called a value is loaded into the W register. Then the Table is called.
The first instruction is ADDWF   PCL,F.
ADDWF means add the Working register to File register "". The File register that is specified is the Program Counter.
Therefore X amount of instructions can be skipped depending on the value in the W register BEFORE the Table is called.
This is perfect for printing a string of characters and all we have to do is increment the value in the W register each time the table is called.

If you don't understand yet, don't worry.
Build the circuit, and go through the Source Code instruction by instruction. It is heavily commented to make it clear what is happening.
Have Fun...
Source Files:
Parts List:

Part Quantity
Semiconductors  
PIC16F628A (can use 627A or 648A) 1
2x16 Character LCD with Hitachi 44780 Driver 1
   
Resistors  
100Ω (R1) 1
2.2KΩ (R2) 1
   
Capacitors  
.1μF Multilayer Ceramic (C1) 1
   
Miscellaneous  
-  
   
Hardware  
Breadboard 1
   
*Note. All circuits require a regulated 5 Volt supply unless othwise stated.
       
 
Any questions? Go to the contact page and fill out the contact form, or Email: jakeselectronics@hotmail.com //
Find me on: My eBay Store MySpace YouTube