; FILENAME      XDMC202.ASM
; DESCRIPTION   DEMO PROGRAM FOR DMC202 LCD-MODULE
; HARDWARE      JAZZ-31 & LCD (CONNECT AT 8255 PORT)
; ASSEMBLER     SXA51
; START-DATE    20/08/92
; SOFTWARE ENG  KRIANGSAK B.
; COMPANY       SILA RESEARCH CO.,LTD.

; FUNCTION      DISPLAY CHARACTER ON DMC202 LCD
;               DMC202 CONNECT AT 8255 PORT (I/O)

; ********** VARIABLE **********

PORTA    EQU    0FC00H            ;LCD DATA (PA0-PA7)
PORTB    EQU    0FC01H            ;LCD CONTROL (PB0-PB2)
                                  ;PB0 -> RS
                                  ;PB1 -> R/W
                                  ;PB2 -> E
PORTP    EQU    0FC03H            ;8255 CONTROL PORT

; ********** MAIN **********

         ORG    8100H

MAIN:    MOV    DPTR,#PORTP       ;SET 8255 CONTROL PORT
         MOV    A,#80H
         MOVX   @DPTR,A
         MOV    R2,#2             ;FIRST DELAY
         LCALL  DELAY

                                  ;**** LCD INITIALIZE ****
         MOV    A,#00111000B      ;FUNCTION SET
         LCALL  LCDWI
         MOV    A,#00001110B      ;DISPLAY ON/OFF
         LCALL  LCDWI
         MOV    A,#01H            ;CLEAR
         LCALL  LCDWI
         MOV    R2,#2
         LCALL  DELAY

                                  ;**** LOAD SILA CHARACTER ****
         MOV    A,#01000000B      ;CGRAM ADD.
         LCALL  LCDWI
         MOV    R7,#8*3           ;LOAD CHAR.
         MOV    DPTR,#MAINTD
MAIN1:   CLR    A
         MOVC   A,@A+DPTR
         PUSH   DPH
         PUSH   DPL
         LCALL  LCDWD
         POP    DPL
         POP    DPH
         INC    DPTR
         DJNZ   R7,MAIN1

MAIN2:   MOV    DPTR,#MAINT1      ;LCD MODULE
         LCALL  LCDLD
         MOV    R2,#10H
         LCALL  DELAY
         MOV    DPTR,#MAINT2
         LCALL  LCDLD
         MOV    R2,#10H
         LCALL  DELAY
         MOV    DPTR,#MAINT3
         LCALL  LCDLD
         MOV    R2,#10H
         LCALL  DELAY

         MOV    DPTR,#MAINT4
         LCALL  LCDLD
         MOV    R2,#10H
         LCALL  DELAY
         MOV    A,#00001111B      ;CURSOR & BLINK
         LCALL  LCDWI
         MOV    A,#80H            ;AT HOME
         LCALL  LCDWI
         MOV    R2,#10H
         LCALL  DELAY

         MOV    A,#80H            ;DDRAM ADD.
         LCALL  LCDWI
         MOV    R7,#40
MAIN4:   MOV    A,#00011100B      ;SHIFT , RIGHT
         LCALL  LCDWI
         MOV    R2,#1
         LCALL  DELAY
         DJNZ   R7,MAIN4

         MOV    R2,#10H
         LCALL  DELAY
         LJMP   MAIN2

MAINT1:  DB     "     LCD MODULE     "
         DB     "  BY SILA RESEARCH  "
MAINT2:  DB     "    EASY TO USE     "
         DB     "     LOW POWER      "
MAINT3:  DB     "DMC202 20 CHR 2 LINE"
         DB     "DMC164 16 CHR 4 LINE"
MAINT4:  DB     "------- ",0,1,2," --------"
         DB     "0123456789ABCDEFGHIJ"

MAINTD:  DB     00011111B
         DB     00000000B
         DB     00000001B
         DB     00001111B
         DB     00010001B
         DB     00011101B
         DB     00010001B
         DB     00010001B

         DB     00000000B
         DB     00000000B
         DB     00000000B
         DB     00001110B
         DB     00010001B
         DB     00000111B
         DB     00001001B
         DB     00010001B

         DB     00000000B
         DB     00000000B
         DB     00000000B
         DB     00001110B
         DB     00010001B
         DB     00000001B
         DB     00000001B
         DB     00000001B

; ********** DELAY SUB **********
; DELAY SUBROUTINE
; IN  = R2
; REG = R2,R3,R4

DELAY:   MOV    R3,#0
DELAY1:  MOV    R4,#0
         DJNZ   R4,$
         DJNZ   R3,DELAY1
         DJNZ   R2,DELAY
         RET

; ********** LCDDIS **********
; LOAD DATA TO LCD-MODULE
; IN  = DPTR  START BLOCK (40 BYTE)
; REG = A,R2,DPTR

LCDLD:   MOV    A,#80H            ;SET ADDRESS LINE 1
         LCALL  LCDLDS
         MOV    A,#0C0H           ;SET ADDRESS LINE 2
         LCALL  LCDLDS
         RET

LCDLDS:  PUSH   DPH               ;LOAD SUB.
         PUSH   DPL
         LCALL  LCDWI             ;WRITE ADDRESS
         POP    DPL
         POP    DPH
         MOV    R2,#20            ;20 CHAR.
LCDLDS1: CLR    A
         MOVC   A,@A+DPTR         ;MOVC FOR CODE / MOVX FOR DATA
         PUSH   DPH
         PUSH   DPL
         LCALL  LCDWD             ;WRITE DATA
         POP    DPL
         POP    DPH
         INC    DPTR
         DJNZ   R2,LCDLDS1
         RET

; ********** LCDWI **********
; LCD WRITE INSTRUCTION (RS=0)
; IN  = A
; REG = A,DPTR

LCDWI:   MOV    DPTR,#PORTA       ;DATA TO PORTA
         MOVX   @DPTR,A
         MOV    DPTR,#PORTB       ;PORTB READ MODIFY WRITE
         MOVX   A,@DPTR
         CLR    ACC.0             ;RS=0
         CLR    ACC.1             ;R/W=0
         CLR    ACC.2             ;ENABLE=0
         MOVX   @DPTR,A
         SETB   ACC.2             ;ENABLE=1
         MOVX   @DPTR,A
         CLR    ACC.2             ;ENABLE=0
         MOVX   @DPTR,A
         MOV    A,#0              ;DELAY
LCDWI1:  DEC    A
         JNZ    LCDWI1
         RET

; ********** LCDWD **********
; LCD WRITE DATA (RS=1)
; IN  = A
; REG = A,DPTR

LCDWD:   MOV    DPTR,#PORTA       ;DATA TO PORTA
         MOVX   @DPTR,A
         MOV    DPTR,#PORTB       ;PORTB READ MODIFY WRITE
         MOVX   A,@DPTR
         SETB   ACC.0             ;RS=1
         CLR    ACC.1             ;R/W=0
         CLR    ACC.2             ;ENABLE=0
         MOVX   @DPTR,A
         SETB   ACC.2             ;ENABLE=1
         MOVX   @DPTR,A
         CLR    ACC.2             ;ENABLE=0
         MOVX   @DPTR,A
         MOV    A,#0              ;DELAY
LCDWD1:  DEC    A
         JNZ    LCDWD1
         RET

         END

