📄 sensehl.asm
字号:
;;*****************************************************************************
;; FILENAME: SENSEHL.asm
;; Version: 1.1, Updated on 2005/10/13 at 09:13:22
;; Generated by PSoC Designer ver 4.2 b1013 : 02 September, 2004
;;
;; DESCRIPTION: CSR User Module high level software
;; implementation file for the 21xxx PSoC family of devices.
;;-----------------------------------------------------------------------------
;; Copyright (c) Cypress MicroSystems 2000-2005. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "m8c.inc"
include "memory.inc"
include "SENSE.inc"
;-----------------------------------------------
; Global Symbols
;-----------------------------------------------
export _SENSE_bUpdateBaseline
export SENSE_bUpdateBaseline
IF SENSE_SLIDERS_EXIST
export _SENSE_bGetCentroidPos
export SENSE_bGetCentroidPos
ENDIF
;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA InterruptRAM (RAM, REL, CON)
; Global variables
_SENSE_iaSwBaseline: ; Baseline, one entry for each switch
SENSE_iaSwBaseline: BLK (2*SENSE_TotalSwitchCount)
_SENSE_iaSwDiff: ; ABS Diff of raw and and baseline, one entry for each switch
SENSE_iaSwDiff: BLK (2*SENSE_TotalSwitchCount)
_SENSE_baBtnFThreshold: ; Containing variable finger threshold for each button
SENSE_baBtnFThreshold: BLK SENSE_ButtonCount
_SENSE_baSwOnMask: ; Switch mask array containing on/off state of switches
SENSE_baSwOnMask: BLK ((SENSE_TotalSwitchCount-1)/8)+1
_SENSE_bBaselineUpdateTimer: ; Adjusts baseline when signal is within noise threshold
SENSE_bBaselineUpdateTimer: BLK 1
_SENSE_fIsBLValid: ; Flag if baseline is valid
SENSE_fIsBLValid: BLK 1
IF SENSE_ESD_DETECTION
; ESD variables used for finger detection
_SENSE_iaSwDeriv: ; Derivative of raw, one entry for each switch
SENSE_iaSwDeriv: BLK (2*SENSE_TotalSwitchCount)
_SENSE_iaSwPrevResult: ; Previous raw result, one entry for each switch
SENSE_iaSwPrevResult: BLK (2*SENSE_TotalSwitchCount)
_SENSE_baESDDebounce: ; Array containing invalid raw data counter to reinstate BL
SENSE_baESDDebounce: BLK SENSE_TotalSwitchCount
_SENSE_baBaselineResetCounter: ; Containing count to update baseline on finger press on startup
SENSE_baBaselineResetCounter: BLK SENSE_TotalSwitchCount
_SENSE_bAbnormalTimer: ; If an ESD event occurs, this timer prevents button presses
SENSE_bAbnormalTimer: BLK 1
ENDIF
IF SENSE_SLIDERS_EXIST
; Global slider variables
_SENSE_baCtrdStartPos: ; Array containing centroid starting position
SENSE_baCtrdStartPos: BLK SENSE_SliderCount
_SENSE_baCtrdSize: ; Array containing centroid size
SENSE_baCtrdSize: BLK SENSE_SliderCount
_SENSE_baCtrdPkPos: ; Array containing peak position of centroid
SENSE_baCtrdPkPos: BLK SENSE_SliderCount
_SENSE_iaCtrdPkValue: ; Array containing peak value of centroid
SENSE_iaCtrdPkValue: BLK (2*SENSE_SliderCount)
ENDIF
; Local variables
_SENSE_bEndOfArray: ; Temp pointer variable
SENSE_bEndOfArray: BLK 1
_SENSE_bDivBtwSw: ; Temp divisions between switches
SENSE_bDivBtwSw: BLK 1
_SENSE_fIsPressed: ; Temp variable for if any switch is pressed
SENSE_fIsPressed: BLK 1
_SENSE_bCurPos: ; Temp position variable
SENSE_bCurPos: BLK 1
_SENSE_bCurPosMask: ; Temp switch mask used in UpdateBaseline
SENSE_bCurPosMask: BLK 1
_SENSE_bSwMaskPtr: ; Temp switch mask pointer used in UpdateBaseline
SENSE_bSwMaskPtr: BLK 1
_SENSE_bStartIndex: ; Temp Start index
SENSE_bStartIndex: BLK 1
IF SENSE_SLIDERS_EXIST
; Local slider variables
_SENSE_bCtrdPos: ; Temp position variable
SENSE_bCtrdPos: BLK 1
_SENSE_iDenom: ; Temp denominator
SENSE_iDenom: BLK 2
_SENSE_iNumer: ; Temp numerator
SENSE_iNumer: BLK 3
_SENSE_iMultTempX: ; Temp multiplication register
SENSE_iMultTempX: BLK 3
_SENSE_iMultTempY: ; Temp multiplication register
SENSE_iMultTempY: BLK 3
_SENSE_bCurSlider:
SENSE_bCurSlider: BLK 1
_SENSE_bCurCtrdStartPos: ; Temp current centroid start position
SENSE_bCurCtrdStartPos: BLK 1
_SENSE_bCurCtrdSize: ; Temp current centroid size
SENSE_bCurCtrdSize: BLK 1
_SENSE_bBiggestCtrdStartPos: ; Temp biggest centroid start position
SENSE_bBiggestCtrdStartPos: BLK 1
_SENSE_bBiggestCtrdSize: ; Temp biggest centroid size
SENSE_bBiggestCtrdSize: BLK 1
_SENSE_iCurPkValue: ; Temp current peak
SENSE_iCurPkValue: BLK 2
_SENSE_bCurPkPos: ; Temp current slider pointer
SENSE_bCurPkPos: BLK 1
_SENSE_bDiplexInfo: ; Temp flag for diplex of current group
SENSE_bDiplexInfo: BLK 1
_SENSE_bDiplexMSB: ; Temp that contains the address of the rom diplex table
SENSE_bDiplexMSB: BLK 1
_SENSE_bDiplexLSB:
SENSE_bDiplexLSB: BLK 1
ENDIF
; Global variables
export _SENSE_iaSwBaseline
export SENSE_iaSwBaseline
export _SENSE_iaSwDiff
export SENSE_iaSwDiff
export _SENSE_baBtnFThreshold
export SENSE_baBtnFThreshold
export _SENSE_baSwOnMask
export SENSE_baSwOnMask
export _SENSE_bBaselineUpdateTimer
export SENSE_bBaselineUpdateTimer
export _SENSE_fIsBLValid
export SENSE_fIsBLValid
IF SENSE_ESD_DETECTION
; ESD variables
export _SENSE_iaSwDeriv
export SENSE_iaSwDeriv
export _SENSE_iaSwPrevResult
export SENSE_iaSwPrevResult
export _SENSE_baESDDebounce
export SENSE_baESDDebounce
export _SENSE_baBaselineResetCounter
export SENSE_baBaselineResetCounter
export _SENSE_bAbnormalTimer
export SENSE_bAbnormalTimer
ENDIF
IF SENSE_SLIDERS_EXIST
; Global slider variables
export _SENSE_baCtrdStartPos
export SENSE_baCtrdStartPos
export _SENSE_baCtrdSize
export SENSE_baCtrdSize
export _SENSE_baCtrdPkPos
export SENSE_baCtrdPkPos
export _SENSE_iaCtrdPkValue
export SENSE_iaCtrdPkValue
ENDIF
; Local variables
export _SENSE_bDivBtwSw
export SENSE_bDivBtwSw
export _SENSE_fIsPressed
export SENSE_fIsPressed
export _SENSE_bEndOfArray
export SENSE_bEndOfArray
export _SENSE_bCurPos
export SENSE_bCurPos
export _SENSE_bCurPosMask
export SENSE_bCurPosMask
export _SENSE_bSwMaskPtr
export SENSE_bSwMaskPtr
IF SENSE_SLIDERS_EXIST
; Local slider variables
export _SENSE_bCtrdPos
export SENSE_bCtrdPos
export _SENSE_iDenom
export SENSE_iDenom
export _SENSE_iNumer
export SENSE_iNumer
export _SENSE_iMultTempX
export SENSE_iMultTempX
export _SENSE_iMultTempY
export SENSE_iMultTempY
export _SENSE_bCurCtrdStartPos
export SENSE_bCurCtrdStartPos
export _SENSE_bCurCtrdSize
export SENSE_bCurCtrdSize
export _SENSE_bBiggestCtrdStartPos
export SENSE_bBiggestCtrdStartPos
export _SENSE_bBiggestCtrdSize
export SENSE_bBiggestCtrdSize
export _SENSE_iCurPkValue
export SENSE_iCurPkValue
export _SENSE_bCurPkPos
export SENSE_bCurPkPos
export _SENSE_bDiplexMSB
export SENSE_bDiplexMSB
export _SENSE_bDiplexLSB
export SENSE_bDiplexLSB
ENDIF
;@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
FINGER_THRESHOLD: equ 64h
NOISE_THRESHOLD: equ 32h
BASELINE_UPDATE_RATE: equ 14h
ESD_DEBOUNCE: equ 8h
; The Group Table defines each of the groups of switches or sliders. There
; is one entry for each slider plus one for the free switches. The first
; entry is always the free switchs. Each entry is four bytes.
; The first byte is the index in the Switch Table where the group starts.
; The second byte is how many switches are in that group. For example, in
; a system where there are 6 free switches and two sliders, the first with
; 8 switches and the second with 4, the table would look like the following.
; db 0, 8
; db 8, 8
; db 16, 4
;
; The third byte signifies whether the slider is diplexed or not (1 is
; diplexed, 0 is not diplexed).
;
; The fourth byte is the fixed point multiplier that the slider's
; calculated centroid will be multiplied by to achieve the resolution
; desired in the CSR wizard. The multiplier is a byte containing the
; following definition:
; bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
; x8 x4 x2 x1 x1/2 x1/4 x1/8 x1/16
; The formula for the resolution is:
; Resolution = (SwitchesInSlider - 1) * Multiplier
; For example, if you had a 10 switch slider and you wanted a
; resolution of 100, the multiplier would need to be 11 1/8 to get
; the closest approximation (using sixteenths). Therefore the
; fixed point value would be 0xb2 (8+2+1+1/8)
; There are 0x0 groups counting the free switches.
SENSE_Group_Table:
_SENSE_Group_Table:
; Group Table:
; Origin Count Diplex? SliceMultiplier
db 0x0, 0x8, 0x0, 0x00 ; Buttons
; Diplex table data are produced for a group only when the group is a
; slider and is also diplexed. Otherwise a label is created but no data
; is placed. The data represents the physical representation of the
; switches in their location on the PCB. A label containing the pointer
; to the corresponding table is also produced for referencing in the high-
; level centroid calculation function.
DiplexTable_0:
; This group is not a diplexed slider
SENSE_Diplex_Table:
_SENSE_Diplex_Table:
db >DiplexTable_0, <DiplexTable_0
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: SENSE_GetBaseline(void)
;
; DESCRIPTION:
; Gathers the baseline for all switches.
;-----------------------------------------------------------------------------
; STACK USAGE: none
;
; RAM VARIABLES USED: SENSE_iaSwResult,
; SENSE_iaSwBaseline, SENSE_fIsBLValid
;
; ARGUMENTS:
; None
;
; RETURNS:
; None, baseline is now updated to current value for all switches
;
; 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.
;
SENSE_GetBaseline:
; Define baseline for all switches for the first time
RAM_X_POINTS_TO_INDEXPAGE
RAM_SETPAGE_IDX 0 ; ram will always be in interrupt ram area
mov X, 0
.DefineSwitchBaseline:
tst [X+SENSE_iaSwResult+MSB], 0xC0 ; check for raw beyond 0x3fff
jz .StoreRawIntoBaseline ; If raw counts is greater than 0x3fff, baseline will wrap, force to max
mov [X+SENSE_iaSwBaseline+MSB], 0xff
mov [X+SENSE_iaSwBaseline+LSB], 0xff
jmp .StoreNextSwitchesBaseline
.StoreRawIntoBaseline:
mov A, [X+SENSE_iaSwResult+MSB]
mov [X+SENSE_iaSwBaseline+MSB], A
IF SENSE_ESD_DETECTION
mov [X+SENSE_iaSwPrevResult+MSB], A
ENDIF
mov A, [X+SENSE_iaSwResult+LSB]
mov [X+SENSE_iaSwBaseline+LSB], A
IF SENSE_ESD_DETECTION
mov [X+SENSE_iaSwPrevResult+LSB], A
ENDIF
asl [X+SENSE_iaSwBaseline+LSB] ; Multiply by four for IIR filter resolution
rlc [X+SENSE_iaSwBaseline+MSB]
asl [X+SENSE_iaSwBaseline+LSB]
rlc [X+SENSE_iaSwBaseline+MSB]
.StoreNextSwitchesBaseline:
inc X
inc X
mov A, X
cmp A, SENSE_TotalSwitchCount*2
jc .DefineSwitchBaseline
mov [SENSE_bBaselineUpdateTimer], BASELINE_UPDATE_RATE ; reset the baseline counter
RAM_X_POINTS_TO_STACKPAGE
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: SENSE_UpdateBaselineIIR(void)
;
; DESCRIPTION:
; Updates baseline with 1/8 + 7/8 IIR for all switches.
;-----------------------------------------------------------------------------
; STACK USAGE: none
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -