2001 Microchip Technology Inc.
DS39024B-page 45
LCD.C
Description
// Setup interface to LCD
#ifdef BIT8
// 8-bit interface
DATA_PORT = 0b00110000;
// Function set
cmd(8-bit interface)
#else
// 4-bit interface
#ifdef UPPER
// Upper nibble
interface
DATA_PORT &= 0x0f;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00110000;
#else
// Lower nibble
interface
DATA_PORT &= 0xf0;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00000011;
#endif
#endif
E_PIN = 1;
// Clock the cmd in
DelayFor18TCY();
E_PIN = 0;
// Delay for at least 100us
DelayXLCD();
// Setup interface to LCD
#ifdef BIT8
// 8-bit interface
DATA_PORT = 0b00110000;
// Function set
cmd(8-bit interface)
#else
// 4-bit interface
#ifdef UPPER
// Upper nibble
interface
DATA_PORT &= 0x0f;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00110000;
#else
// Lower nibble
interface
DATA_PORT &= 0xf0;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00000011;
#endif
#endif
E_PIN = 1;
// Clock cmd in
DelayFor18TCY();
E_PIN = 0;
DelayXLCD();
#ifndef BIT8
#ifdef UPPER
// Upper nibble
interface
DATA_PORT &= 0x0f;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00100000;
#else
// Lower nibble
interface
DATA_PORT &= 0xf0;
// Function set
cmd(4-bit interface)
DATA_PORT |= 0b00000010;
#endif