Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing an LCD

Status
Not open for further replies.

Marks256

New Member
I have a 4x20 LCD with a HD44780 controller in it. I can not get the thing to work! I have it connected to my stamp, and i cant the the damn thing to work!

It is REALLY frustrating! I know for a fact that i am over complicating it, but i don't know how to initialize it. This is pissing me off because i know that the HD44780 is one of the simplest controllers available, AND I CAN'T FIGURE IT OUT! :eek:

Does anyone know of a good simple tutorial for a stamp? Or even interfacing it to a parallel port. Basic or C, it doesn't matter to me.

Please shed some light on this SOB, or it will shed some light of its own here pretty soon... :(
 
Initialization is pretty contorted with those things - it's like half a dozen steps with timing/delay requirements. That and if you don't have the contrast setup correctly, you'll never know it's actually doing anything.

What are you using as reference material, and what do you have connected?
 
I can only refer you to my PIC tutorials - it took me a LONG time to get an LCD working properly, and none of the examples I downloaded ever worked.

In the end I started from scratch and wrote my own - reliable and fast!.

It's easier to start off working with 8 bit mode, then once that's working change to 4 bit mode.
 
Hi marks,
Look under electronics projects forum, interfacing 8951 to lcd. I have
posted a reply to another member. The hitachi is a slow device and most
problems arise during initialising it. It requires delays during the first 3
init steps. Let me know which lcd and asm you are using, I'll post a demo
program. ie; 2 or 4 line, 4 or 8 wires, hi or lo nibble, you get the idea.

Regards
EricG
 
It is a PWB20434B-CEM. Standard ios, and 4x20. I have 8 bit sounds great.
 
It took me a week (at 3 hrs a day) to get my first 2x16 LCD working with a pic18f. I still remember the first time it showed signs of life - it said:

IT'S ABOUT TIME!
YOU GENIUS

Just keep at it, make sure that its getting power, you should see the first line of the LCD showing very dim black boxes (i.e. all the pixels on the first line are on, but very dim). Also play around with the pot everytime you test a new piece of code: its amazing how many people can write good code and wire everything up right, but miss turning the damn pot the right way round! Good luck =]
 
NJ Roadmap said:
It took me a week (at 3 hrs a day) to get my first 2x16 LCD working with a pic18f. I still remember the first time it showed signs of life - it said:

IT'S ABOUT TIME!
YOU GENIUS

Just keep at it, make sure that its getting power, you should see the first line of the LCD showing very dim black boxes (i.e. all the pixels on the first line are on, but very dim). Also play around with the pot everytime you test a new piece of code: its amazing how many people can write good code and wire everything up right, but miss turning the damn pot the right way round! Good luck =]

Oh yes, make sure you twiddle that pot! - one way you get all black (on one line if not initialised), the other way nothing at all - if the pots set wrong you won't know it's working.

I can't remember how long it took me to get an LCD working, but it was a considerable time!.
 
What needs to be done for initialization?

1. Power on
2. Set functions to 8 bit, and 8x5 mode
3. What?

Or is it
1. Set functions to 8 bit, and 8x5 mode
2. Power on
3. more...


What needs to be done in what order?

Well i just screwed around with the pot, and this is what happend. So my code must have done something right...

Code:
████████████████████

████████████████████
 
Adjust the contrast pot so that the squares are on the verge of turning black. If you turn the knob all the way, they'll completely turn black, and you won't see anything - too far the other way and they'll stay transparent, and again, you won't see anything. When the LCD is initialized correctly, the first line goes black, and the second line stays transparent (I think...)

Have you seen a block diagram that looks like this:
http://esd.cs.ucr.edu/labs/interface/interface.html

Also if you google around, you should be able to find the original data sheet this came from - I think Optrex might have a copy on their website somewhere.
 
hi marks,

Initialising a Hitachi HD44780 LCD Controller.

Assumed: lcd display, connected with 8 data lines.

NOTE:
Some of the wait times are longer than the lcd manual states.
From experience, the response times of the lcds do vary for devices
of the same type. If you trim down the waits you may find that when
you change an lcd, the new one may display garbage.

