Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple 4-bit LCD display interface help

Status
Not open for further replies.

aj9999

Junior Member level 3
Joined
Feb 5, 2010
Messages
28
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
Missouri
Activity points
1,456
Simple 4-bit LCD help

Hi, Im new to the PIC world and i am trying to get the LCD working on a PICDEM 2+ board with a pic1854520 using the C18 compiler. The code below doesnt work and I believe it has to do with breaking the 8bit character into two nibbles. I have searched numerous examples online but i cant seem to get any of them working or they are too complex for me to modify. If anyone can point out my mistake i would appreciate it.


#include <p18f4520.h>
#include <delay.h>

int result;
void LCD_init(void);
void LCD_cntrl(char);
void LCD_data(char);

#define LCD_DATA PORTD
#define LCD_RW PORTDbits.RD5
#define LCD_RS PORTDbits.RD4
#define LCD_E PORTDbits.RD6
#define LCD_PWR PORTDbits.RD7

unsigned char temp_l=0, temp_h=0;

void main()
{
TRISD = 0x00;
TRISB = 0x00;
TRISD = 0x00;
TRISE = 0x00;
PORTB = 0x00;
PORTD = 0x00;

LCD_init();

while(1)
{
LCD_data("a");
PORTBbits.RB1 = 1; //test to see if code is running
}

}
void LCD_init(void)
{
LCD_PWR = 1;
msdelay(1);
LCD_cntrl(0x20); // sets 4 bit mode
msdelay(5);
LCD_cntrl(0x28); //display shift
LCD_cntrl(0x0f); //display on with blink
LCD_cntrl(0x02); //set cursor position to zero

}

void LCD_cntrl(char x)
{
LCD_RW=0;
LCD_RS=0;
temp_l = x & 0x0f;
temp_h = x>>4;
LCD_E=1;
LCD_DATA= PORTD | temp_l;
msdelay(1);
LCD_E=0;
msdelay(1);
LCD_E=1;
LCD_DATA= PORTD | temp_h;
msdelay(1);
LCD_E=0;
msdelay(1);
}

void LCD_data(char x)
{
LCD_RW=0;
LCD_RS=1;
temp_l = x & 0x0f;
temp_h = x>>4;
LCD_E=1;
LCD_DATA = PORTD | temp_l;
msdelay(1);
LCD_E=0;
msdelay(1);
LCD_E=1;
LCD_DATA = PORTD | temp_h;
msdelay(1);
LCD_E=0;
msdelay(1);
}
 

Simple 4-bit LCD help

Seems the initialization is not proper.

Nandhu
 

Re: Simple 4-bit LCD help

I don't know which LCD controller your're using, but in controllers like ST7036 you've to transfer first the 4 high order bits, then the 4 low order bits.
You should check that in the datasheet.

Second problem: when writing to the data port you're reading the complete port, then OR the data nibble to it. But this way the old value is kept.
Perhaps you should write something like this:
LCD_DATA= (PORTD & 0xF0) | temp_l;
 

Re: Simple 4-bit LCD help

Thanks guys I appreciate the help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top