The Web is littered with examples of how to control the standard Hitachi-44780 LCD using an 8051 micro. So, you may ask, “Why bother doing another?”
A bunch of reasons:
I hate everybody else's code. Call it “NIH.” I don't care. There. I've said it. (You'll probably hate my code, too. I understand and accept your judgment.)
Most of the examples I've seen are written in assembly, and quite frankly, I would rather not deal with assembly language if at all possible.
Some of the examples used the nybble interface to the LCD; I wanted to use the byte-wide interface.
Some examples had various latches or other logic between the micro and the LCD; I wanted a glueless interface (at the cost of extra micro port I/O pins).
So, here is my LCD interface code. I compiled this using the Keil C51 compiler, v7.04. My target is the Silicon Labs (Cygnal) C8051F231 micro, but I suppose any 8051 variant with enough free port pins (all eight bits of Port 1 for the data I/O bus plus three control signals) will work. No glue logic between the micro and the LCD is required. I like the Cygnal parts because they have built-in flash and in-circuit emulator support via JTAG, and the RS-232-to-JTAG emulator dongle costs only $65! (Buy the prototyping board for only $99!) I mean, that's a screeeeeeaming deal, especially if you remember having to pay five large for the old ISA-bus Nohau emulator with the bond-out chip. (And you probably also remember blowing up the bondout chip just as a deadline was approaching!)
I used an Optrex DMC-16202NY-LY-AGE (pdf) 16-character by 2-line LCD module, mainly because DigiKey had them in stock and they weren't all that expensive.
The only bit in the code that is Cygnal-specific is in the private
isLcdBusy() function in
lcd.c. The register
PRT1CF is manipulated to allow port 1 to be read as an
header file that holds the function prototypes.
source for LCD interface functions.
header file that holds some convenient constant definitions (used by
lcd.c and not needed by "the outside world")
Note: Updated 9 Jan 2007
To use, simply add
lcd.c to your Keil project, add
lcd.h to whatever sources may call the functions in
lcd.c and off you go. Be sure to call the
function before calling anything else.
My code specifies the following micro port pin-to-LCD-signal assignments:
(bidirectional data bus)
Oh, yeah, don't forget to wire the micro to the LCD pins, and make sure the LCD bias is set to something that will actually display the characters. Powering the LCD helps, too.
I can probably help you get this code working on your particular 8051 flavor. Send me a note at email@example.com. I've built things using the original Intel 87C51, the Dallas Semiconductor (now Maxim) DS5000T, the TI TUSB3200A and the aforementioned Cygnal chip. Sorry, can't help you with Moto HC05/08/11 or PIC or any other microcontroller family, but hey, a micro is a micro, so porting the code oughta be fairly obvious.
Some real good LCD interfacing info is available at Myke Predko's LCD Interfacing Reference Page.
The good folks at 8052.com have a really good tutorial you might like to read.
Also, see Peer's LCD Pages.
I've played with the Small Device C Compiler (sdcc) but its syntax is not (or at least wasn't, last time I looked) compatible with Keil. Good luck if you choose to use it.
I cannot help you do your homework assignment, so please don't ask. Pester the people at news:comp.arch.embedded instead.
Disclaimer and copyright.
This code is © 2004 by Andy Peters, ASP Digital. All rights reserved. I suppose that this code is now officially Open Source, and while I am not up-to-date on the differences between the GPL, the LGPL, the BSD and other open-source licenses, I'm sure that at least one of them applies. You may use this code as you see fit. If you use it, please drop me a note at firstname.lastname@example.org and tell me! If you publish it, make sure to include my copyright information.
I make no guarantees or warranties whatsoever about this code. (In other words, if you use it as part of a flight-control system and the plane crashes, it is not my fault. You should have done your due diligence and some proper testing.) I also do not warrant that this code is free of anyone's intellectual property claims.