Wednesday 25 May 2011

LCD Tutorial 4

"Hello World"



This tutorial shows you briefly how to enter character in your LCD module. You can enter number or alphabetic character so you need to look up another table called standard LCD character table. Let say we want to enter 'Hello' on second character in the 1st line.


A table above assists you to select the correct upper and lower 4 bits of data.  For example, look for upper 4 bits at the top of the table and the lower 4 bits of data can be found on the far left side. 

'H'            - 01001000 - 0x48
'E'            - 01100101 - 0x55
'L'             - 01101100 - 0z6C
'L'             - 01101100 - 0x6C
'O'            - 01101111 - 0x6F
SPACE   - 01100000 - 0x20
'W'           - 01010111 - 0x57
'O'            - 01100111 - 0x6F
'R'            - 01110010 - 0x72
'L'             - 01101100 - 0x6C
'D'            - 01100100 - 0x64
  
Note that pulse_e function prototype has been added in the main program.  It just activates enable on, few seconds delay then switch enable off.  Please check the codes for more information.

void main()
{
  // Set 8 bits, 2 lines, 5x7 Format  RW=0;
  RS=0;
  DATA=0x3B;
  pulse_e():

  // Display underline, cursor and blink 

  DATA=0x0F;
  pulse_e();
 

  // Display position 1st on 1 line 
  DATA=0x80;
  pulse_e(): 
 

  //Set RS High  
  RS=1; 
  // H  
  DATA=0x48;
  pulse_e();
 
 
  // e  DATA=0x65;
  pulse_e();

  // l

  DATA=0x6C;
  pulse_e();
  // l

  DATA=0x6C;
  pulse_e();
  // o
 
  DATA=0x20;
  pulse_e(); 
 

  //Set RS low  
  RS=0;
  // Display character on 1st position in 2nd line  
  DATA=0xC0;
  pulse_e(): 
 

  //Set RS High  
  RS=1;
  // W  
  DATA=0x6F;
  pulse_e(); 

  // o  
  DATA=0x72;
  pulse_e(); 
 
  // r  
  DATA=0x6C;
  pulse_e(); 
 

  // d 
  DATA=0x64;
  pulse_e();
 

  //Set RS low  
  RS=0;
}