LCD abd Microcontroller Trouble

Status
Not open for further replies.

gstavrev

New Member
Hello,
I have been sweeping the forums most of the afternoon making progress on an LCD. I have the pic18f4252 and I am trying to make it work with a 2*16 LCD.

This is a link to the LCD data sheet.
**broken link removed**

I am still new to these electronics projects, but to my understanding it isn't the Hitachi 44780, but very similar. This is a link to the driver spec, KS0066U:
http://www.datasheetcatalog.org/datasheet/SamsungElectronic/mXuuzvr.pdf

I am using Microchip's C18 compiler. I wasn't able to get the contrast working at first, but that is taken care of now. Below is my C code. I think I have initialized the LCD correctly, but I am not very positive. It seems to be fine until I tell it to display something. I am able to move the cursor to a desired place, all over the display, but when I tell it to print (which might not be right way) it just moves the cursor.

This is the code: ( Parts of it are taken from a book "PIC Microcontroller and Embedded Systems" by Mazidi/McKinlay/Causey)

Code:
#include <p18cxxx.h>
#define ldata PORTD			// PORTD = LCD data pins
#define rs PORTBbits.RB0	//rs = PORTB.0
#define rw PORTBbits.RB1	//rw = PORTB.1
#define en PORTBbits.RB2	//en = PORTB.2
#define busy PORTDbits.RD7	// busy = PORTD.7

#pragma config WDT = OFF
#pragma config LVP = OFF

void MSDelay(unsigned int itime)
{
	unsigned int i, j;
	for(i = 0; i < itime; i++)
		for ( j = 0; j < 135; j++);
}

void lcdcmd(unsigned char value)
{
	ldata = value;	// put the value on the pins
	rs = 0;
	rw = 0;
	en = 1;		// strobe the enable pin
	MSDelay(1);
	en = 0;
}

void lcddata(unsigned char value)
{
	ldata = value;	// put the value on the pins
	rs = 1;
	rw = 0;
	en = 1;		// strobe the enable pin
	MSDelay(1);
	en = 0;
}

void main(void)
{
	TRISD = 0;		// port D as output
	TRISB = 0; 		// port B as output
	en = 0;			// enable idle low
	MSDelay(250);
	lcdcmd(0x38);	//inti. LCD 2 lines, 5*8 matrix
	MSDelay(250);
	lcdcmd(0x0f);	// set display and cursor visible, and blink
	MSDelay(15);
	lcdcmd(0x01);	// Clear display
	MSDelay(100);
	lcdcmd(0x06);	// set the entry mode / cursor shift
	MSDelay(150);
	lcddata('H');
	MSDelay(250);
}

The second to last command, lcddata('H') appears to just move the cursor to the middle. H = 48 hex, and if I use lcdcmd(0x48) it moves to the same place.


Thanks for the help.

-George
 
I have it taken care of. I had to move the rs, rw, en connections to a different port, from B to C. Would anyone have an idea why? I am using the pic18f4525 with the PICkit2.

Thanks.
 
After only a brief look at your code I wonder if you might have been experiencing a R-M-W (read-modify-write) problem because you were toggling the output port pins (PORTB) instead of the output latch (LATB)?

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