;;; analog2hex.s ;;; reads analog port 0 and outputs it as two hex digits BASE= 0x1000 SCSR= 0x102e ; serial comms status reg SCDR= 0x102f ; serial comms data reg ADCTL= 0x1030 ; analog-to-digital control reg ADR1= 0x1031 ; A/D result 1 reg OPTION= 0x1039 ; options register ldx #BASE ; pointer to register base lds #0x1ff ; set up stack ptr to top of RAM bset turn on A/Ds loop: ldaa #0 ; select channel 0 staa ADCTL ; start conversion donelp: ldaa ADCTL bpl donelp ; if high bit set, it's done ldaa ADR1 ; grab result! tab ; save for later in reg B anda #0xf0 ; mask off low bits lsra lsra lsra lsra ; move high nybble to low position jsr cvtxmit tba ; retrieve saved value anda #0x0f ; mask off high bits jsr cvtxmit ldaa #0x0d ; send carriage return jsr xmit ldaa #0x0a ; send line feed jsr xmit bra loop cvtxmit: ;;; subroutine accepts value in A as 0 - F and transmits ;;; correct ascii character cmpa #10 bmi dig0to9 adda #55 ; cvt 10-15 to ascii 'A' to 'F' bra xmit dig0to9: adda #48 ; cvt 0-9 to ascii '0' to '9' ;;; fall into xmit xmit: ;;; subroutine accepts value in A and sends it staa