;FILENAME:   STLAB082.ASM
;DATE:       March 16, 1996
;TITLE:      Digital to analog voltage conversion
;HARDWARE:   MLAB-121

; Pin Interface
PB_8255  EQU    0FA01H  ;8255 port b
CTL_8255 EQU    0FA03H  ;8255 control port

;Program 2: Square step wave generation
;
        ORG     8100H
MAIN:
        LCALL   INIT_8255
        MOV     R0,#0B0H        ;initial value
        MOV     R1,#4FH
        MOV     R2,#50H
        MOV     DPTR,#PB_8255
LOOP:
        MOV     A,R0            ;load voltage level
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY1
        PUSH    ACC
        ADD     A,R1            ;A = A + R1
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY2
        POP     ACC
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY1
        MOV     A,R2            ;A = R2
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY2
        PUSH    ACC
        SUBB    A,R1            ;A = A - R1
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY1
        POP     ACC
        MOVX    @DPTR,A         ;sent to port
        LCALL   DELAY2
        SJMP    LOOP
;
; Initial 8255 mode of operation
;
INIT_8255:
        MOV     DPTR,#CTL_8255  ;Init 8255 mode
        MOV     A,#80H          ;PC(low) = in PC(high) = out
        MOVX    @DPTR,A
        RET
;
; Delay time
;
DELAY1:
        MOV     R6,#00H
DLAY1:
        MOV     R7,#00H
        DJNZ    R7,$
        DJNZ    R6,DLAY1
        RET
;
DELAY2:
        MOV     R6,#00H
DLAY2:
        MOV     R7,#00H
        DJNZ    R7,$
        DJNZ    R6,DLAY2
        RET
;
        END
