User Tools

Site Tools


info:lcd_4_bit_interfacing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
info:lcd_4_bit_interfacing [2011/01/15 09:10] tomgeeinfo:lcd_4_bit_interfacing [2011/01/16 11:29] (current) tomgee
Line 20: Line 20:
  
  
-The common steps are:+The steps are:
  
-   1. Mask lower 4-bits+   1. Load high 4-bits on 4 LCD data pins
    2. Send to the LCD port    2. Send to the LCD port
-   3. Send enable signal +   3. Toggle enable signal 
-   4. Mask higher 4-bits+   4. Load lower 4-bits on 4 LCD data pins
    5. Send to LCD port    5. Send to LCD port
-   6. Send enable signal+   6. Toggle enable signal
  
-//The pins used are same as explained earlier +==== C code to perform the above ==== 
-#define lcd_port    P3+   ;In this 4-bit tutorial the LCD is connected to 
 +   ;the controller in following way... 
 +   ;D4 - P3.0 
 +   ;D5 - P3.1 
 +   ;D6 - P3.2 
 +   ;D7 - P3.3 
 +   ;EN - P3.7 
 +   ;RS - P3.5
  
-//LCD Registers addresses +   //The pins used are same as explained earlier 
-#define LCD_EN      0x80 +   #define lcd_port    P3
-#define LCD_RS      0x20+
  
-void lcd_reset() +   //LCD Registers addresses 
-{+   #define LCD_EN      0x80 
 +   #define LCD_RS      0x20 
 + 
 +   void lcd_reset() 
 +   {
         lcd_port = 0xFF;         lcd_port = 0xFF;
         delayms(20);         delayms(20);
Line 52: Line 62:
         lcd_port = 0x02;         lcd_port = 0x02;
         delayms(1);         delayms(1);
-}+   }
  
-void lcd_init () +   void lcd_init () 
-{+   {
         lcd_reset();         // Call LCD reset         lcd_reset();         // Call LCD reset
         lcd_cmd(0x28);       // 4-bit mode - 2 line - 5x7 font.         lcd_cmd(0x28);       // 4-bit mode - 2 line - 5x7 font.
Line 61: Line 71:
         lcd_cmd(0x06);       // Automatic Increment - No Display shift.         lcd_cmd(0x06);       // Automatic Increment - No Display shift.
         lcd_cmd(0x80);       // Address DDRAM with 0 offset 80h.         lcd_cmd(0x80);       // Address DDRAM with 0 offset 80h.
- }+   } 
 + 
 +==== Sending Command/Data to LCD in 4-bit mode ==== 
 + 
 +   void lcd_cmd (char cmd) 
 +   { 
 +        lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN; 
 +        lcd_port = ((cmd >> 4) & 0x0F); 
 + 
 +        lcd_port = (cmd & 0x0F)|LCD_EN; 
 +        lcd_port = (cmd & 0x0F); 
 + 
 +        delayus(200); 
 +        delayus(200); 
 +   } 
 + 
 +   void lcd_data (unsigned char dat) 
 +   { 
 +        lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); 
 +        lcd_port = (((dat >> 4) & 0x0F)|LCD_RS); 
 +        
 +        lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); 
 +        lcd_port = ((dat & 0x0F)|LCD_RS); 
 + 
 +        delayus(200); 
 +        delayus(200); 
 +   }
info/lcd_4_bit_interfacing.1295100602.txt.gz · Last modified: 2011/01/15 09:10 by tomgee