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.

lcd 4 bit interfacing with 8051

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,380
hello experts please correct the code below
lcd 4 bit interfacing with 8051
Code:
[FONT=Courier New][COLOR=#339933]#include <REGX51.H>[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#339933]#include <stdio.H>[/COLOR]
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#339933]#define LCDPORT P2[/COLOR][/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New]sbit RS = LCDPORT ^ [COLOR=#CC66CC]4[/COLOR];
[/FONT]
[FONT=Courier New]sbit EN = LCDPORT ^ [COLOR=#CC66CC]5[/COLOR];
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] delay[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] msec[COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#993333]int[/COLOR] i, j;
[/FONT]
[FONT=Courier New][COLOR=#B1B100]for[/COLOR] [COLOR=#66CC66]([/COLOR]i = [COLOR=#CC66CC]0[/COLOR]; i < msec; i++[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#B1B100]for[/COLOR] [COLOR=#66CC66]([/COLOR]j = [COLOR=#CC66CC]0[/COLOR]; j < [COLOR=#CC66CC]1275[/COLOR]; j++[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR][/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]EN = [COLOR=#CC66CC]1[/COLOR];
[/FONT]
[FONT=Courier New]    delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]EN = [COLOR=#CC66CC]0[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] dt[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]char[/COLOR] c[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR][/FONT]
[FONT=Courier New]RS = [COLOR=#CC66CC]1[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0f[COLOR=#66CC66])[/COLOR] | EN | RS;
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]    LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0F[COLOR=#66CC66])[/COLOR] | RS[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] cmd[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]char[/COLOR] c[COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]RS = [COLOR=#CC66CC]0[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0f[COLOR=#66CC66])[/COLOR] | EN;
[/FONT]
[FONT=Courier New]    LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0F[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcdclear[COLOR=#66CC66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x01[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]2[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_init[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]15[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]    cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]100[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]    cmd[COLOR=#66CC66]([/COLOR]0x28[COLOR=#66CC66])[/COLOR];			[COLOR=#808080][I]// Function set (4-bit interface, 2 lines, 5*7Pixels)[/I][/COLOR][/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x28[COLOR=#66CC66])[/COLOR];			[COLOR=#808080][I]// Function set (4-bit interface, 2 lines, 5*7Pixels)[/I][/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x0c[COLOR=#66CC66])[/COLOR];			[COLOR=#808080][I]// Make cursorinvisible[/I][/COLOR]
[/FONT]
[FONT=Courier New]lcdclear[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];			[COLOR=#808080][I]// Clear screen[/I][/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x6[COLOR=#66CC66])[/COLOR];			[COLOR=#808080][I]// Set entry Mode(auto increment of cursor)[/I][/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR][/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] [COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#993333]const[/COLOR] [COLOR=#993333]char[/COLOR] *q[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#B1B100]while[/COLOR] [COLOR=#66CC66]([/COLOR]*q[COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]	dt[COLOR=#66CC66]([/COLOR]*q++[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New] 
[/FONT]
[FONT=Courier New]main[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]lcd_init[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = 0x00;
[/FONT]
[FONT=Courier New]    [COLOR=#B1B100]while[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR][/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x80[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"HELLO WORLD"[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0xc0[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"IT IS WORKING:-)"[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
 
Last edited by a moderator:

Hi,

Is this a test??
:-D
 

You didn't give any description of the problem or a schematic.
 

I have doubt how the nibbles sending to the lCD port while the EN and Rs are also nee
Code:
void dt(unsigned char c)

{
RS = 1;

delay(50);

LCDPORT = ((c >> 4) & 0x0f) | EN | RS;

LCDSTROBE();

    LCDPORT = (((c >> 4) & 0x0F) | RS);
 

LCDSTROBE();

}
 

Read the sequence **broken link removed** to see if it helps
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top