;------------------------------------------
; Experiment lab no.10 INCLUDED FILE
;------------------------------------------
;
; Initial MAX7219's operation with many control bytes
;
INIT_7219:
        MOV     R7,#0CH         ;SHUTDOWN register
        MOV     R6,#01H         ;with normal operation
        LCALL   SEND_AD
;
        MOV     R7,#09H         ;DECODE MODE register
        MOV     R6,#00H         ;with no decode for digit 0-7
        LCALL   SEND_AD
;
        MOV     R7,#0AH         ;INTENSITY register
        MOV     R6,#08H         ;with pale brightness
        LCALL   SEND_AD
;
        MOV     R7,#0BH         ;SCAN LIMIT register
        MOV     R6,#07H         ;with all 7 digits display
        LCALL   SEND_AD
        RET
;
; Send address & data in serial form
; IN: R7 = ADDRESS, R6 = DATA
;
SEND_AD:
        SETB    LOADX           ;prompt to transfer
;
        MOV     B,#08H
SENAD1: MOV     A,R7            ;shift address bit out
        RLC     A
        MOV     R7,A
        MOV     DATAI,C
        LCALL   MAKE_CLK
        DJNZ    B,SENAD1
;
        MOV     B,#08H
SENAD2: MOV     A,R6            ;shift data bit out
        RLC     A
        MOV     R6,A
        MOV     DATAI,C
        LCALL   MAKE_CLK
        DJNZ    B,SENAD2
;
        CLR     LOADX           ;latch previously bits
        SETB    LOADX
        CLR     LOADX
        RET
;
; Generate a clock
;
MAKE_CLK:
        SETB    CLOCK
        CLR     CLOCK
        RET
;
; Command to on all LEDs of 8 digits
;
ON_LEDS:
       MOV      R7,#08H
ON_LED1:
       MOV      00H,07H
       MOV      R6,#0FFH
       LCALL    SEND_AD
       MOV      07H,00H
       DJNZ     R7,ON_LED1
       RET
;
; Command to off all LEDs of 8 digits
;
OFF_LEDS:
       MOV      R7,#08H
OFF_LED1:
       MOV      00H,07H
       MOV      R6,#00H
       LCALL    SEND_AD
       MOV      07H,00H
       DJNZ     R7,OFF_LED1
       RET
;
; Delay time
;
DELAY:
       MOV      R2,#02H
       LCALL    DTSEC
       RET

