Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Interfacing LCD to PIC Microcontroller (PIC16F877)

Status
Not open for further replies.

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
Hello,

Ive been reading up on how to interface an LCD to a pic for a few days now but am still quite confused.. I read from this link: LCD Tutorial for interfacing with Microcontrollers: Introduction : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes but he is using 8051, whereas I also read from thsi place: Mark Crosbie's Homepage and he is using a PIC.

i noticed both sources use different ommands, which one to follow?

also I dont understand how to write the #define commands writte by the 8051 site..

im using sourceboost btw.

I know how to interface it, i mean i know how to connect the pins, its the coding thats getting to me..

suppos i use the initialization commands from here: Initialization: LCD Tutorial for interfacing with Microcontrollers : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes

will this work in sourceboost and for a PIC?

I dont have a LCD plugin to test

---------- Post added at 18:48 ---------- Previous post was at 18:46 ----------

I fogot to mention that Im using C language and know only C language, so no assembly please

---------- Post added at 18:49 ---------- Previous post was at 18:48 ----------

I fogot to mention that Im using C language and know only C language, so no assembly please
 

cubanflyer

Full Member level 5
Joined
Jul 31, 2010
Messages
255
Helped
75
Reputation
152
Reaction score
71
Trophy points
1,308
Location
UK
Activity points
2,501
Check out this link, it explains the sequence of events for controlling the LCD LCD Commands
 

ipunished

Junior Member level 3
Joined
Mar 15, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
United Kingdom
Activity points
1,504
This is the initialization code from the site i linked above: 8051 projects
Code:
#include <AT89X51.H>.
#define LCD_data P2
#define LCD_D7   P2_7
#define LCD_rs   P1_0
#define LCD_rw   P1_1
#define LCD_en   P1_2

void LCD_init()
{
     LCD_data = 0x38;     //Function set: 2 Line, 8-bit, 5x7 dots
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x0F;     //Display on, Curson blinking command
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x01;     //Clear LCD
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x06;     //Entry mode, auto increment with no shift
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_busy();
}

a few questions:

can I use the same code as is in sourceboost for my pic? if not what changes need to be made?

also why is the enable set to high then low? he has done this three times and has set it high then low.

Thanks
 

Zwilorg

Member level 5
Joined
Oct 13, 2010
Messages
89
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,906
if you are programing in C why not use hi tech? it has a free version and it already has a Non Rohs lcd working in the samples directory when you install it.

if you are using a ROHS lcd just tell i will send the proper config code ^^

If you are not changing compiler sorry but i can´t help you...
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
232
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
check this code witten in mplab ide using C-18 toolsuite for pic18f452

#pragma config OSC=HS, OSCS=OFF
#pragma config PWRT=OFF, BOR=ON, BORV=45
#pragma config WDT =OFF
#pragma config DEBUG=OFF,LVP=OFF,STVR=OFF
#include <P18F452.h>
void LcdCommand (unsigned char);
void LcdData (unsigned char);
void Delay (int);
#define LcdByte LATB
#define RegSelect LATDbits.LATD5
#define ReadWrite LATDbits.LATD6
#define Enable LATDbits.LATD7


void main()
{
int count=0;
char Line1[] = "16x2 LCD DISPLAY";
char Line2[] = " WITH PIC18F452!";
LATB=0;
TRISB=0;
LATD=0;
TRISD=0;
Delay (250);
LcdCommand (0x38);
Delay (250);
LcdCommand (0x0E);
Delay (250);
LcdCommand (0x01);
Delay (250);
LcdCommand (0x06);
Delay (250);
while(Line1[count] != '\0')
{
LcdData(Line1[count]);
count++;
}
LcdCommand(0xC0);
count=0;
while(Line2[count] != '\0')
{
LcdData(Line2[count]);
count++;
}
}

void LcdCommand (unsigned char value)
{
LcdByte=value;
RegSelect=0;
ReadWrite=0;
Enable=1;
Delay (50);
Enable=0;
}


void LcdData (unsigned char value)
{
LcdByte=value;
RegSelect=1;
ReadWrite=0;
Enable=1;
Delay (50);
Enable=0;
}


void Delay (int a)
{
unsigned char y;
int i;
for (i=0;i<a;i++)
for (y=0;y<180;y++);
}

---------- Post added at 21:29 ---------- Previous post was at 21:14 ----------

no you cannot use code of 8051 for your pic microcontroller.
 

abidr

Full Member level 5
Joined
Feb 14, 2007
Messages
255
Helped
37
Reputation
74
Reaction score
32
Trophy points
1,308
Location
33 N, 73 E
Activity points
2,682
If you use hitech c or CCS, drivers for a standard HD44780 compliant LCD are in the install directories of both of them, by drivers I mean sample codes.

If you search the forum for "interfacing LCD with 16F877A" I think dozens of thread will come up and in many cased there will be working codes.

I remember posting a working code for the same mcu at edaboard a while ago.
 

dayanpad

Advanced Member level 4
Joined
Mar 23, 2009
Messages
114
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,298
Location
Colombo
Activity points
1,921
If you have mikroC PRO for PIC and open software and see library Manager and click LCD. it has good lesson and example
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top