Saturday, June 6, 2009

LCD to PIC interfacing.

Just as the title says, here's how to connect an hd44780 compliant LCD module to your PIC microcontroller.

I will be using mikroElektronika's mikroBasic for this, . Their BASIC compilers are just fantastic. Moreover, they are free for hobbyists. You can get it here.

For the micro, I am using the 16F628A, configured to run on the 8Mhz internal oscillator.

mikroBasic by default assumes that the wiring between the PIC and the LCD is as follows:
D7 → port.7 (pin13 on the 16F628)
D6 → port.6 (pin12)
D5 → port.5 (pin11)
D4 → port.4 (pin10)
E → port.3 (pin9)
RS → port.2 (pin8)
RW → port.0 (pin6)

The pin-out for commonly found LCD modules is:
Remember, Vss: GND, Vcc:+5v, VLc:GND, VB+ and VB- are for back lighting.

For the code, I used a screen dump here instead of copy-pasting.
Ah, Neatness..(FAIL)

( have to write it ALL OVER. GWAHAHAHAH!)

(Click to enlarge)

As you have probably guessed from the (very) self-documenting source code above, what we want to display on the LCD is enclosed in commas on the 28th line. (My program starts on the 16th line)

And if everything is done according to the above, the end result is, most of the time, a variation of this.

Again, another satisfying moment in the life of the weary experimenter...when something you build from genuine scratch finally manages to concoct an output. In words.

No comments: