;LCD interface 89s52
;LCD 8952
;D7 14 p1.7
;D6 13 p1.6
;D5 12 P1.5
;D4 11 p1.4
;EN 6 p1.3
;RS 4 p1.2
;GND 1,3,5
;VCC 2
#INCLUDE "8051EQU.INC"
LCD_DATA_4 .equ P1.4
LCD_DATA_5 .equ P1.5
LCD_DATA_6 .equ P1.6
LCD_DATA_7 .equ P1.7
LCD_RS .equ P1.2
LCD_EN .equ P1.3
; RESET
.ORG 0H
AJMP START
; INTERRUPTS (not used) ;place interrupt routines at appropriate
;memory locations
.ORG 03H ;external interrupt 0
RETI
.ORG 0BH ;timer 0 interrupt
RETI
.ORG 13H ;external interrupt 1
RETI
.ORG 1BH ;timer 1 interrupt
RETI
.ORG 23H ;serial port interrupt
RETI
.ORG 25H ;locate beginning of rest of program
INITIALIZE: ;set up control registers
MOV R4,#00H
MOV A,#00H
MOV TCON,#00H
MOV TMOD,#00H
MOV PSW,#00H
MOV IE,#00H ;disable interrupts
RET
LCD_INITIALIZE:
NOP
mov P1, #20h
CLR LCD_RS
SETB LCD_EN
ACALL DELAYMS
CLR LCD_EN
ACALL DELAYMS
mov a, #28h
ACALL LCD_SEND_COMMAND
mov a, #0ch
ACALL LCD_SEND_COMMAND
mov a, #02h
ACALL LCD_SEND_COMMAND
RET
LCD_SEND_COMMAND:
mov 20H,a
ACALL LCD_DATA
clr LCD_RS
setb LCD_EN
ACALL DELAYMS
clr LCD_EN
ACALL DELAYMS
mov a,20H
swap a
ACALL LCD_DATA
clr LCD_RS
setb LCD_EN
ACALL DELAYMS
clr LCD_EN
ACALL DELAYMS
ret
LCD_SEND_DATA:
mov 20H,a
ACALL LCD_DATA
setb LCD_RS
setb LCD_EN
ACALL DELAYMS
clr LCD_EN
ACALL DELAYMS
mov a,20H
swap a
ACALL LCD_DATA
setb LCD_RS
setb LCD_EN
ACALL DELAYMS
clr LCD_EN
ACALL DELAYMS
ret
LCD_DATA:
clr c
mov 20h,a
mov c,4h
mov LCD_DATA_4, c
mov c,5h
mov LCD_DATA_5, c
mov c,6h
mov LCD_DATA_6, c
mov c,7h
mov LCD_DATA_7, c
; MOV 20H,A ;Save A for low nibble
; ORL P1,#0F0h ;Bits 4..7 <- 1
; ORL A,#0Fh ;Don't affect bits 0-3
; ANL P1,A ;High nibble to display
; MOV A,20H
RET
LCD_CLEAR:
MOV a,#01H
ACALL LCD_SEND_COMMAND
RET
LCD_SEND_SPACES:
MOV R4,#20H
LOOP_SPACES:
MOV A,#' '
ACALL LCD_SEND_DATA
DJNZ R4,LOOP_SPACES
RET
DELAYMS: ;millisecond delay routine
MOV R7,#00H
LOOPA:
INC R7
MOV A,R7
CJNE A,#0FFH,LOOPA
RET
DELAYHS: ;half second delay above millisecond delay
MOV R6,#00H
MOV R5,#002H
LOOPB:
INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPB
DEC R5
MOV A,R5
JNZ LOOPB
RET
DELAY1S: ;one second delay above millisecond delay
MOV R6,#00H
MOV R5,#004H
LOOPC:
INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPC
DEC R5
MOV A,R5
JNZ LOOPC
RET
DELAY5S: ;5 SECONDS DELAY
MOV R6,#00H
MOV R5,#010H
LOOPD:
INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPD
DEC R5
MOV A,R5
JNZ LOOPD
RET
DELAY20S: ;20 SECONDS DELAY
MOV R6,#00H
MOV R5,#030H
LOOPE:
INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPE
DEC R5
MOV A,R5
JNZ LOOPE
RET
WRITE_MOBISERVE:
mov a, #'M'
ACALL LCD_SEND_DATA
mov a, #'O'
ACALL LCD_SEND_DATA
mov a, #'B'
ACALL LCD_SEND_DATA
mov a, #'I'
ACALL LCD_SEND_DATA
mov a, #'S'
ACALL LCD_SEND_DATA
mov a, #'E'
ACALL LCD_SEND_DATA
mov a, #'R'
ACALL LCD_SEND_DATA
mov a, #'V'
ACALL LCD_SEND_DATA
ACALL LCD_SEND_SPACES
mov a, #'E'
ACALL LCD_SEND_DATA
mov a, #'-'
ACALL LCD_SEND_DATA
mov a, #'E'
ACALL LCD_SEND_DATA
mov a, #'g'
ACALL LCD_SEND_DATA
mov a, #'y'
ACALL LCD_SEND_DATA
mov a, #'p'
ACALL LCD_SEND_DATA
mov a, #'t'
ACALL LCD_SEND_DATA
RET
;************************* program entry *********************************************
START: ;main program (on power up, program starts at this point)
ACALL INITIALIZE
ACALL LCD_INITIALIZE
ACALL LCD_CLEAR
ACALL WRITE_MOBISERVE
MOV P1,#01H
ACALL DELAY1S
FREEZ:
NOP
CPL P1.1
CPL P1.0
ACALL DELAY1S
AJMP FREEZ
.END