;------------------------------------------
; Experiment lab no.4 INCLUDED FILE
;------------------------------------------

;8255 user port
CONA    EQU     0F800H
CONB    EQU     0F801H
CONC    EQU     0F802H
CONP    EQU     0F803H

; Print a character on printer
; IN:  A = ASCII value
;
PRINT_CHAR:
         LCALL  PBYTE
         MOV    A,#CR    ;send cr
         LCALL  PBYTE
         MOV    A,#LF    ;send lf
         LCALL  PBYTE
         RET
;
; Print a number on printer
; IN:  A = hex value
;
PRINT_NUM:
         LCALL  HTOA     ;convert hex to ascii
         MOV    A,R2     ;send the 1st byte of converted data
         LCALL  PBYTE
         MOV    A,R3     ;and the 2nd byte
         LCALL  PBYTE
         MOV    A,#CR    ;send cr
         LCALL  PBYTE
         MOV    A,#LF    ;send lf
         LCALL  PBYTE
         RET
;
; Send out a byte to printer port
; IN: A = ASCII value
;
PBYTE:   PUSH   DPH
         PUSH   DPL
         PUSH   ACC
;
         MOV    DPTR,#CONB        ;SELECT DIGIT 0
         MOVX   A,@DPTR
         ANL    A,#11111000B
         MOVX   @DPTR,A
;
         CALL   CHECK_BUSY        ;wait until not busy
         POP    ACC
PBYTE1:  MOV    DPTR,#CONA        ;sent out data to port
         MOVX   @DPTR,A
         CALL   PDELAY            ;delay for a while
;
         MOV    DPTR,#CONB        ;pulse the strobe line
         MOVX   A,@DPTR
         CLR    ACC.5
         MOVX   @DPTR,A           ;low signal
         PUSH   ACC
         CALL   PDELAY            ;delay for a while
         POP    ACC
         SETB   ACC.5             ;high signal
         MOVX   @DPTR,A
;
         POP    DPL
         POP    DPH
         RET
;
; Wait until busy line is not busy
;
CHECK_BUSY:
         MOV    DPTR,#CONC        ;WAIT FOR BUSY SIGNAL
PBYTE51: MOVX   A,@DPTR
         JB     ACC.5,PBYTE51
         RET
;
; Printer signal delay
;
PDELAY:
         MOV    A,#0C0H           ;time delay
PDLY1:   DEC    A
         JNZ    PDLY1
         RET
