To cs_post,
Thanks for your continous help. I tried the SCI port again and again,it just cannot function well to when apply to the ATD converter. Can anyone help me to check the code below? First I initiate the SCI port and the ATD converter, once the comment string is transfered, I'll let SCI go and read the ATD result from the ADR register. Do I need to set up some breakpoint or synchronization during the programing?
ORG $0800 FCB $07 ORG $820
;ATD registers; ATDCTL1 EQU $0061 ATDCTL2 EQU $0062 ;used to select power-up mode; (ADPU,AFFC,AWAI,0,0,0,ASCIE,ASCIF) ATDCTL3 EQU $0063 ;used to select freeze control; (0,0,0,0,0,0,FRZ1,FRZ2) ATDCTL4 EQU $0064 ;used to select sample time bit and total divisor ATDCTL5 EQU $0065 ;used to select conversion modes, channels and initiate conversions ;(0,S8CM,SCAN,MULT,CD,CC,CB,CA)
ADR2H EQU $0074 ;Result registers
ATDSTATH EQU $0066 ;SCF implemented, sequence complete flag
;SCI registers; SC0BDL EQU $00C1 SC0CR1 EQU $00C2 SC0CR2 EQU $00C3 SC0SR1 EQU $00C4 SC0DRH EQU $00C6 SC0DRL EQU $00C7
;ORG $0D00 MAIN: ;LDAB #$FF BSR INIT_SCI ;Branch to INIT to initialize ATD BSR TRANS ;Branch to CONVERT for ATD conversion BSR INIT BSR CONVERT
BSR TRANS2 ;BSR DELAY2 ;DECB BSR DELAY2 BSR MAIN
SWI END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;subroutine to initiate adc; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INIT LDAA #$80 ;Load $80 to ATDCTL2 to power up ATD STAA ATDCTL2
BSR DELAY ;Delay 100us for the capacitors charging
LDAA #$00 ;Load $00 to ATDCTL3 to select the continue conversion mode,NO FREEZE STAA ATDCTL3
LDAA #$01 ;8-bit operation, 2 ATD clock STAA ATDCTL4 ;total divisor as 4 RTS
;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROURTINE DELAY 100us; ;;;;;;;;;;;;;;;;;;;;;;;;;;
LDAA #$C8
DELAY: DECA BNE DELAY RTS
JMP INIT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;subroutine convert; ;-----------------------------------; ;set up ATD, make single conversion and store the result to a memory location. ;configure and start ATD conversion ;Analog input signal: on port AD6 ;convert:using single channel, non-continuous ;The result will be located in ADR2H
CONVERT:LDAA #$06 ;Initiate ATD scan=0, mult=0, pad6 STAA ATDCTL5 WTCONV NOP BRCLR ATDSTATH,#$80,WTCONV ;Wait for sequitence complet flag
LDD ADR2H ;Load conversion result from ADR2H,results in accumulator D STD READING ;STORE D IN LOCATION READING BRA CONVERT ;Contiously updates results
RTS ;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROURTINE DELAY 100us; ;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY2 LDY #$FFFF L1 DEY BNE L1
DEC $800 BNE DELAY2 RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROUTINE TO INITIATE SCI; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INIT_SCI:TPA ;transfer CCR to A accumulator ORAA #$10 ;Ored A with #$10 to set I bit TAP ;Transfer A to CCR
MOVB #$34,SC0BDL ;SET baud=9600 MOVB #$00,SC0CR1 ;Initialize for 8-bit data format
MOVB #$08,SC0CR2 ;set for no Ints, and transmitter enabled SC1CR2 LDX #COMMENT ;TRANSFER THE COMMENT
LDY #READING ;TRANSFER THE READING RESULT LDAA SC0SR1 ;1st step to clear TDRE flag:read SC0SR1 STD SC0DRH ;2nd step to clear TDRE flag: write SC0DR register RTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROUTINE TO TRANSMIT THE DATA STORED IN X; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; TRANS NOP BRCLR SC0SR1,#$80,TRANS ;Wait for TDRE flag
MOVB 1,X+,SC0DRL
CPX #$0B12 BNE TRANS
RTS
TRANS2 NOP BRCLR SC0SR1,#$80,TRANS2
MOVB 1,Y+,SC0DRL CPY #$0B16 BNE TRANS2
RTS
;;;;;;;;;;;;;;;;;;;;;;; ;Display the answer; ;;;;;;;;;;;;;;;;;;;;;;; ORG $0B00
COMMENT FCC 'THE result IS' ;location ended at $0B0Ddddd FCB $20 ;location ended at $0B0F ;FCC 'PLEASE SHOW RESULT' ;location ended at $B21 ;FCB $0D,$0A ;location ended at $B23 ;EOT FCB $04 ;location ended at $0B10 ;DISPLAY THE NUMBER, LOCATION AT $0905;
READING RMB 2 FCB $41 FCB $0D,$0A ;DATA FCC 'NEXT LENGTH' ; FCB $0D,$0A ;EOT2 FCB $04
Jessie