Mike - K8LH
Well-Known Member
Hi guys,
I just hooked up a 44780 type LCD to a PIC for the first time a few days ago. No big deal, right? Well, I haven't worked with a 44780 type LCD in about 10 years (on a 68HC12 project) so it was pretty exciting for me when it came to life on the first try (grin). I'm sure all of you know that feeling.
Anyway, I was wondering if anyone was interested in my approach for the 44780 subsystem code (in assembler)? The subsystem is relatively small and includes a PutLCD macro with 'type' and 'data' parameters, an InitLCD subroutine to reset the LCD and place it in 4 bit interface mode, and a low level driver. I'm also using my little 12 word DelayCy() subsystem for LCD write delays because it's easy to setup for almost any clock frequency.
The PutLCD macro only supports five different 'type' parameters at the moment (more to come) but I'm very pleased with it's capabilities so far. The macro automatically sets the LCD 'RS' line before calling the low level driver and it also selects the appropriate LCD write time delay after a write operation (it knows to use a 1.53 msec delay after a Clear or Home command, for example). Here's an example to illustrate how I'm using the macro and subsystem;
What do you think?
Mike
I just hooked up a 44780 type LCD to a PIC for the first time a few days ago. No big deal, right? Well, I haven't worked with a 44780 type LCD in about 10 years (on a 68HC12 project) so it was pretty exciting for me when it came to life on the first try (grin). I'm sure all of you know that feeling.
Anyway, I was wondering if anyone was interested in my approach for the 44780 subsystem code (in assembler)? The subsystem is relatively small and includes a PutLCD macro with 'type' and 'data' parameters, an InitLCD subroutine to reset the LCD and place it in 4 bit interface mode, and a low level driver. I'm also using my little 12 word DelayCy() subsystem for LCD write delays because it's easy to setup for almost any clock frequency.
The PutLCD macro only supports five different 'type' parameters at the moment (more to come) but I'm very pleased with it's capabilities so far. The macro automatically sets the LCD 'RS' line before calling the low level driver and it also selects the appropriate LCD write time delay after a write operation (it knows to use a 1.53 msec delay after a Clear or Home command, for example). Here's an example to illustrate how I'm using the macro and subsystem;
What do you think?
Mike
Code:
;
; 44780 "function set" bit masks
;
m8bits equ b'00110000' ; select 8 bit interface
m4bits equ b'00100000' ; select 4 bit interface
m1line equ b'00100000' ; select 1 line display
m2line equ b'00101000' ; select 2 line display
fon5x7 equ b'00100000' ; select 5x7 font
;******************************************************************
; *
; init 2x16 LCD using the 44780 procedure for a 4 bit interface *
; *
InitLCD
DelayMS(15) ; wait 15 msecs after power up |B0
PutLCD nyb, m8bits ; step 1, 8 bit reset (160 usec) |B0
DelayMS(4) ; wait 4.1 msecs total, then |B0
PutLCD nyb, m8bits ; step 2, 8 bit reset (160 usec) |B0
PutLCD nyb, m8bits ; step 3, 8 bit reset (160 usec) |B0
PutLCD nyb, m4bits ; set 4 bit mode from 8 bit mode |B0
PutLCD cmd, m4bits|m2line|fon5x7 ; "function set" |B0
PutLCD cmd, DispOff ; display, cursor, blink all off |B0
PutLCD cmd, Clear ; clear display (1.53 msecs) |B0
PutLCD cmd, CursInc ; cursor inc, shift off |B0
PutLCD cmd, DispOn ; display on, leave cursor off |B0
PutLCD pwm, 100 ; set 100% backlight brightness |B0
return ; |B0
Code:
;******************************************************************
; *
Main
call InitLCD ; initialize LCD subsystem |B0
PutLCD cmd, line1+0 ; line 1, tab 0 |B0
PutLCD str, "K8LH Photo Timer"
PutLCD cmd, line2+0 ; line 2, tab 0 |B0
PutLCD str, "Off 00:00:23.750"