// LCD Interface
// 4-bit Data on RB3-RB0
#undef CLOCK32K
#define FAST_CLOCK
#define LCD_RS RA4
#define LCD_RW RA3
#define LCD_E RA2
#define LCD_Data PORTB
#define LCD_TRIS TRISB
#define NUL 0
#define SPACE 32
//-----------------------------------------------------------
// Display Functions
//------------------------------------------------------------
void LCDrdy(void)
{
#ifdef FAST_CLOCK
char b;
// wait for LCD ready
// read data and wait for bit-7 = 0
LCD_TRIS = 0b00001111;
LCD_RS = 0;
LCD_RW = 1;
do
{
LCD_E = 1;
b = LCD_Data & 0x00001000;
LCD_E = 0;
LCD_E = 1;
LCD_E = 0;
} while (b != 0);
#endif
}
void LCD(char b)
{// send to data register
// send HI-byte, LO-byte
LCDrdy();
LCD_RS = 1;
LCD_RW = 0;
LCD_TRIS = 0b00000000;
LCD_Data = (b >> 4);
LCD_E = 1;
LCD_E = 0;
LCD_Data = b;
LCD_E = 1;
LCD_E = 0;
}
void LCDir(char b)
{
// send to instruction register
// send HI-byte, LO-byte
LCDrdy();
LCD_RS = 0;
LCD_RW = 0;
LCD_TRIS = 0b00000000;
LCD_Data = (b >> 4);
LCD_E = 1;
LCD_E = 0;;
LCD_Data = b;
LCD_E = 1;
LCD_E = 0;
}
void LCDinit(void)
{
// initialize LCD for 4-bit mode
// send $28, $06, $0C, $10
#ifdef FAST_CLOCK
_delay(50000); // 50ms delay
#endif
LCDir(0x28);
LCDir(0x28);
LCDir(0x06);
LCDir(0x0C);
LCDir(0x10);
}
void LCDclr(void)
{
// clear LCD
// send $01
LCDir(0x01);
#ifdef FAST_CLOCK
_delay(2000); //2ms delay
#endif
}
void LCD_Line1(void)
{
LCDir(0x80);
}
void LCD_Line2(void)
{
LCDir(0xC0);
}
void LCD_Posn(int n)
// position n = 0 to 79
// Line 1 begins at n = 0
// Line 2 begins at n = 40
{
if (n < 40)
{
LCDir(0x80 + n);
}
else
{
LCDir(0x80 + n + 24);
}
}
void LCD_Txt(char *s)
{
while (*s)
{
LCD(*s++);
};
}
// End of LCD functions
Sure but you did not tell us if you are using assembler or C. And If C which compiler you are usingHello,
We are currently on LCD interfacing using PIC16f877A and MPLAB. Could someone give me any example source code for this just to get an idea how its done. Thank you.![]()