Click here to Skip to main content
12,996,709 members (78,799 online)
Rate this:
Please Sign up or sign in to vote.
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.


Here is my code for initializing:

void lcdinit()
    RS = 0;
    EN = 0;
Posted 4-Jun-12 5:31am
Updated 4-Jun-12 8:02am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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?
JackDingler 4-Jun-12 16:42pm
Yes, 0x30.
JackDingler 4-Jun-12 16:42pm
Or (0x03 << 4)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170609.2 | Last Updated 5 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100