Interfacing LCD with HD44780 compatible controller

Started by Roth Markus July 22, 2003
Gents

Wondering if anyone hase some source code available for interfacing a LCD
with HD44780 compatible controller. This would save me the some time to
write the handlers myself.

Thanks, Markus




Try this one. You will need to adjust the addresses for the lcd and ram,
perhaps, but it works with the HD44780 controller

cheers
Nigel At 14:13 03-07-22 +0200, you wrote:
>Gents
>
>Wondering if anyone hase some source code available for interfacing a LCD
>with HD44780 compatible controller. This would save me the some time to
>write the handlers myself.
>
>Thanks, Markus >-------------------- >
>">http://docs.yahoo.com/info/terms/

Nigel W. Johnson
MCSE, Mem.IEEE
VE3ID / G4AJQ
Web site: http://nigel.homelinux.net
If you want me to have it ready yesterday, you'd better come back the day
before and ask me.
----------

*****************************************************************
* BUBTEST.ASM
* This program tests the Technological Arts Seneca Board by randomly filling
* a block of memory with 32 bytes of ASCII codes. It displays them on the LCD
* and proceeds to sort them and re-display them as they change. Each time
* through the loop gives a long beep and then, the program returns to BUFFALO.
*
* Modified for Tech Arts Board with lcd addresses at 1045/6
*
* 2001 11 28 NWJ

******************************************************************
* EQUATES SECTION
******************************************************************
lcddata EQU $1045
lcdcsr EQU lcddata+1
bargrph EQU $1040
led1 EQU $1041
led2 EQU $1042
led3 EQU $1043
led4 EQU $1044
rambase EQU $A000 8k RAM in RAM socket
scsr equ $102e
scdr equ scsr+1
tcount equ $100e

*****************************************************************
* Mainline Section
*****************************************************************
ORG rambase program start addres
lds #rambase+8190
jsr init
JSR inilcd initialize LCD display
LDX #text1 init X pointer to output 1st line
JSR outlcd output text to LCD
JSR iniln2 bring cursor to beginning line2
LDX #text2 init X pointer to output 2nd line
JSR outlcd output text to LCD
jsr random
jsr display
ldaa #30
jsr beep
jsr bubble
ldaa #30
jsr beep
JMP $E000 return to operating system
**************************************************************
* Subroutine Section
**************************************************************
**************************************************************
* RANDOM fills the buffer from buffer to bufend with random?
**************************************************************
random ldx #buffer
getch jsr del_2mS
ldaa tcount
cmpa #$41
blo getch ignore if < 41
cmpa #$5A
bhi getch
staa 0,x
inx
cpx #buffend
bne getch
rts
**************************************************************
* INIT initialises all variables
***************************************************************
init CLR bargrph
CLR led1
CLR led2
CLR led3
CLR led4
ldaa #$7E
staa $C4 evb pseudo vector for sci
ldd #irqisr
std $C5
ldx #$1000
bset $2D,x $20 enable sci interrupts in sccr2
cli
rts
**************************************************************
* BEEP sends a 1000 HZ beep for the duration specified
* in A as hundredths of a second
**************************************************************
beep pshy Enter with A= tenths of seconds to beep
pshx
ldab #10
mul
again jsr tone
subd #1
bne again
pulx
puly
rts

tone ldx #$1000
bset 0,x $10
jsr delay
bclr 0,x $10
jsr delay
rts

delay pshy
ldy #143
loop dey
bne loop
puly
rts
*****************************************************************
*
* bubble - a good, old-fashioned, inefficient bubble sort
*
*****************************************************************
bubble pshx
bubble1 ldx #buffer
clr flag
next ldaa 0,x
cmpa 1,x
bls notnow
ldab 1,x
stab 0,x
staa 1,x
xgdx
stab bargrph
xgdx
jsr leds
inc flag
ldaa #1
jsr beep
jsr display
notnow inx
cpx #buffend-1
bne next
ldaa flag
bne bubble1
pulx
rts
*****************************************************************
* IRQISR - here on interrupt (hopefully only the acia)
*****************************************************************
irqisr ldaa scsr
anda #$20 check rdrf bit
beq exit spurious interrupt, therefore ignore
ldaa scdr
cmpa #3 check if control C
bne exit someone typed something else
sei
jmp $E000 if it is, then stop program
exit rti
*****************************************************************
*
* DISPLAY - displays the ASCII characters in the buffer
*
*****************************************************************
display pshx
jsr inilcd
ldx #buffer
jsr outlcd
jsr iniln2
ldx #buffer+16
jsr outlcd
pulx
rts

