📄 adcinc14.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; ADCINC14.asm
;; Version: 1.3, Updated on 2005/09/29 at 13:13:53
;; Generated by PSoC Designer ver 4.2 b1013 : 02 September, 2004
;;
;; DESCRIPTION: ADCINC14 User Module software implementation file for
;; the 22/24/25/26/27xxx PSoC family of devices.
;;
;; NOTE: User Module APIs conform to the fastcall16 convention for marshalling
;; arguments and observe the associated "Registers are volatile" policy.
;; This means it is the caller's responsibility to preserve any values
;; in the X and A registers that are still needed after the API functions
;; returns. For Large Memory Model devices it is also the caller's
;; responsibility to perserve any value in the CUR_PP, IDX_PP, MVR_PP and
;; MVW_PP registers. Even though some of these registers may not be modified
;; now, there is no guarantee that will remain the case in future releases.
;;-----------------------------------------------------------------------------
;; Copyright (c) Cypress MicroSystems 2000-2003. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "ADCINC14.inc"
include "m8c.inc"
include "memory.inc"
;-----------------------------------------------
; Global Symbols
;-----------------------------------------------
export ADCINC14_Start
export _ADCINC14_Start
export ADCINC14_SetPower
export _ADCINC14_SetPower
export ADCINC14_Stop
export _ADCINC14_Stop
export ADCINC14_GetSamples
export _ADCINC14_GetSamples
export ADCINC14_StopAD
export _ADCINC14_StopAD
export ADCINC14_fIsData
export _ADCINC14_fIsData
export ADCINC14_fIsDataAvailable
export _ADCINC14_fIsDataAvailable
export ADCINC14_iGetData
export _ADCINC14_iGetData
export ADCINC14_ClearFlag
export _ADCINC14_ClearFlag
export ADCINC14_iGetDataClearFlag
export _ADCINC14_iGetDataClearFlag
;-----------------------------------------------
; Constant Definitions
;-----------------------------------------------
LSB: equ 1
MSB: equ 0
CALCTIME_LSB: equ (ADCINC14_CALCTIME & 0x0000FF)
CALCTIME_ISB: equ ((ADCINC14_CALCTIME & 0x00FF00) >> 8)
CALCTIME_MSB: equ ((ADCINC14_CALCTIME & 0xFF0000) >> 16)
AREA UserModules (ROM, REL)
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_Start
; FUNCTION NAME: ADCINC14_SetPower
;
; DESCRIPTION:
; Applies power setting to the module's analog PSoc block.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A Contains power level setting 0 to 3
;
; RETURNS: NA
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
ADCINC14_Start:
_ADCINC14_Start:
ADCINC14_SetPower:
_ADCINC14_SetPower:
RAM_PROLOGUE RAM_USE_CLASS_2
and A,ADCINC14_bfPOWERMASK ; Mask only the valid power setting bits
mov X, SP ; Get location of next location on stack
push A ; Save power value on temp location
mov A, reg[ADCINC14_bfAtoDcr3] ; Get current value of AtoDcr3
and A, ~ADCINC14_bfPOWERMASK ; Mask off old power value
or A, [X] ; OR in new power value
or A, f0h ; Make sure other register is set correctly
mov reg[ADCINC14_bfAtoDcr3], A ; Reload CR with new power value
pop A ; Restore the stack and power value
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_Stop
;
; DESCRIPTION:
; Removes power from the module's analog PSoc block, but the digital
; blocks keep on running.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: NA
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
ADCINC14_Stop:
_ADCINC14_Stop:
RAM_PROLOGUE RAM_USE_CLASS_1
and reg[ADCINC14_bfAtoDcr3], ~ADCINC14_bfPOWERMASK
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_Get_Samples
;
; DESCRIPTION:
; Starts the A/D convertor and will place data is memory. A flag
; is set whenever a new data value is available.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A Number of samples to be taken. A zero will cause the ADC to run
; continuously.
;
; RETURNS: NA
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
ADCINC14_GetSamples:
_ADCINC14_GetSamples:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ADCINC14_bSampC
mov [ADCINC14_bSampC], A ; Store sample count
call ADCINC14_StopAD ; Halt PWM and counter, Disable
; Interrupts, Put A/D in reset
mov reg[ADCINC14_bPWM_IntTime_LSB], FFh ; Int time = (2^14)*4 = 2^16 = 0x010000
mov reg[ADCINC14_bPWM_IntTime_ISB], FFh
mov reg[ADCINC14_bPWM_IntTime_MSB], 00h
mov A,<(0x010000 - 1) ; Add CalcTime to integrate period to get total
add A,CALCTIME_LSB ; period.
mov reg[ADCINC14_bPWM_Period_LSB],A
mov A,>(0x010000 - 1)
adc A,CALCTIME_ISB
mov reg[ADCINC14_bPWM_Period_ISB],A
mov A,0
adc A,CALCTIME_MSB
mov reg[ADCINC14_bPWM_Period_MSB],A
IF (ADCINC14_DATA_FORMAT)
mov [ADCINC14_iCounterU+LSB], 0xE0 ; Start counter at -(2^14)/2 = -8192 for signed result
mov [ADCINC14_iCounterU+MSB], 0xFF ; Start counter at -(2^14)/2 = -8192 for signed result
ELSE
mov [ADCINC14_iCounterU+LSB], 00h ; Always start at zero for unsigned values
mov [ADCINC14_iCounterU+MSB], 00h ; Always start at zero for unsigned values
ENDIF
mov A, reg[ADCINC14_bPWM_IntTime_LSB] ; Dummy Read - required do not remove
mov reg[ADCINC14_bPeriod], FFh ; Make sure counter starts at FF
and reg[ADCINC14_bfAtoDcr3],~ADCINC14_fFSW0 ; Take Integrator out of reset
IF ADCINC14_NoAZ
and reg[ADCINC14_bfAtoDcr2],~ADCINC14_fAutoZero ; Take Integrator out of AutoZero
ENDIF
; Enable the A/D and Start it!
or reg[ADCINC14_bCounter_CR0], (ADCINC14_fDBLK_ENABLE|ADCINC14_fPULSE_WIDE) ; Enable the Counter
or reg[ADCINC14_fPWM_LSB_CR0], ADCINC14_fDBLK_ENABLE ; Enable PWM
or reg[ADCINC14_bfPWM24_INT_REG], ADCINC14_bfPWM24_Mask ; Enable PWM and Counter interrupts
or reg[ADCINC14_bfCounter_INT_REG], ADCINC14_bfCounter_Mask
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_StopAD
;
; DESCRIPTION:
; Completely shuts down the A/D is an orderly manner. Both the
; Timer and Counter are disabled and their interrupts are deactivated.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: NA
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
ADCINC14_StopAD:
_ADCINC14_StopAD:
RAM_PROLOGUE RAM_USE_CLASS_1
and reg[ADCINC14_fPWM_LSB_CR0], ~ADCINC14_fDBLK_ENABLE ; Disable the PWM
and reg[ADCINC14_bCounter_CR0], ~ADCINC14_fDBLK_ENABLE ; Disable the Counter
IF ADCINC14_NoAZ
or reg[ADCINC14_bfAtoDcr2], ADCINC14_fAutoZero ; Put the Integrator into Autozero mode
ENDIF
or reg[ADCINC14_bfAtoDcr3], ADCINC14_fFSW0 ; Put Integrator into reset
push A
M8C_DisableIntMask ADCINC14_bfPWM24_INT_REG, ADCINC14_bfPWM24_Mask ; Disable interrupts
M8C_DisableIntMask ADCINC14_bfCounter_INT_REG, ADCINC14_bfCounter_Mask
pop A
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_fIsData
; FUNCTION NAME: ADCINC14_fIsDataAvailable
;
; DESCRIPTION:
; Returns the status of the A/D Data is set whenever a new data
; value is available.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS:
; A Returns data status A == 0 no data available
; A != 0 data available
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
ADCINC14_fIsData:
_ADCINC14_fIsData:
ADCINC14_fIsDataAvailable:
_ADCINC14_fIsDataAvailable:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ADCINC14_bfStatus
mov A, [ADCINC14_bfStatus] ; Get status byte
and A, ADCINC14_fDATA_READY ; Mask off other bits
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_iGetDataClearFlag
; FUNCTION NAME: ADCINC14_iGetData
;
; DESCRIPTION:
; Returns the data from the A/D. Does not check if data is available.
; iGetDataClearFlag clears the result ready flag as well.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS:
; A:X return the ADC result.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
ADCINC14_iGetDataClearFlag:
_ADCINC14_iGetDataClearFlag:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ADCINC14_bfStatus
and [ADCINC14_bfStatus], ~ADCINC14_fDATA_READY ; Clear Data ready bit
mov X, [(ADCINC14_iResult + MSB)]
mov A, [(ADCINC14_iResult + LSB)]
RAM_EPILOGUE RAM_USE_CLASS_4
ret
ADCINC14_iGetData:
_ADCINC14_iGetData:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ADCINC14_bfStatus
mov X, [(ADCINC14_iResult + MSB)]
mov A, [(ADCINC14_iResult + LSB)]
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: ADCINC14_ClearFlag
;
; DESCRIPTION:
; Clears the data ready flag.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: NA
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
ADCINC14_ClearFlag:
_ADCINC14_ClearFlag:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ADCINC14_bfStatus
and [ADCINC14_bfStatus], ~ADCINC14_fDATA_READY ; Clear Data ready bit
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
; End of File ADCINC14.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -