Click here to Skip to main content
15,860,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have my PIC 16f690 processor connected to an LCD screen that uses an Hitachi 44780 driver. I would like to use 4 bit mode (since I only have the 4 data lines connected, D4-D7). I have found some ways to do this online, but there is always a couple of differences between them, and none of them seem to work. Maybe the order that I initialize the LCD is not correct. Any ideas would be great.

Thanks,
GabeA

Here is my code for initializing:

C#
void lcdinit()
{

    RS = 0;
    EN = 0;

    lcdwrite_nibble(0x30);
    delay_ms(50);
    lcdwrite_nibble(0x30);
    delay_ms(1);
    lcdwrite_nibble(0x30);
    delay_ms(1);

    lcdwrite_nibble(0x20);

    delay_ms(1);
    lcdwrite_set(0x28);
    delay_ms(20);
    lcdwrite_set(0x08);
    delay_ms(20);
    lcdwrite_set(0x01);
    delay_ms(20);
    lcdwrite_set(0x07);
    delay_ms(20);
    lcdwrite_set(0x0F);
    delay_ms(20);

}
Posted
Updated 4-Jun-12 8:02am
v2

 
Share this answer
 
Comments
GabeA 4-Jun-12 13:15pm    
Ok, so when it says to write a nibble with hex value 0x03, this does not make sense to me because 0x03 is a full byte, and if only the higher 4 bits are connected to the LCD screen, then it will read only 0x0 and not 0x03.
JackDingler 4-Jun-12 14:27pm    
With 4 bits, you can write a value from 0x00 to 0x0F.

0000 = 0x00
0001 = 0x01
0010 = 0x02
0011 = 0x03
0100 = 0x04
0101 = 0x05
0110 = 0x06
0111 = 0x07
1000 = 0x08
1001 = 0x09
1010 = 0x0A
1011 = 0x0B
1100 = 0x0C
1101 = 0x0D
1110 = 0x0E
1111 = 0x0F
GabeA 4-Jun-12 14:33pm    
Yes, but not if the 4 bits are the high four bits. I thought that if you write 0x03, then it implies that the binary for that is 0b00000011. So when they say 0x03, they actually mean 00110000, because the higher four bytes are connected to the LCD, and the lower four bits are floating.
JackDingler 4-Jun-12 15:16pm    
Are you connecting the high order bits from the microcontroller to the high order bits of the LCD?

If so, then you'll need to shift left the instructions, 4 bits.

If you connect the 4 lower bits of the micro-controller to the higher order bits of the LCD, then your wiring will perform this shift function, and you don't need to do it in code.

Don't leave the lower four bits floating. Tie them to ground.
GabeA 4-Jun-12 15:55pm    
I have them connected to the higher bits. That means I should send 0x30?
Ok, I figured out why it wasn't working:

Turns out that my I/O ports were all defaulted to analog inputs instead of I/O. So I had to add the command ANSEL = 0. That's it. Lot of time for a silly problem.

Anyway, thanks Jack for the clarification on the high byte - low byte stuff.

- GabeA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900