*****************************************************************
* INILCD sub - initializes LCD by sending instructions to it,
* which clear the screen, bring the cursor home, increment it
* right, make the cursor off, deal with 8bit data and 2line
* display
*****************************************************************
inilcd PSHX save X register on system stack
LDX #inicod set X-ptr to init instructions for LCD
contini LDAA 0,X get code specified by X-ptr
BEQ doneini if 00(end of code) then done
STAA lcdcsr send instruction to LCD
JSR del_2mS waste two milliseconds
INX
BRA contini continue initializing LCD
doneini PULX get X register from stack
RTS
*****************************************************************
* LEDS takes the data in A and B and displays them on the
* seven segment displays
*****************************************************************
leds psha
pshb
pshx
pshy
asrb
asrb
asrb
asrb
jsr getseg
stab led3 put it out
stab bargrph
tsy
ldab 4,y get another copy of B
andb #$0F
jsr getseg
stab led4
tab put a into b for getseg
asrb
asrb
asrb
asrb
jsr getseg
stab led1
ldab 5,y get another copy of A
andb #$0F
jsr getseg
stab led2
puly
pulx
pulb
pula

*****************************************************************
* GETSEG - get the segment vaules for the lEDS
*****************************************************************
getseg pshx
ldx #segtbl start of segment table
abx index into table
ldab 0,x get segment data
pulx
rts
*****************************************************************
*OUTLCD sub - outputs ASCII characters specified by the *
*X-pointer to LCD display *
*****************************************************************
outlcd PSHX save X register on system stack
PSHA save accumulator A on stack
pshb
clrb using b as a character counter
outtxt LDAA 0,X get char at X-ptr
BEQ donetxt if 00 then text is outputted
cmpb #16 max 16 characters
beq donetxt
STAA lcddata else send character to LCD
JSR del_2mS waste 2 milliseconds
INX point to next character
incb
BRA outtxt continue outputting character
donetxt pulb
PULA get back accumulator A value
PULX get back X register value
RTS return from subroutine
*****************************************************************
*INILN2 sub - brings the cursor to the beginning of line 2 of *
*the LCD *
*****************************************************************
iniln2 PSHA save accumulator A on system stack
LDAA #$C0 get instruction for LCD's line 2
STAA lcdcsr send insturction to LCD
JSR del_2mS waste 2 milliseconds
PULA get back accumulator A value
RTS return from subroutine
*****************************************************************
*DEL_2mS sub - wastes two milliseconds for the LCD's internal *
*processing. *
*****************************************************************
del_2mS PSHY save Y register on system stack
LDY #569 value to waste 2ms
loop2m DEY decrement counter
BNE loop2m if not 0 then continue decrementing
PULY else get Y register from stack
RTS return from subroutine
*****************************************************************
* Data Section *
*****************************************************************
inicod FCB $01,$06,$0C,$38,$00
text1 FCC "You will now see"
FCB $00
text2 FCC "numbers sorting "
FCB $00
flag rmb 1
segtbl fcb $3f '0' lookup table for seven segment leds
fcb $06 '1'
fcb $5B '2'
fcb $4F '3'
fcb $66 '4'
fcb $6D '5'
fcb $7D '6'
fcb $07 '7'
fcb $7F '8'
fcb $67 '9'
fcb $77 'A'
fcb $7c 'b'
fcb $39 'C'
fcb $5E 'd'
fcb $79 'E'
fcb $71 'F'

ORG rambase+4096
buffer rmb 32
buffend fcb 0 END