View Full Version : Interfacing to "parallel" LCDs
kbanks
09-23-2008, 06:00 PM
"Interfacing to LCD Displays" has been on our "TODO" list of Application Notes for a while now. We built up two prototypes, and wrote both 4-bit and 8-bit scripts to drive them. We are just missing the documentation.
Because several people have been asking if SNAPpy can control these types of displays, I am going ahead and posting the example scripts now.
Those of you "hardware savvy" enough to wire an LCD display to your RF Engine should be able to understand the example scripts, even without the missing Application Note.
martinnossel
10-03-2008, 01:23 AM
After a day of learning and debugging I got a LCD to work with the 4 bit bus.
I hope this note will save others the time.
The main problem is lack of schematics. The software example implies (I thought) that the port is mapped to the GPIO pins as register 4.0 t GPIO 11 and as register 4.7t GPIO 18.
This is because the sample code for a bit bus is …
"""write specified upper nibble on LCD bits D7-D4"""
print "hiNibble=",hiNibble
poke(0x04, (peek(0x04) & 0x0f) | hiNibble)
and for the 8 bit is
poke(0x04, val) # Using GPIO 11-18 as the "data bus" makes this easy and efficient
Unfortunately I messed around for a day before, I decided to bother with a scope. At which point I noticed that there was no output on GPIO 15 to 18 (which I assumed was the high nibble). But is not it’s the low nibble and its also backwards.
Bit 0 is GPIO 18
Bit 4 is GPIO 11.
Anyway I made the changes to the software, only to find the display was blank. (took me a while to realize that that’s what happens when the curser is set off and blinking is off) I was still sending commands to try and initialized the $#@& thing and only wrote characters by mistake an saw thing working.
I used GPIO 11 to 18 leaving the 4 ADC inputs which I need.
I changed this routine (hiNibble shoyld be loNibble)
def writeNibble(hiNibble):
"""write specified upper nibble on LCD bits D7-D4
poke(0x04, val) # Using GPIO 11-18 as the "data bus" makes this easy and efficient"""
writePin(ePin, True)
print "hiNibble=",hiNibble
poke(0x04, ((peek(0x04) & 0xf0)) | hiNibble)
# a negative pulse on the "E" pin transfers the data
writePin(ePin, False)
writePin(ePin, True)
def writeData(val):
"""used internally"""
print "val=",val
upperNibble = val & 0xf0
upperNibble >>= 4 # we need it on the lower 4 bits
lowerNibble = val & 0x0f
#lowerNibble <<= 4 # we need it on the upper 4 bits original
writeNibble(upperNibble)
writeNibble(lowerNibble)
I do have a question though on generating delays ‘inline’. I wasted most of the time trying to get delays between initialization commands (as I thought the display was not initilising). See delays recommended by this page
http://esd.cs.ucr.edu/labs/interface/fig4bit.gif (http://esd.cs.ucr.edu/labs/interface/fig4bit.gif)
is there an easy msec_delay(milliseconds) routine?.
Their may be other small things needed, my test program is a big mess.
Martin
PS
Permanent loops in the start up routine, I found, can oly be fixed with a serial update of the firmware, and even that need power removed a few times whike rhe reload was starting (or trying to)!
kbanks
10-03-2008, 01:54 PM
Is there an easy msec_delay(milliseconds) routine?
No, when you start needing to control the timing of things you should use a Finite State Machine driven off of the HOOK_100MS.
martinnossel
10-03-2008, 03:31 PM
I tried to do a delay by reading a variable in a while loop. The variable was incremented in the HOOK_100MS ‘interrupt”. This unfortunately locked up the module.
def poll100ms(msTick):
global cc,secondCounter, LED_PIN
cc += 1
def startupEvent():
"""This is hooked into the HOOK_STARTUP event"""
global secondCounter, LED_PIN, BUTTON_PIN, BUZZER_PIN, ADC_PIN_4, ADC_PIN_5, rsPin, ePin,cc
…
…
cc = 0;
while cc < 2: #delay
dummy=1 # or something like this
writeNibble(0x20) # initial switch from 8-bit to 4-bit mode
cc is global. Why does this not work? Is the startupEvent(): run before the interrupts initialized?
Thanks
Martin
kbanks
10-03-2008, 06:34 PM
You are not supposed to be looping like that in your SNAPpy scripts.
SNAPpy is non-preemptive, if you are in a loop in one part of your script then no other parts of your script are being allowed to run. This includes HOOK_100MS, HOOK_GPIN, etc.
Have the HOOK_100MS do the actions for you, instead of trying to just derive timing from it.
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.