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.

[SOLVED] lcd 4 bit error .. trying to interfcing with 8051 in single port

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,601
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,611
Code:
.............................main...................................
[FONT=Courier New][COLOR=#339933]#include <REGX51.H>[/COLOR][/FONT]

[FONT=Courier New][COLOR=#339933]#define LCDPORT P2[/COLOR][/FONT]

[FONT=Courier New]sbit RS = LCDPORT ^ [COLOR=#cc66cc]2[/COLOR];[/FONT]

[FONT=Courier New]sbit E = LCDPORT ^ [COLOR=#cc66cc]3[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#339933]#include "lcd.h"[/COLOR][/FONT]

[FONT=Courier New][COLOR=#993333]void[/COLOR] main[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR][/FONT]

[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]

[FONT=Courier New] [/FONT]

[FONT=Courier New]    lcd_init[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x80[COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_data[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];		[COLOR=#808080][I]// just send "1" to lcd to display ;[/I][/COLOR][/FONT]

[FONT=Courier New]    [COLOR=#b1b100]while[/COLOR] [COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#66cc66]}

[/COLOR]..................................................................................................

 ........................lcd.h.......................

[FONT=Courier New][COLOR=#339933]#include"delay.h"[/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] latch[COLOR=#66cc66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66cc66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]
[FONT=Courier New]    E = [COLOR=#cc66cc]1[/COLOR];[/FONT]
[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    E = [COLOR=#cc66cc]0[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_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]10[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    c = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New]    latch[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] lcd_data[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]10[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    c = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New]    latch[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] 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]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New]    lcd_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]    lcd_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]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x0c[COLOR=#66cc66])[/COLOR];		[COLOR=#808080][I]// Make cursorinvisible[/I][/COLOR][/FONT]
[FONT=Courier New]    lcd_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].......................................................................................................[COLOR=#66cc66]
[/COLOR]
................................ delay.h[COLOR=#66cc66][/COLOR].........................[COLOR=#66cc66]
 
[/COLOR]
[/FONT]


[LIST=1]
[*][FONT=Courier New][COLOR=#993333]void[/COLOR] delay[COLOR=#66cc66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] j[COLOR=#66cc66])[/COLOR][/FONT]

[*][FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]

[*][FONT=Courier New]    [COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] i = [COLOR=#cc66cc]0[/COLOR];[/FONT]

[*][FONT=Courier New]    [COLOR=#b1b100]for[/COLOR] [COLOR=#66cc66]([/COLOR]; i < j; i++[COLOR=#66cc66])[/COLOR];[/FONT]

[*][FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]

[*][FONT=Courier New] 
[/FONT]
[/LIST]
[COLOR=#66cc66]

[/COLOR]
[/FONT]
 
Last edited:

I cant test because delay.h missing......
Which version of Keil compiler you have? Problems is with simulation or ...?
 

printf("Greetings,")
main()
{No delay.h ???}
#include<Good Luck.h> // :p

- - - Updated - - -

Stupid questions are better than stupid mistakes.
Make every stupid/silly mistake you can, in that way you will learn more.
 

I am attaching the whole project file with Proteus
 

Attachments

  • 4bit with single port.rar
    37.9 KB · Views: 116

sir did you look the data masking and shifiting section .I have some doubts there ?
is there correct sending MSB and LSB ?
 
Last edited:


Code C - [expand]
1
2
3
4
LCDPORT = c & 0xf0;
latch();
c = (c << 4);
LCDPORT = c & 0xf0;



Say c = 0xAB

c & 0xF0 = 0A0 which is sent to D4 to D7

c = c << 4 makes c = 0xB0 and

c & 0xF0 becomes 0xB0 which is sent to D4 to D7

so, c = c<< 4 is enough, you don't need c & 0xF0


Code C - [expand]
1
2
3
4
LCDPORT = c & 0xf0;
latch();
c = (c << 4);
LCDPORT = c;

 
I will check out sir and will the result soon
thanks again .
 

Post your whole code and the error window!!!
 

there no error .. now I can debug (due to separate header file i cant debug now okay ).

after build up ,in Proteus there is no output . blank

Code:
[FONT=Courier New][COLOR=#339933]#include <REGX51.H>[/COLOR][/FONT]

[FONT=Courier New][COLOR=#339933]#define LCDPORT P2[/COLOR][/FONT]

[FONT=Courier New]sbit RS = LCDPORT ^ [COLOR=#cc66cc]2[/COLOR];[/FONT]

[FONT=Courier New]sbit E = LCDPORT ^ [COLOR=#cc66cc]3[/COLOR];[/FONT]


[FONT=Courier New][COLOR=#993333]void[/COLOR] delay[COLOR=#66cc66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] itime[COLOR=#66cc66])[/COLOR][/FONT]

[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]

[FONT=Courier New]    [COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] i, j;[/FONT]

[FONT=Courier New]    [COLOR=#b1b100]for[/COLOR] [COLOR=#66cc66]([/COLOR]i = [COLOR=#cc66cc]0[/COLOR]; i < itime; 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] latch[COLOR=#66cc66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66cc66])[/COLOR][/FONT]

[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]

[FONT=Courier New]    E = [COLOR=#cc66cc]1[/COLOR];[/FONT]

[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    E = [COLOR=#cc66cc]0[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]



[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_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]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]

[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    LCDPORT = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]



[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_data[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]2[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    LCDPORT = c & 0xf0;[/FONT]

[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]



[FONT=Courier New]    LCDPORT = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#66cc66]}[/COLOR][/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]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_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]    lcd_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]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x0c[COLOR=#66cc66])[/COLOR];        [COLOR=#808080][I]// Make cursorinvisible[/I][/COLOR][/FONT]

[FONT=Courier New]    lcd_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][COLOR=#993333]void[/COLOR] main[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR][/FONT]

[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]

[FONT=Courier New]    lcd_init[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_cmd[COLOR=#66cc66]([/COLOR]0x80[COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New]    lcd_data[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]2[/COLOR][COLOR=#66cc66])[/COLOR];        [COLOR=#808080][I]// just send "1" to lcd to display ;[/I][/COLOR][/FONT]

[FONT=Courier New]    P3 = 0xf0;[/FONT]

[FONT=Courier New]    [COLOR=#b1b100]while[/COLOR] [COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]

[FONT=Courier New][COLOR=#66cc66]}[/COLOR]
[/FONT]

used diffrent delay whats the wrong with it ?
 
Last edited:

in your program where did u configure your port pins that you have connected to LCD ??
why did you write functions in header file ?
 

yes given P2 = 0x00;
but nothing happens .
i used header file firstly but in keil i cant debug correctly without header file can be check the register value ...


whats the wrong with me ?
 

Code:
#define LCDPORT P2
[COLOR="#008000"]sbit RW = P2^1;[/COLOR]
sbit RS = LCDPORT ^ 2;
sbit E = LCDPORT ^ 3;
Code:
void lcd_cmd(unsigned char c)
{
    
    LCDPORT = c & 0xf0;
    RS = 0;
    RW = 0;
    delay(10);
    latch();
    c = (c << 4);
    LCDPORT = c & 0xf0;
    RS = 0;
    RW = 0;
    delay(10);
    latch();
}
void lcd_data(unsigned char c)
{
    LCDPORT = c & 0xf0;
    RS = 1;
    RW = 0;
    delay(10);
    latch();
    c = (c << 4);
    LCDPORT = c & 0xf0;
    RS = 1;
    RW = 0;
    delay(10);
    latch();
}
 

But sir RW already have connected to ground , is that 0 ?
 

Writing to LCDPORT resets also the lower P2 bits to zero, in this case RS. Means you are always writing to command register, never to data.
Code:
LCDPORT = c & 0xf0;
 
thanks sir ., may i know how to send RS value along with data value . can I use an OR function ?


LCDPORT = c & 0xf4; ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top