;***********************************************************
; THIS IS AN EXAMPLE PROGRAM FOR THE 6805 PROCESSOR.
; IT IS TAKEN FROM PAGE 289 OF THE SEPTEMBER 20, 1984 ISSUE
; OF EDN, AND AFTER ONLY FORMAT MODIFICATIONS FOR CROSS-32,
; IT IS PASSED ON AS AN EXAMPLE, FREE OF CHARGE ,BY
; UNIVERSAL CROSS-ASSEMBLERS.

; THE USER NEED NOT SPECIFY DIRECT OR EXTENDED
; AND INDEXED 8-BIT OR INDEXED 16-BIT ADDRESSING.
; CROSS-32 WILL AUTOMATICALLY SELECT THE SHORTEST
; FORM OF THE INSTRUCTION.

         CPU     "6805.TBL"     ; CPU TABLE

         HOF     "MOT8"         ; HEX OUTPUT FORMAT

;***********************************************************
;
; INTERFACE FOR A BARGRAPH DISPLAY
; USING A MC68705R3 MICROCOMPUTER
;   BY: D. ARTUSI  06/27/84

; I/O PORTS ALLOCATION
;
PORTA:   EQU     00H
DDRA:    EQU     04H
ADCR:    EQU     0EH          ; A/D CONTROL REGISTER
ADRE:    EQU     0FH          ; A/D RESULT REGISTER

; RAM ALLOCATION
;
         ORG     10H
VALUE:   DFS     1
ZEROS:   DFS     1

; CONNECTIONS BETWEEN THE 68705R3 AND THE DRIVER
;
;  PA0---> CLOCK   (PIN 19 OF DRIVER)
;  PA1---> DATA    (PIN 21 OF DRIVER)
;  PA2---> ENABLE  (PIN 20 OF DRIVER)

; INITIALIZATION OF I/O PORTS
;
         ORG     0100H
         LDA     #0FFH        ; MAKE ALL OUTPUTS
         STA     DDRA

; A/D CONVERSION ROUTINE
;
ADCONV:  LDA     #00H         ; LOAD CHANNEL SELECTION (AN0)
         STA     ADCR         ; SELECT CHANNEL & START CONV.
         BRCLR   7,ADCR,$     ; CHECK FOR END OF CONV. FLAG
         LDA     ADRE         ; READ RESULT OF A/D CONV.

         BCLR    2,PORTA      ; ENABLE DISPLAY DRIVER
         LSRA
         LSRA
         LSRA                 ; SCALE RESULT (DIVIDE BY 8)
         STA     VALUE        ; SAVE RESULT
         BEQ     ALZERO       ; IF RESULT IS ALL ZEROS
         CMP     #1FH         ; IS RESULT = FULL SCALE?
         BEQ     ONES         ; FULL SCALE DISPLAY
         SUB     VALUE
         STA     ZEROS        ; # OF SEGMENTS OFF AT THE TOP
         BRA     DISPLY       ; GO TO DISPLAY OUTPUT ROUTINE

ALZERO:  LDA     #20H         ; # OF ELEMENTS IN BARGRAPH
         BCLR    1,PORTA      ; CLEAR DATA OUTPUT LINE
         BSR     CLOCK        ; CLOCK IT IN
         BSET    2,PORTA      ; DISABLE DISPLAY DRIVER
         BRA     ADCONV       ; GO FOR ANOTHER CONVERSION

ONES:    INCA                 ; ENTER HERE WHEN IS FULL SCALE
                              ; AND ALL ELEMENTS ARE "ON"
         BSET    1,PORTA      ; SET DATA OUTPUT LINE
         BSR     CLOCK        ; CLOCK IN
         BSET    2,PORTA      ; DISABLE DISPLAY DRIVER
         BRA     ADCONV       ; GO FOR ANOTHER CONVERSION

DISPLY:  LDA     ZEROS        ; LOAD ZEROS (SEGMENTS "OFF")
         BCLR    1,PORTA      ; CLEAR DATA LINE
         BSR     CLOCK        ; CLOCK IN
         LDA     VALUE        ; LOAD ONES (SEGMENTS "OFF")
         BSET    1,PORTA      ; SET DATA LINE
         BSR     CLOCK        ; CLOCK ONES IN
         BSET    2,PORTA      ; DISABLE DISPLAY DRIVER
         BRA     ADCONV       ; RETURN FOR ANOTHER CONVERSION

; CLOCKING ROUTINE:  ENTER WITH NUMBER
; OF CLOCK PULSES IN ACCUMULATOR
;
CLOCK:   BCLR    0,PORTA      ; CLOCK LINE LOW
         BSET    0,PORTA      ; BRING IT HIGH
         DECA                 ; DECREMENT COUNTER
         BNE     CLOCK        ; ONCE MORE
         RTS                  ; RETURN

         END
