Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Embedded C PIC drivers
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:
 
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 4-Jun-12 6:31am
GabeA190
Edited 4-Jun-12 9:02am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
GabeA at 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 at 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 at 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 at 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 at 4-Jun-12 15:55pm
   
I have them connected to the higher bits. That means I should send 0x30?
JackDingler at 4-Jun-12 16:42pm
   
Yes, 0x30.
JackDingler at 4-Jun-12 16:42pm
   
Or (0x03 << 4)
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 5 Jun 2012
Copyright © CodeProject, 1999-2014
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