crocklip
Junior Member level 1
sample LCD code for PIC
Hi,
I'm using HITECH PICC V.3 compiler to program a PIC16f877a. I wish to interface with a standard 16X2 Hitachi LCD.
Anyway, I plan to use a sample program that was supplied with the software. The following code is a routine used to write a byte to the LCD in 4-bit mode.
#define LCD_DATA PORTD
#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c)
{
DelayUs(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}
As you can see, the entire PORTD is used as "LCD_DATA". However I wish to use only bits 2-5 of PORTA as the other bits are already taken up. Considering that I dont really understand the routine I cannot change the code to suit my own! Can someone tell me how I can do this? Probably a silly question but any help would be great!
Hi,
I'm using HITECH PICC V.3 compiler to program a PIC16f877a. I wish to interface with a standard 16X2 Hitachi LCD.
Anyway, I plan to use a sample program that was supplied with the software. The following code is a routine used to write a byte to the LCD in 4-bit mode.
#define LCD_DATA PORTD
#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c)
{
DelayUs(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}
As you can see, the entire PORTD is used as "LCD_DATA". However I wish to use only bits 2-5 of PORTA as the other bits are already taken up. Considering that I dont really understand the routine I cannot change the code to suit my own! Can someone tell me how I can do this? Probably a silly question but any help would be great!