Sunday 29 May 2011

LCD Tutorial 5

Modified character entry source code


The previous tutorial taught you how to implement the character mode and the code is very simple.  If you have not seen it, please check 'Tutorial Four' out before starting here.  This time, six function prototypes have been developed because it will save your time to use repetitive codes. The additional function prototypes are:

 character_mode   - It allows you to enter character in your LCD
 display_cursor      - Configures the underline, cursor and blink
 display_address   - Displays character within 2x16 character
  function_mode     - Configures number of line, bit and format
  table_lookup        - A table consists of A to Z and and numbers
  stop                       - No operation


Above the first column is the functional prototype which will be used in the code, the description on the 2nd column explains what each functional prototype actually does.  
 
According to the source code below, the function_set has been configured so that the LCD module will use 2 lines, 8 bits and 5x7 format. The first character will display on $00. If you look the fourth line in the command mode table in tutorial, 0x08 would represent that cursor, underline and blink have been disabled. 

The character_mode function prototype automatically display 'HELLO WORLD' and it uses the table_lookup function prototype in order to find the hexadecimal number for each character. You can put different word between (' ') in the character_mode function prototype. Another display_cursor has been configured in order to enable underline, cursor and blink. Finally stop function prototype use 'while' loop which run endless.

 void main()
{
       // Configue LCD module into 2 lines, 8-Bits and 5x7 Pixels
        function_set();

        // Place character on $00
        display_address(0x80);

        // Blinking and underline cursor
        display_cursor(0x08);

        // Enter characters         character_mode(''HELLO WORLD");

        // Blinking and underline cursor
        display_cursor(0x0F);

        // Stop there
        stop();
}



Since there are only 16 character in each line, so it would not show the word with more than 16 letters. In the same source code, it has been devised to display the 17th character in the second line by using the display_cursor(0xC0); function prototype. Check it out in the character_mode function prototype. Here is an example, let apply 'DEOXYRIBONUCLEIC ACID' in the character_mode in the main program. You should see like this: