⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csa_1.asm

📁 电容感应程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: CSA_1.asm
;;   @Versions@
;;  Generated by PSoC Designer ver 4.3  b1884 : 23 June, 2006
;;
;;  DESCRIPTION: CSA User Module software implementation file for the 20x34 
;;               PSoC family of devices.
;;
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress Semiconductor 2000-2006. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************

include "m8c.inc"
include "memory.inc"
include "CSA_1.inc"

;-----------------------------------------------
;  Global Labels
;-----------------------------------------------

; Exported functions
export _CSA_1_Start
export  CSA_1_Start
export _CSA_1_Stop
export  CSA_1_Stop
export _CSA_1_ClearSensors
export  CSA_1_ClearSensors
export _CSA_1_wReadSensor
export  CSA_1_wReadSensor
export _CSA_1_wGetPortPin
export  CSA_1_wGetPortPin
export _CSA_1_EnableSensor
export  CSA_1_EnableSensor
export _CSA_1_DisableSensor
export  CSA_1_DisableSensor
export _CSA_1_ScanSensor
export  CSA_1_ScanSensor
export _CSA_1_ScanAllSensors
export  CSA_1_ScanAllSensors 

; Exported variables
export  CSA_1_bfStatus
export _CSA_1_bfStatus
export  CSA_1_bSensorNum
export _CSA_1_bSensorNum
export  CSA_1_waSnsResult
export _CSA_1_waSnsResult
export _CSA_1_baDACCodeBaseline

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA InterruptRAM (RAM, REL, CON)

 CSA_1_bBitMask:                        BLK  1  ; Temp bitmask byte
_CSA_1_bfStatus:                                ; Status byte
 CSA_1_bfStatus:                        BLK  1
_CSA_1_bSensorNum:                              ; Current sensor to scan
 CSA_1_bSensorNum:                      BLK  1
_CSA_1_bScanWeight:                             ; SA helper variable
 CSA_1_bScanWeight:                     BLK  1
_CSA_1_bTempDACD:                               ; SA helper variable
 CSA_1_bTempDACD:                       BLK  1

AREA bss
_CSA_1_waSnsResult:                             ; Array of ints, one entry for each sensor
 CSA_1_waSnsResult:                     BLK  (2*CSA_1_TotalSensorCount)
_CSA_1_baDACCodeBaseline:                       ; DAC Code found with SA
 CSA_1_baDACCodeBaseline:               BLK  CSA_1_TotalSensorCount

;@PSoC_UserCode_INIT@ (Do not change this line.)
;---------------------------------------------------
; Insert your custom declarations below this banner
;---------------------------------------------------

;------------------------
; User Includes
;------------------------


;------------------------
; User Constant Definitions
;------------------------


;------------------------
; User Variable Allocation
;------------------------


;---------------------------------------------------
; Insert your custom declarations above this banner
;---------------------------------------------------
;@PSoC_UserCode_END@ (Do not change this line.)

;------------------------
;  Constant Definitions
;------------------------

AREA UserModules (ROM, REL, CON)

LSB:  equ  1
MSB:  equ  0

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_Start(void)
;
;  DESCRIPTION:
;  Connects external cap; sets up comparator
;  disables all possible analog mux bus
;  connections; shunts all sensor pins to ground.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:  
;    None
;
;  RETURNS:      None.   
;  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.
;
 CSA_1_Start:
_CSA_1_Start:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
   
   mov reg[AMUXCFG], 0Ch | CSA_1_EXTERNAL_CAP         ; Enable external cap
   or  reg[CMP_CR0], 01h                                  ; Enable the Comparator

   call  CSA_1_ClearSensors                           ; Loop through all sensors and deactivates them
                                                          ; This sets the pin to the proper drive mode (strong low).

   mov   A,CSA_1_TotalSensorCount                     ; Loop through to do Successive Approximation on the DAC current
   dec   A
.InitLoop:                                          
   push  A
   call  CSA_1_wGetPortPin
   call  CSA_1_EnableSensor
   call  CSA_1_bFindDACCodeBaseline
   pop   X
   RAM_X_POINTS_TO_INDEXPAGE
   RAM_SETPAGE_IDX >CSA_1_baDACCodeBaseline
   mov   [X+CSA_1_baDACCodeBaseline],A
   push  X
   mov   A,X
   call  CSA_1_wGetPortPin
   call  CSA_1_DisableSensor
   pop   A
   dec   A
   jnc   .InitLoop

   IF(CSA_1_EXTERNAL_CAP & 01h)
   mov   X, 00h
   mov   A, 02h 
   call CSA_1_EnableSensor
   ENDIF

   IF(CSA_1_EXTERNAL_CAP & 02h)
   mov   X, 00h
   mov   A, 08h 
   call CSA_1_EnableSensor
   ENDIF

   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_bFindDACCodeBaseline(void)
;
;  DESCRIPTION:
;  Performs successive apporiximation to find the DAC setting that results
;  in a voltage closest to the reference
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None.
;  RETURNS:      DAC code for the currently enabled sensor via Successive Aprox
;  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.
;
 CSA_1_bFindDACCodeBaseline:
_CSA_1_bFindDACCodeBaseline:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   ; Set scan weight to initial state
   mov [CSA_1_bScanWeight], 80h
   ; Start current at mid value
   mov reg[IDAC_D], 80h
   mov [CSA_1_bTempDACD], 80h

.SARLoop:
   or reg[CSA_1_CapSense_CR0_REG], 01h                               ; Enable the CapSense block, starts the switching circuitry

   mov a, CSA_1_SettlingTime                                         ; Settling time
.DelayLoop:
   dec a
   jnc .DelayLoop

   tst reg[CMP_RDC], 10h                                             ; Check if comparator is high
   jz .KeepBit
.ClearBit:
   mov a, [CSA_1_bScanWeight]
   cpl a
   and [CSA_1_bTempDACD], a
.KeepBit:
   and reg[CSA_1_CapSense_CR0_REG], ~(01h)                           ; Disable Capsense block
   and F, ~04h ; Clear carry bit	
   rrc [CSA_1_bScanWeight]
   jc .EndSARStep	
   mov	a, [CSA_1_bScanWeight]
   or [CSA_1_bTempDACD], a
   mov a, [CSA_1_bTempDACD]
   mov reg[IDAC_D], a                                                ; Update DAC register to new value
   jmp .SARLoop
.EndSARStep:
   mov a, [CSA_1_bTempDACD]
   mov reg[IDAC_D], a                                                ; Return DAC register value
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_ClearSensors(void)
;
;  DESCRIPTION:
;    Clears all sensor connections to the analog mux bus and shunts all sensor
;    pins to ground.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None.
;  RETURNS:      None
;  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.
;
 CSA_1_ClearSensors:
_CSA_1_ClearSensors:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   mov   A,CSA_1_TotalSensorCount                     ; Check if key value in range.
   dec   A
.InitLoop:                                            ; Loop through all sensors and deactivate
   push  A
   call  CSA_1_wGetPortPin
   call  CSA_1_DisableSensor
   pop   A
   dec   A
   jnc   .InitLoop
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_Stop(void)
;
;  DESCRIPTION:
;  Disables RO interrupt; disables the relaxation oscillator circuitry;
;  clears scan active flag; disables all sensors and shunts them to ground.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None.
;  RETURNS:      Nothing.
;  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.
;
 CSA_1_Stop:
_CSA_1_Stop:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   CSA_1_DisableInt_M                                                ; Disable scanner interrupts
   and reg[CSA_1_CapSense_CR0_REG], ~(01h)                           ; Disable Capsense block
   and  [CSA_1_bfStatus],~(CSA_1_SCAN_ACTIVE)                        ; Clear scan active flag
   call  CSA_1_ClearSensors                                          ; Loop through all keys and deactivate
   and  reg[CMP_CR0], ~01h                                           ; Disable the Comparator
   mov  reg[AMUXCFG], 0                                              ; Disable external cap

   IF(CSA_1_EXTERNAL_CAP & 01h)
   mov   X, 00h
   mov   A, 02h 
   call CSA_1_DisableSensor
   ENDIF

   IF(CSA_1_EXTERNAL_CAP & 02h)
   mov   X, 00h
   mov   A, 08h 
   call CSA_1_DisableSensor
   ENDIF
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -