LCD Software Help PIC 16F877A

Thread Starter

oiyela

Joined Mar 6, 2012
3
Hi,
I am currently doing my project and i need to test my microcontroller with an LCD screen, i am using HI-tech compiler on mp lab. my code builds but does not display anything or put on the LCD. Please Help
Here is what i mapped the microcontroller pins to

Rich (BB code):
RD4 to LCD_RS
RD5 to LCD_EN

RD0 to LCD_D4
RD1 to LCD_D5
RD2 to LCD_D6
RD3 to LCD_D7

Here is my software:

#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 8000000
#endif

#include	<htc.h>
#include	"lcd.h"

#define	LCD_RS RD4
#define LCD_EN RD5

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

/*
* Clear and home the LCD
*/

void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
LCD_RS = 1;	// write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(char c)
{
LCD_RS = 1;	// write characters
lcd_write( c );
}


/*
* Go to the specified position
*/

void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;



init_value = 0x3;
TRISA=0;
TRISD=0;
LCD_RS = 0;
LCD_EN = 0;


__delay_ms(15);	// wait 15mSec after power applied,
LCD_DATA	 = init_value;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2;	// Four bit mode
LCD_STROBE();

lcd_write(0x28); // Set interface length
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
lcd_clear();	// Clear screen
lcd_write(0x6); // Set entry Mode
}
 
Last edited by a moderator:

t06afre

Joined May 11, 2009
5,934
Can you show your main program also. One thing you must remember. Is that the Hi-Tech C example you use. Use two different ports. One for the control signal and one for the data. If you use the same port for both data and and control. You must modify that example slightly. As a hint take a look on how the control signal LCD_RS are used ;)
 
Top