where : ibrtses embedded
connecting a LM1100SYL 4x20 LCD to the 8535
assume the LM1100SYL from SOLOMON, a 4x20 LCD with LED backlight being connected as :
; Display
; PORTC :parallel I/O bidirectional
; PD5 : output :RS
; PD6 : output :RW
; PD7 : output :E
then the following macros are used :
.MACRO LCD_E_Lo
cbi portd,7
.ENDMACRO
.MACRO LCD_E_Hi
sbi portd,7
.ENDMACRO
.MACRO LCD_RW_Lo
cbi portd,6
.ENDMACRO
.MACRO LCD_RW_Hi
sbi portd,6
.ENDMACRO
.MACRO LCD_RS_Lo
cbi portd,5
.ENDMACRO
.MACRO LCD_RS_Hi
sbi portd,5
.ENDMACRO
and the code in an own unit :
U1, U2, U3 & temp are in R15 - R25, and my other macros apply
################################################################
;
;module for LCD LM1100SYL
;
; LCD : line1, line3, line2, line 4
;line1 :$00 =0
;line2: $40 =64
;line3: $14 =20
;line4: $54 =84
;
.equ _LCD_Clear =0x01 ;
.equ _LCD_Off =0x08 ;
.equ _LCD_On =0x0C ;
.equ _LCD_OnC =0x0E ;with cursor
.equ _LCD_OnB =0x0D ;with blink
;
;
;
;;wait 100us - 118us
Wait100n:
push u1
push u2
ldi u1,2
wn1: ldi u2,70
wn2: dec u2
brne wn2
dec u1
brne wn1
pop u2
pop u1
ret
;write instruction to LCD, instruction in U1
LCD_WI:
out PortC,U1 ;instruction to port
ser temp
out DDRC,temp ;portC:=output
LCD_RS_Lo
LCD_RW_Lo
LCD_E_Hi
nop
nop
nop
LCD_E_Lo
LCD_RW_Hi
clr temp
out DDRC,temp ;portC:=input
ret
;write data to LCD, data in U1
LCD_WD:
out PortC,U1 ;instruction to port
ser temp
out DDRC,temp ;portC:=output
LCD_RS_Hi
LCD_RW_Lo
LCD_E_Hi
nop
nop
nop
LCD_E_Lo
LCD_RW_Hi
clr temp
out DDRC,temp ;portC:=input
ret
;reads LCD status
LCD_RI:
clr temp
out PORTC,temp
out DDRC,temp ;portC:=input
LCD_RS_Lo
LCD_RW_Hi
LCD_E_Hi
nop
nop
in U1,PortC ;instruction to port
nop
nop
LCD_E_Lo
LCD_RW_Hi
ret
;reads LCD data
LCD_RD:
clr temp
out DDRC,temp ;portC:=input
LCD_RS_Hi
LCD_RW_Hi
LCD_E_Hi
nop
nop
in U1,PortC ;instruction to port
nop
LCD_E_Lo
LCD_RW_Hi
ret
; wait while LCD busy
LCD_wait:
push U1
clr temp
out PORTC,temp
out DDRC,temp ;portC:=input
ww1: LCD_RS_Lo
LCD_RW_Hi
LCD_E_Hi
nop
nop
in U1,PinC ;instruction to port
nop
LCD_E_Lo
LCD_RW_Hi
andi u1,0x80
brne ww1
pop U1
ret
; initialize LCD - more than 15ms after power up
LCD_Init:
; function set
ldi u1,0x3F ; function set
rcall LCD_WI
; wait more than 4.1ms
ldi u1,40
aa2: rcall Wait100n
dec u1
brne aa2
ldi u1,0x3F ; function set
rcall LCD_WI
rcall Wait100n ; wait more than 100us
ldi u1,0x3F ; function set
rcall LCD_WI
rcall wait100n ; wait more than 100us
ldi u1,_LCD_Off ; off
rcall LCD_WI
rcall LCD_wait
ldi u1,_LCD_Clear ;clear
rcall LCD_WI
rcall LCD_wait
ldi u1,0x06 ;increment,
rcall LCD_WI
rcall LCD_wait
ldi u1,_LCD_OnC ;
rcall LCD_WI
rcall LCD_wait
ret
; set LCD adress U1
LCD_Adr:
ori U1,0x80
rcall LCD_WI
rcall LCD_wait
ret
; display char U1
LCD_Char:
rcall LCD_WD
rcall LCD_wait
ret
; display char U1 at adr U2
LCD_CharAtAdr:
push U1
mov U1,U2
ori U1,0x80
rcall LCD_WI
rcall LCD_wait
rcall wait100n
rcall wait100n
pop u1
rcall LCD_WD
rcall LCD_wait
ret
; display char U1 at (x,y) U2,U3
LCD_CharXY:
cpi u3,1 ;test 1st line
brne cxy1
; 1st line
rcall LCD_CharAtAdr
rjmp cxye
cxy1: cpi u3,2 ;test 2ns line
brne cxy2
ldi u3,0x40
add u2,u3
rcall LCD_CharAtAdr
rjmp cxye
cxy2: cpi u3,3 ;test 3rd line
brne cxy3
ldi u3,0x14
add u2,u3
rcall LCD_CharAtAdr
rjmp cxye
cxy3: cpi u3,4 ;test 4th line
brne cxye
ldi u3,0x54
add u2,u3
rcall LCD_CharAtAdr
cxye: ret
;display string Z^ at line U2
LCD_StringY:
push YL
push YH
mov YL,ZL
mov YH,ZH
push U4
push U1
cpi u2,1 ;test 1st line
brne csy1
ldi U1,0
rcall LCD_Adr
ld u4,Z+ ;length
tst U4
breq csye
csl1: ld u1,Z+
rcall LCD_Char
dec u4
brne csl1
rjmp csye
csy1: cpi u2,2 ;test 2ns line
brne csy2
ldi u1,0x40
rcall LCD_Adr
ld u4,Z+
csl2: ld u1,Z+
rcall LCD_Char
dec u4
brne csl2
rjmp csye
csy2: cpi u2,3 ;test 3rd line
brne csy3
ldi u1,0x14
rcall LCD_Adr
ld u4,Z+
csl3: ld u1,Z+
rcall LCD_Char
dec u4
brne csl3
rjmp csye
csy3: cpi u2,4 ;test 4th line
brne csye
ldi u1,0x54
rcall LCD_Adr
ld u4,Z+
csl4: ld u1,Z+
rcall LCD_Char
dec u4
brne csl4
csye: pop U1
pop U4
mov ZL,YL
mov ZH,YH
pop YH
pop YL
ret
; cursor off
LCD_CursorOff:
push U1
ldi U1,_LCD_On
rcall LCD_WI
pop U1
rcall LCD_Wait
ret
; cursor off
LCD_CursorOn:
push U1
ldi U1,_LCD_OnC
rcall LCD_WI
pop U1
rcall LCD_Wait
ret
; set cursor (x,y)=U1,U2
LCD_CursorXY:
rcall LCD_CursorOn
cpi U2,1
brne ccxy1
; cursor on 1st line
rcall LCD_Adr
ret
ccxy1: cpi U2,2
brne ccxy2
; cursor on 2nd line
ldi U2,0x40
add U1,U2
rcall LCD_Adr
ret
ccxy2: cpi U2,3
brne ccxy3
; cursor on 3rd line
ldi U2,0x14
add U1,U2
rcall LCD_Adr
ret
ccxy3: cpi U2,4
brne ccxye
; cursor on 4th line
ldi U2,0x54
add U1,U2
rcall LCD_Adr
ccxye: ret
##########################################################
Questions ?
Suggestions?
Feedback ?
sponsored links
disclaimer
AVR index
embedded software pages
home
last updated: 30.oct.99
Copyright (99,2001) Ing.Büro R.Tschaggelar