The controller is a slow device compared to the MCU, so if you
are using high freq xtal's, nops maybe required to pad out
the write subroutines. This is to ensure that signal timings are
are longer than the minimum required by the lcd.

To initialise the lcd.

1. wait at least 15mSec after powering up the system before
starting the init sequence. [leave the lcd as last device to init]

2. write the cmd 0x38 to the lcd. [0x33 for 2 line lcd]
using call lcdcmd0
- wait 10mSec. rem: you cannot test the BUSY yet.

3. write the cmd 0x38 to the lcd. [0x33 for 2 line lcd]
using call lcdcmd0
- wait 5mSec rem: you cannot test the BUSY yet.

4. write the cmd 0x38 to the lcd. [0x33 for 2 line lcd]
using call lcdcmd0
- wait 1mSec rem: you cannot test the BUSY yet.

6. write the cmd 0x38 to the lcd. [0x33 for 2 line lcd]
using call lcdcmd, will test BUSY_BIT

7. write cmd 0xE0 to the lcd [display ON, cursor ON]
using call lcdcmd, will test BUSY_BIT

8. write cmd 0x02 to the lcd. [home and clear lcd]
using call lcdcmd, will test BUSY_BIT

... init complete


test:
write data, char "X" to lcd

goto test


' the nops with a 4mHz xtal on a PIC are 1uSec long
' by using nops you can stretch the signals to the lcd
' to ensure that they meet the lcd minimum response times.
' for CS thats a min of 1uSec.

;enter with a command byte
lcdcmd:
call lcdbusy
lcdcmd0:
set RS low, cmd state
nop
set RW low
nop
set data lines, b0 to b7 as the cmd code byte
nop
set CS high
nop
set CS low
return

;enter with the char to display.
lcddta:
call lcdbusy
set RS high, data state
set RW low, write
set data lines, b0 to b7 as the char data byte
set CS high
nop
set CS low
return


lcdbusy:
save the cmd or char byte
make data bit 7 an input , to prepare for BUSY check read
lp1:
set CS high
set RS low
set RW low
set CS high

read BUSY, data bit 7
if its high goto lp1, its BUSY

set CS low

make data bit 7 an output
recall saved byte
return


Info for Ref: 16 chars/line display
the start address of line 1 is 0x80
the start address of line 2 is 0xC0
the start address of line 3 is 0x90
the start address of line 4 is 0xD0

Info for Ref: 20 chars/line display
the start address of line 1 is 0x80
the start address of line 2 is 0xC0
the start address of line 3 is 0x94
the start address of line 4 is 0xD4


A 10K contrast pot is required, connected between +5vdd and 0vss
with the wiper to VO [pin3]. The pixel blocks on the lcd should
be visible a some setting of the pot, even if actual characters
are not appearing. If you cannot see the blocks, whatever the
contrast pot is set to, you will never see characters.

Regards
EricG
 
as others have said, I'll echo, as I'm working on a lcd project right now too (serial to parallel backpack)

some LCDs, especially fancy ones, require a negative bias voltage. If you're not seeing the solid line of blocks at powerup, regardless of how much twiddling you're doing, your LCD is one of these.

to give it some negative bias, at least on a breadboard, you need (at least) a single AA battery. connect the positive terminal of the battery to the breadboard GROUND (yes thats right, positive to ground). Now connect the negative terminal of the battery to one end of a pot, with the other end connected to ground. Now you can dial a negative voltage between 0 and -1.5 volts. Most lcd only need -0.3 to -0.7 volts, however, one I've got designed for "cold weather" requires -7 volts.

my backpack design incorporates a charge-pump inverted voltage doubler, producing -10 volts from the +5 rail. a 10k pot delivers +5v to -10v bias to the LCD.
 
