📄 捕捉时间驱动.asm.txt
字号:
;=====================================================================
; File Name : Cap_drv.asm
; Module Name : CAP_EVENT_DRV
; Initialization Routine: CAP_EVENT_DRV_INIT
; Description: Provides the instantaneous value of the selected time
; base(GP Timer) captured on the occurrence of an event.
; Such events can be any specified transition of a signal
; applied at the capture input pins of 24x/24xx devices.
;
; |~~~~~~~~~~~~~~~|
; CAPn (EV H/W pin) o---->| |----->o FIFOn
; |CAP_EVENT_DRV |
; | |
; |---------------|
;
;=====================================================================
;(To use this Module, copy this section to main system file)
; .ref CAP_EVENT_DRV, CAP_EVENT_DRV_INIT ;function call
; .ref CAP_EVENT_DRV_CLKPS_INIT ;function call
; .ref CLK_prescaler_bits ;Parameter
;=====================================================================
;Module definitions for external reference.
.def CAP_EVENT_DRV, CAP_EVENT_DRV_INIT ;function call
.def CAP_EVENT_DRV_CLKPS_INIT ;function call
.def CLK_prescaler_bits ;Parameter
;=====================================================================
.include x24x_app.h
.bss CLK_prescaler_bits,1
;Select Capture inputs
CAP1 .set 1
CAP2 .set 0
CAP3 .set 0
CAP4 .set 0
;=====================================================================
CAP_EVENT_DRV_INIT:
;=====================================================================
;---target dependancy---------------
POINT_PF2
.if (x240) ;Select CAP functions for the I/O
;pins on x240
.if (CAP4)
LACC OCRB
OR #00010000000b ;Set pin function as CAP4.
SACL OCRB
.endif
.if (CAP3)
LACC OCRB
OR #01000000b ;Set pin function as CAP3.
SACL OCRB
.endif
.if (CAP2)
LACC OCRB
OR #00100000b ;Set pin function as CAP2.
SACL OCRB
.endif
.if (CAP1)
LACC OCRB
OR #00010000b ;Set pin function as CAP1.
SACL OCRB
.endif
.endif
;---------------------------------------------------------------------
.if (x243) ;Select CAP functions for the I/O
;pins on x243
.if (CAP3)
LACC OCRA
OR #00100000b
SACL OCRA ;Set pin function as CAP3.
.endif
.if (CAP2)
LACC OCRA
OR #00010000b
SACL OCRA ;Set pin function as CAP2.
.endif
.if (CAP1)
LACC OCRA
OR #00001000b
SACL OCRA ;Set pin function as CAP1.
.endif
.endif
;---------------------------------------------------------------------
.if (x2407) ;Select CAP functions for the I/O
;pins on x2407
.if (CAP3)
LACC MCRA
OR #00100000b
SACL MCRA ;Set pin function as CAP3.
.endif
.if (CAP2)
LACC MCRA
OR #00010000b
SACL MCRA ;Set pin function as CAP2.
.endif
.if (CAP1)
LACC MCRA
OR #0001000b
SACL MCRA ;Set pin function as CAP1.
.endif
.endif
;---------------------------------------------------------------------;---target dependancy--------------------------------------------------------
.if (x240 | x243) ;Use Timer T2 as time base with
;default clock prescaler
POINT_B0
SPLK #2, CLK_prescaler_bits ;Default prescaler set to x/4
CLRC SXM
LACC CLK_prescaler_bits,8
AND #0700h
; 5432109876543210
; ||||!!!!||||!!!!
OR #1001000001000010b
POINT_EV
SACL T2CON ;Cont Up mode
SPLK #0FFFFh, T2PER
;Empty all FIFOs
LACC FIFO1
LACC FIFO1
LACC FIFO2
LACC FIFO2
LACC FIFO3
LACC FIFO3
; Configure Capture registers. [options: Enable CAP1, CAP2, CAP3, CAP4 func]
.if (CAP1 | CAP2)
; 5432109876543210
; ||||!!!!||||!!!!
SPLK #1010000001010000b,CAPCON ;CAP1/2 En, TMR2, +ve edge
.endif
.if (CAP3)
; 5432109876543210
; ||||!!!!||||!!!!
SPLK #1001000000000100b,CAPCON ;CAP3 En, TMR2, +ve edge
.endif
.if (CAP4)
; 5432109876543210
; ||||!!!!||||!!!!
SPLK #1000100000000001b,CAPCON ;CAP4 En, TMR2, +ve edge
.endif
.endif
;---------------------------------------------------------------------;---target dependancy--------------------------------------------------------
.if (x2407) ;Use Timer T2 as time base with
;default clock prescaler
POINT_B0
SPLK #2, CLK_prescaler_bits ;Default prescaler set to x/4
CLRC SXM
LACC CLK_prescaler_bits,8
AND #0700h
; 5432109876543210
; ||||!!!!||||!!!!
OR #1001000001000010b
POINT_EV
SACL T2CON ;Cont Up mode
SPLK #0FFFFh, T2PER
; Configure Capture registers. [options: Enable CAP1, CAP2, CAP3]
;Select one of following options
.if (CAP1 | CAP2)
; 5432109876543210
; ||||!!!!||||!!!!
SPLK #1010000001010000b,CAPCONA ;CAP1/2 En, TMR2, +ve edge
.endif
.if (CAP3)
; 5432109876543210
; ||||!!!!||||!!!!
SPLK #1001000000000100b,CAPCONA ;CAP3 En, TMR2, +ve edge
.endif
.endif
RET
;=====================================================================
CAP_EVENT_DRV_CLKPS_INIT:
;=====================================================================
;---target dependancy--------------------------------------------------------
.if (x240 | x243) ;Use Timer T2 as time base with
;selectable clock prescaler
POINT_B0
CLRC SXM
LACC CLK_prescaler_bits,8 ;Input user selected prescaler
AND #0700h
; 5432109876543210
; ||||!!!!||||!!!!
OR #1001000001000010b
POINT_EV
SACL T2CON ;Cont Up mode
.endif
;---target dependancy--------------------------------------------------------
.if (x2407) ;Use Timer T2 as time base with
;selectable clock prescaler
POINT_B0
CLRC SXM
LACC CLK_prescaler_bits,8 ;Input user selected prescaler
AND #0700h
; 5432109876543210
; ||||!!!!||||!!!!
OR #1001000001000010b
POINT_EV
SACL T2CON ;Cont Up mode
.endif
RET
;=====================================================================
CAP_EVENT_DRV
;=====================================================================
;No S/W functions are performed here. Capture module performs internal
;H/W functions as specified in the initialization routines.
RET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -