LDI R18, $35
STS $D0, R18 ;LOCALIDAD DE LA DIRECCION DEL PUERTO LCD
; envia a pantalla un par de digitos hexagesimales, R20 es el registro con el par de digitos, Z el puerto
printdig2hex:
PUSH R16
PUSH R28
PUSH R29
PUSH R30
PUSH R31
push R20
push R20
LDI R16,$00
lsr R20
lsr R20
lsr R20
lsr R20
PUSH R30
PUSH R31
LDI ZL, LOW(TABLAASCCI) ;EL COMPILADOR HACE UN CORRIMENTO LOGICO A LA LEFT
LDI ZH, HIGH(TABLAASCCI)
CLC
ROL R30
ROL R31
ADD R30,R20
ADC R31,R16
LPM R20,Z
POP R31
POP R30
RCALL wdata
pop R20
andi R20,$0f
PUSH R30
PUSH R31
LDI ZL, LOW(TABLAASCCI) ;EL COMPILADOR HACE UN CORRIMENTO LOGICO A LA LEFT
LDI ZH, HIGH(TABLAASCCI)
CLC
ROL R30
ROL R31
ADD R30,R20
ADC R31,R16
LPM R20,Z
POP R31
POP R30
RCALL wdata
pop R20
POP R31
POP R30
POP R29
POP R28
POP R16
ret
; envia a pantalla un par de digitos decimales, R20 es el registro con el par de digitos, Z el puerto
printdig2dec:
push R20
push R20
lsr R20
lsr R20
lsr R20
lsr R20
ori R20,$30
RCALL wdata
pop R20
andi R20,$0f
ori R20,$30
RCALL wdata
pop R20
ret
; posiciona el cursor en una localidad de la pantalla, R20 es el registro con la localidad en pantalla y Z el puerto donde esta el display
setposchar:
push R20
ORI R20,$80
RCALL wcom
pop R20
ret
; inicializa la pantalla con envio de 4 bits, Z la localidad del a pantalla
pantallaset:
push R20
push R21
push R22
LDI R21, $04
RCALL retarshort
LDI R20,$00
st Z,R20
RCALL retarshort
LDI R20,$20
ST Z, R20
RCALL retarshort
ADD R20, R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
LDI R20,$80
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
LDI R20,$00
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
LDI R20,$60
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
LDI R20,$00
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
; 0f = cursor + blink 0e = cursor 0c = no cursor
LDI R20,$E0
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
POP R22
POP R21
POP R20
ret
; borra el display y pone el cursor en la posicion 0, Z la localidad de la pantalla
borradisp:
push R20
push R21
push R22
LDI R20, $00
LDI R21, $04
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
LDI R20, $10
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20, R21
ST Z, R20
RCALL retarshort
LDI R20,$00
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20, R21
ST Z, R20
RCALL retarshort
LDI R20, $20
ST Z, R20
RCALL retarshort
add R20, R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
POP R22
POP R21
POP R20
ret
; escribe un caracter en la pantallla, R20 el caracter, Z la localidad dela pantalla
wdata:
push R20
push R21
push R22
PUSH R20
push R20
LDI R21, $04
LDI R20, $01
ST Z, R20
POP R20
andi R20,$f0
ORI R20, $01
ST Z, R20
RCALL retarshort
add R20, R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
pop R20
LSL R20
LSL R20
LSL R20
LSL R20
andI R20,$f0
ORI R20,$01
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
POP R22
POP R21
POP R20
ret
; envia un comando a la pantalla matricial, R20 el comando, Z la localidad dela pantalla
wcom:
push R20
push R21
push R22
PUSH R20
push R20
LDI R21, $04
LDI R20, $00
ST Z, R20
POP R20
andi R20,$f0
ST Z, R20
RCALL retarshort
add R20, R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
pop R20
LSL R20
LSL R20
LSL R20
LSL R20
andI R20,$f0
ST Z, R20
RCALL retarshort
add R20,R21
ST Z, R20
RCALL retarshort
sub R20,R21
ST Z, R20
RCALL retarshort
POP R22
POP R21
POP R20
ret
retarshort:
push R25
LDI R25,$2F
retb:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
DEC R25
BRNE retb
pop R25
ret
TABLAASCCI:
.DB "0123456789ABCDEF"