Interfacing an LCD

Status
Not open for further replies.
Hi,
As requested I am going to attach a download file to this posting.
Its written in assembler using MPLAB IDE 7.x, for a 16F877 PIC, running at
4mHz, with a 2/4 line LCD, Hitachi HD44780 controller.

Before the ?expert? programmers start giving me flak, I know that
the program isnt 'optimised', 'rationalised' or 'pasturised' and there
are at least a dozen different ways to do it better, BUT it works and it
will give you are starting point.

When an simple LCD program can be seen up and running, it gives
the novice programmer the opportunity to try 'what if I do this!'.
There is nothing worse than a blank display, it give no clues to the problem.
Its the same as the PC's 'blue screen of death', useless.

Regards
EricG

If I cant get the file to attach I'll post it.
 
Last edited:


That'll probably be it mate. You're right, thinking about it, it is a bit confusing, if you look at LCD init progs on the web, (any language) they'll have after every command/data a 'make 'E' high, wait minimum time (200ns?) make 'E' low. just like a 4094 shiftregister...which on a side note, is handy for making a pseudo-SPI driven display (less I/O's!!, well, 4). Its the low-high transistion that clocks in the data. So ultimately, you'd just have to invert the strobe signal so it goes from low to high AFTER the command/data byte is shown to D7-D0.

I'd worry about '4-bit' mode later on. Those links I posted were more than enough to get me started, especially the 'epemag' pdf's, fantastic introduction to the HD44780.

Good luck sir, maybe now you'll catch the 'LCD bug'....I swear I must have about 45 displays right next to me, why is it so addictive?

Blueteeth
 
LCDs look sexy, that is why!


Well, after the pile of homework i have has gone down, i will give her one last go. Thanks for clarifying what "E" is! So basically what i must do is set "e" low before the command, and set "E" high after it, and THEN pause?
 
Ok... i am just going to say that it didn't work...

Code:
' {$STAMP BS2}
' {$PBASIC 2.5}

OUTPUT 0   '\
OUTPUT 1   ' \
OUTPUT 2   '  \
OUTPUT 3   '   \_ This sets the low ouputs (0-7) to an output
OUTPUT 4   '   /
OUTPUT 5   '  /
OUTPUT 6   ' /
OUTPUT 7   '/

en CON 6   '
rs CON 4   ' Defines whether it is a command or if it is data...

PAUSE 1000
HIGH en
LOW rs
OUTL = %00110000
LOW en


PAUSE 500
HIGH en
LOW rs
OUTL = %00110000
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00110000
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00110000
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00001000
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00000001
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00000110
LOW en

PAUSE 1000
HIGH en
HIGH rs
OUTL = %00100110
LOW en

DO
LOOP



Sorry the code isn't commented, but it follows one of the flowcharts... Please help. It is really making me mad...
 
Hi,

I know nothing about basic stamps or the code used for them, but it seems like quite a nice language, well, I can follow it at least.

'E' is meant to be sent high, then low, after the command is sent. And any delays between commands should come AFTER 'E' has gone from low to high. Because thats when the instruction is read in by the display.Although looking at the code, there are pauses between E's, so it 'should' be fine.

looking at this bit:
PAUSE 500
HIGH en
LOW rs
OUTL = %00110000
LOW en

PAUSE 500
HIGH en
LOW rs
OUTL = %00110000
LOW en

You're making E high first, which is 'reading' in the previous command. I would change those instructions to groups like:

LOW rs ; we're sending a command. 0-command, 1-data (characters)
OUTL = %00110000 ; send data to port
HIGH en ; strobe the E
LOW en
PAUSE 500 ; wait a little bit before doing another instruction.

Your omcmand bytes look fine for 8-bit mode. Do you have R/W tied to GND? you're only writing to the display, so you probably won't need it. The numbers for the pauses, are they in microseconds? or miliseconds? Ericgibbs posted the correct delays between instrucitons earlier.

Heres a link I just found with LCD's and basic stamps:
https://www.weethet.nl/english/basicstamp2_lcdcontrol.php

The code on that site looks fine to me, easy to follow to. Should get you up and running......at least with the software. Once initialized then you should see a blank screen...but I'd advise you to turn on the blinking cursor (the commands are in the links I posted) as its truely uplifting to see that little cursor blink before your eyes as if to say 'ready for your commands sah!'

All the best,

Blueteeth
 
IT WORKS!!!!!!!!! Yay!!!!!!!

The only problem is that it is 4 bit mode... oh well...

Is there REALLY a major difference in the two?
 
the stamp language doesn't have built in routines for handling parallel lcds? for example in Proton basic, you output to an LCD with the simple PRINT command, after setting up a few declares - this works for both text-only as well as graphical lcds.
 
I would need the BS2sx or something like that. The BS2 (which is what i have) doesn't support the LCDCMD, LCDIN, and LCDOUT commands. I already tried....
 
in regards to your 4/8 bit question, I think there are two drawbacks

1) in 4 bit mode, each byte written takes two clocks, opposed to a single clock per byte in 8 bit mode

2) having to split the bytes into 4 bit nibbles requires more code

I don't think it's a major issue today, all the micro controllers are so fast, even with a double clock on each byte updates are still faster than the eye can see or the lcd can physically display.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…