No, i see the lines at powerup. My flipping program does nothing. :( I still can't get the thing to work! I mean NOT AT ALL. :mad:
 
Marks256 said:
No, i see the lines at powerup. My flipping program does nothing. :( I still can't get the thing to work! I mean NOT AT ALL. :mad:

As someone suggested, rigging it up to a parallel port on your PC, and using some software like 'lcdsmartie' or something is great way to test the lcd in question. If its working fine, then you can worry about any micro controlling it. Google (image search?) is your friend.

I was fortunate enough to get my first HD44780-like LCD up an running in ten minutes. Was my first real PIC program too (after the mandatory 'blink' prog).
The only errors I made seemed to be hardware related, ie: getting the connections wrong, almost every time :D

A few sites:
http://www.hsg-kl.de/faecher/inf/msr/pic/lcd/init.gif
http://home.iae.nl/users/pouweha/lcd/lcd.shtml
**broken link removed**
**broken link removed**

I simply collected code snippets and went through all of them, working out the delays, and I can honestly say, I haven't had any trouble with commands/delay ericgibbs provided. It seems to be the conventional way.
And once its written, its written, very handy to have a bunch of routines I can just include in future progs.

I never 'read' the display, so the R/W line is tied to GND. So theres only D7-D0, RS (instruction or data) and the strobe line 'E'. So no busy flag is checked, its all maximum delays, which is probably inefficient, but I haven't as yet needed to use it.

I do'nt want to sound patronising but I'll just include some other bits as well, more info is better than less. 5v supply, contrast is usually around 0.8-1.2V, but can be negative, And are the pins numbered? I have a few oddball LCD's that seem to have them the wrong way around.

It could always be that you're LCD is faulty...I *vaguely* remember seeing that part number in a forum somewhere, and they mentioned '1989', so maybe something in it has died.

My two cents,

Blueteeth
 
Are you sure your program has set the I/O lines you're using to outputs? Stamps default to inputs, if you don't change it the best you can do is blink the pullups, and that's inverted logic? Post your code.
 
Hi,
Ref some lcd's requiring a -V thru +V supply to the contrast pot.
A number of graphic lcds I have used in the past did required a -V contrast
voltage. If your MCU pcb has a MAX232 RS232 line driver/receiver, then the
-V can be connected to the -V cap [ about -9v] on the MAX232.
[use a 20k pot, with a 1k in series with the wiper to pin 3, on the lcd pcb]

I don't think the contrast voltage is 'marks' problem, has suggested it could be the hardware. 'Marks' post your program, prefer, the version using MPLAB asm.

Regards
EricG

I am sure someone will crack this problem.
[' like a bat out of hell' right marks]
 
ericgibbs said:
Hi,
Ref some lcd's requiring a -V thru +V supply to the contrast pot.
A number of graphic lcds I have used in the past did required a -V contrast
voltage. If your MCU pcb has a MAX232 RS232 line driver/receiver, then the
-V can be connected to the -V cap [ about -9v] on the MAX232.

good call on using the charge pump inside the max232!
 
ericgibbs said:
like a bat out of hell

Well, at the moment i have "Read 'Em and Weep" cranked. But yeah, you got the general idea... :D



E is strobe? That might be my problem... all of the data sheets i looked at make "E" sound like "Enable"! :rolleyes: So what do i do with strobe? I have always been turning it on at the beginning of my program, and turning it off at the end! Turn it true when i have data on the lines and then turn it off right before i put new data on, and then repeat? I will try it after homework...
 
Heh, if you use pic basic it the whole program would look a little like this;


Code:
Device = 16F876A
XTAL = 4

LCD_DTPIN = PORTB.4	        ' Setup the LCD
LCD_RSPIN = PORTB.2
LCD_ENPIN = PORTB.3
LCD_INTERFACE = 4			
LCD_LINES = 4
LCD_TYPE = 0

Dim RND As Word
Dim Letter As Byte

Seed $0345            ' Start in the center of the random table

DelayMS 150           ' Allow the LCD to warm up
Cls

Select_Letter:

    RND = Random
    
    Select RND
        Case < 10000
            Print At 1, 1, "H    "
        Case < 20000
            Print At 1, 1, " E   "
        Case < 30000
            Print At 1, 1, "  L  "
        Case < 40000
            Print At 1, 1, "   L "
        Case < 50000
            Print At 1, 1, "    O"
        Case > 59999
            GoTo Select_Letter
    EndSelect
    
    DelayMS 500
    
    GoTo Select_Letter

And you would just wire up the LCD the same way you defined its controls in the progam, i.e. **broken link removed**
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top