;------------------------------------------
; Experiment lab no.6 INCLUDED FILE
;------------------------------------------
;
;Initialize LCD registers with commands
;
LCD_INIT:
        MOV     A,#00111000B    ;FUNCTION SET command
        LCALL   LCD_WRITE_INST  ;with 2 LINE & 8 bit comm.
        MOV     A,#00001110B    ;DISPLAY ON/OFF command
        LCALL   LCD_WRITE_INST  ;with diplay on & unblink cursor
        MOV     A,#00000001B    ;CLEAR command
        LCALL   LCD_WRITE_INST  ;to clear display & home cursor
        RET
;
; Write a byte to LCD's instruction register
; IN: A = instruction code
;
LCD_WRITE_INST:
        PUSH    DPH
        PUSH    DPL
        MOV     DPTR,#LCDWRC    ;write instruction code
        MOVX    @DPTR,A
        MOV     DPTR,#LCDRDC    ;read busy flag (BF)
LCD_WR1:
        MOVX    A,@DPTR
        JB      ACC.7,LCD_WR1   ;wait until bit 0
        POP     DPL
        POP     DPH
        RET
;
; Write a character to LCD's data register
; IN: A = data byte
;
LCD_WRITE_DATA:
        PUSH    DPH
        PUSH    DPL
        MOV     DPTR,#LCDWRD    ;write data
        MOVX    @DPTR,A
        MOV     DPTR,#LCDRDC    ;read busy flag (BF)
LCDWD1: MOVX    A,@DPTR
        JB      ACC.7,LCDWD1    ;and wait until 0
        POP     DPL
        POP     DPH
        RET
;
; Read 8 bytes from 8051 program memory
; and transfer to LCD data register
; IN:  DPTR = start address of 16 bytes buffer
;
PMEM_XFER:
        MOV     R2,#08H         ;move 8 characters
PMEM_XFR1:
        CLR     A
        MOVC    A,@A+DPTR       ;get data from memory
        LCALL   LCD_WRITE_DATA
        INC     DPTR
        DJNZ    R2,PMEM_XFR1
        RET
;
;Time Delay
;
DELAY:
        MOV     R2,#10          ;delay 1 sec
        LCALL   DTSEC
        RET
