📄 adctimer.asm
字号:
;********************************************************************
;
; Author : ADI - Apps www.analog.com/MicroConverter
;
; Date : 28 May 1999
;
; File : ADCtimer.asm
;
; Hardware : ADuC812
;
; Description : Performs ADC conversions at 10KSPS in Timer2 mode.
; Outputs ADC results on P0 & P2. Continuously
; flashes LED (independently of ADC routine) at
; approximately 5Hz.
; All rate calculations assume an 11.0592MHz Mclk.
;
;********************************************************************
$MOD812 ; Use 8052&ADuC812 predefined symbols
LED EQU P3.4 ; P3.4 drives red LED on eval board
CHAN EQU 0 ; convert this ADC input channel..
; ..chan values can be 0 thru 8
;____________________________________________________________________
; BEGINNING OF CODE
CSEG
ORG 0000h
JMP MAIN ; jump to main program
;____________________________________________________________________
; INTERRUPT VECTOR SPACE
ORG 0033H ; (ADC ISR)
MOV P0,ADCDATAL ; ADC result low byte to Port0
MOV P2,ADCDATAH ; high nibble and channel ID to Port2
RETI
;====================================================================
; MAIN PROGRAM
ORG 004Bh
MAIN:
; PRECONFIGURE...
MOV ADCCON1,#062h ; power up ADC & enable Timer2 mode
MOV ADCCON2,#CHAN ; select channel to convert
MOV RCAP2L,#0D2h ; sample period = 2 * T2 reload prd
MOV RCAP2H,#0FFh ; = 2*(10000h-FFD2h)*1.085us
MOV TL2,#0D2h ; = 2*46*1.085us
MOV TH2,#0FFh ; = 99.8us
; LAUNCH Timer2 DRIVEN CONVERSIONS...
SETB EA ; enable interrupts
SETB EADC ; enable ADC interrupt
SETB TR2 ; run Timer2
; CONTINUE WITH OTHER CODE...
AGAIN: CPL LED ; blink (complement) the LED
CALL DELAY ; delay 100ms
JMP AGAIN ; repeat
; the micro is free to continue with other tasks (flashing the LED in
; this case) while the ADC operation is being controlled by Timer2
; and the ADC interrupt service routine.
;____________________________________________________________________
; SUBROUTINE
DELAY: ; delay 100ms
MOV R7,#200 ; 200 * 500us = 100ms
DLY1: MOV R6,#229 ; 229 * 2.17us = 500us
DJNZ R6,$ ; sit here for 500us
DJNZ R7,DLY1 ; repeat 200 times (100ms total)
RET
;____________________________________________________________________
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -