📄 atdpro1.asm
字号:
;* Title: ATD.ASM *
;* "Analog to Digital Converter (Using the A/D Converter)" *
;* Description: *
;* ------------ *
;* This program makes it first to utilize the ATD on the
;* HC12 to measure a POTENTIOMETER signal output routed from the *
;* outside worknet to the HC12 ATD pins .
;* First the ATDCTL Registers are initialized. A delay loop of 100 *
;* usec is then executed. The resolution is set up followed by a *
;* conversion set up on channel. After waiting for the status bit *
;* to set, the result goes to the D accumulator and then goes to the *
;* data code.
INCLUDE 'EQUATES.ASM' ;Equates for all registers user Variables
; and bit Equates
; ----------------------------------------------------------------------
; ATD PROGRAM
; ----------------------------------------------------------------------
XDEF ATDPRO,ATD0,ATD1,ATD2,ATD3,ATD4,ATD5,ATD6,ATD7
ATDDATA: SECTION
ATD0: DS.W 1
ATD1: DS.W 1
ATD2: DS.W 1
ATD3: DS.W 1
ATD4: DS.W 1
ATD5: DS.W 1
ATD6: DS.W 1
ATD7: DS.W 1
ATDCODE: SECTION
ATDPRO:
LDS #$3FFF ; Set the stack point
BSR INIT ; Branch to INIT subroutine to Initialize ATD
BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for breakpoint
; ----------------------------------------------
; Subroutine INIT: Initialize ATD ;
; ----------------------------------------------
INIT:
LDAA #$90 ; Allow ATD to function normally,
STAA ATD0CTL2 ; ATD Flags clear normally & disable interrupts
BSR DELAY ; Delay (100 uS) for WAIT delay time.
LDAA #$00 ; Select continue conversion in BGND Mode
STAA ATD0CTL3 ; Ignore FREEZE in ATDCTL3
LDAA #$C1 ; Select Final Sample time = 2 A/D clocks
STAA ATD0CTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
RTS ; Return from subroutine
; ----------------------------------------------
; Subroutine CONVERT:
; ----------------------------------------------
; Set-up ATD, make multiple conversion and store
; the result to a memory location.
; Configure and start A/D conversion
CONVERT:LDAA #$70 ; Initializes ATD S8C=1,SCAN=1,MULT=1, PAD6, Write Clears Flag
STAA ATD0CTL5 ; 8 conversions on a MUTIPLE Conversion sequence,
WTCONV: BRCLR ATD0STAT0,#$80,WTCONV ; Wait for Sequence Complete Flag
LDD ADR00
STD ATD0
LDD ADR01
STD ATD1
LDD ADR02
STD ATD2
LDD ADR03
STD ATD3
LDD ADR04
STD ATD4
LDD ADR05
STD ATD5
LDD ADR06
STD ATD6
LDD ADR07
STD ATD7 ; Loads conversion result into Accumulator
; and then loads them into the datacode
RTS ; Return from subroutine
; -------------------------------
; Subroutine DELAY 100 uS
; -------------------------------
; Delay Required for ATD converter to Stabilize (100 uSec)
DELAY:
LDAA #$C8 ; Load Accumulator with "100 uSec delay value"
SUBDELAY: DECA ; Decrement ACC
BNE SUBDELAY ; Branch if not equal to Zero
RTS ; Return from subroutine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -