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.

Whats wrong with this LCD command FUNCTION?

Status
Not open for further replies.

Naumanpak

Member level 2
Joined
Nov 19, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Pakistan
Activity points
1,635
Experts,

I have this lcd command function but cannot initialize the lcd in 4 bit mode. 8 bit was done without any problems but am struggling to initialize LCD in 4 bit mode.

Code:
void lcd_command(unsigned char command)
{
        rw=0;
        delay_ms(1);
        rs=1;

        PORTB  = PORTB&0x0F;
        PORTB  = PORTB|(command&0xF0);
        enable=1;
        delay_ms(1);
        enable=0;
        
        PORTB  = PORTB&0x0F;
        PORTB  = PORTB|((command<<4)&(0xF0));
        enable=1;
        delay_ms(1);
        enable=0;
}

where,
rs PORTB.RB2
rw PORTB.RB1
enable PORTB.RB0
and D7-D4 are connected to RB&-RB4


thanks
 

Hi,

First of all, RS should be equal to 0 for command transfer.
Other part is seems to be ok. Try with keeping rs=0.

NIKS
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
thanks NIKS, it should be '0' but still doesnt works?

Forgot to mention, Lcd pins D3-D0 are grounded.
 

I don't know C but I believe this LCD manual would help you.
Go to page 7 and look at the table, row - Function Set. D4 (8/4)

Yes, when RS is 0, it means it's in Command mode, where you can use the table in the manual.

Basically, RS+RW should be 0 --> Set D4 as 1 , only, not F --> Toggle Enable...

Then you should be in 4 bit nibble mode, then you need to configure your LCD depending what kind of LCD you have.

Grounding D0-D3 does not make any difference for me in my circuit, good practice I suppose? But I don't think it is required since the LCD will ignore it once in 4 bit mode.

Hope it helps.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
If I am not wrong, you have to write 0010xxxx (D7-D0) to initialize it to 4 bit mode. You could try writing it directly (i.e PORTX = 0010xxxx) before using your lcd_command for other intializations.
It worked for me.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top