Help me with changing a code which writes a byte to the LCD

Status
Not open for further replies.

crocklip

Junior Member level 1
Joined
Nov 23, 2005
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,568
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!
 

sample LCD code for PIC

This is a long shot but try this?

#define LCD_DATA PORTA

#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 ) & 0b00111100 );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}



.................................

Under your port initialisation, write down ADCON1= 0b10000010; this is to ake port A I/O port instead of analog. Also, TRISA = 0x00; to make all ports output.
I hope it helps...(Oh ive sent u a pm in need of your help)

Added after 54 seconds:

oops.. this one..

void
lcd_write(unsigned char c)
{
DelayUs(40);
LCD_DATA = ( ( c >> 4 ) & 0b00111100 );
LCD_STROBE();
LCD_DATA = ( c & 0b00111100 );
LCD_STROBE();
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…