?? csr_1hl.asm
字號:
;;*****************************************************************************
;; FILENAME: CSR_1HL.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 "CSR_1.inc"
;-----------------------------------------------
; Global Symbols
;-----------------------------------------------
export _CSR_1_bUpdateBaseline
export CSR_1_bUpdateBaseline
IF CSR_1_SLIDERS_EXIST
export _CSR_1_bGetCentroidPos
export CSR_1_bGetCentroidPos
ENDIF
;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA InterruptRAM (RAM, REL, CON)
; Global variables
_CSR_1_iaSwBaseline: ; Baseline, one entry for each switch
CSR_1_iaSwBaseline: BLK (2*CSR_1_TotalSwitchCount)
_CSR_1_iaSwDiff: ; ABS Diff of raw and and baseline, one entry for each switch
CSR_1_iaSwDiff: BLK (2*CSR_1_TotalSwitchCount)
_CSR_1_baBtnFThreshold: ; Containing variable finger threshold for each button
CSR_1_baBtnFThreshold: BLK CSR_1_ButtonCount
_CSR_1_baSwOnMask: ; Switch mask array containing on/off state of switches
CSR_1_baSwOnMask: BLK ((CSR_1_TotalSwitchCount-1)/8)+1
_CSR_1_bBaselineUpdateTimer: ; Adjusts baseline when signal is within noise threshold
CSR_1_bBaselineUpdateTimer: BLK 1
_CSR_1_fIsBLValid: ; Flag if baseline is valid
CSR_1_fIsBLValid: BLK 1
IF CSR_1_ESD_DETECTION
; ESD variables used for finger detection
_CSR_1_iaSwDeriv: ; Derivative of raw, one entry for each switch
CSR_1_iaSwDeriv: BLK (2*CSR_1_TotalSwitchCount)
_CSR_1_iaSwPrevResult: ; Previous raw result, one entry for each switch
CSR_1_iaSwPrevResult: BLK (2*CSR_1_TotalSwitchCount)
_CSR_1_baESDDebounce: ; Array containing invalid raw data counter to reinstate BL
CSR_1_baESDDebounce: BLK CSR_1_TotalSwitchCount
_CSR_1_baBaselineResetCounter: ; Containing count to update baseline on finger press on startup
CSR_1_baBaselineResetCounter: BLK CSR_1_TotalSwitchCount
_CSR_1_bAbnormalTimer: ; If an ESD event occurs, this timer prevents button presses
CSR_1_bAbnormalTimer: BLK 1
ENDIF
IF CSR_1_SLIDERS_EXIST
; Global slider variables
_CSR_1_baCtrdStartPos: ; Array containing centroid starting position
CSR_1_baCtrdStartPos: BLK CSR_1_SliderCount
_CSR_1_baCtrdSize: ; Array containing centroid size
CSR_1_baCtrdSize: BLK CSR_1_SliderCount
_CSR_1_baCtrdPkPos: ; Array containing peak position of centroid
CSR_1_baCtrdPkPos: BLK CSR_1_SliderCount
_CSR_1_iaCtrdPkValue: ; Array containing peak value of centroid
CSR_1_iaCtrdPkValue: BLK (2*CSR_1_SliderCount)
ENDIF
; Local variables
_CSR_1_bEndOfArray: ; Temp pointer variable
CSR_1_bEndOfArray: BLK 1
_CSR_1_bDivBtwSw: ; Temp divisions between switches
CSR_1_bDivBtwSw: BLK 1
_CSR_1_fIsPressed: ; Temp variable for if any switch is pressed
CSR_1_fIsPressed: BLK 1
_CSR_1_bCurPos: ; Temp position variable
CSR_1_bCurPos: BLK 1
_CSR_1_bCurPosMask: ; Temp switch mask used in UpdateBaseline
CSR_1_bCurPosMask: BLK 1
_CSR_1_bSwMaskPtr: ; Temp switch mask pointer used in UpdateBaseline
CSR_1_bSwMaskPtr: BLK 1
_CSR_1_bStartIndex: ; Temp Start index
CSR_1_bStartIndex: BLK 1
IF CSR_1_SLIDERS_EXIST
; Local slider variables
_CSR_1_bCtrdPos: ; Temp position variable
CSR_1_bCtrdPos: BLK 1
_CSR_1_iDenom: ; Temp denominator
CSR_1_iDenom: BLK 2
_CSR_1_iNumer: ; Temp numerator
CSR_1_iNumer: BLK 3
_CSR_1_iMultTempX: ; Temp multiplication register
CSR_1_iMultTempX: BLK 3
_CSR_1_iMultTempY: ; Temp multiplication register
CSR_1_iMultTempY: BLK 3
_CSR_1_bCurSlider:
CSR_1_bCurSlider: BLK 1
_CSR_1_bCurCtrdStartPos: ; Temp current centroid start position
CSR_1_bCurCtrdStartPos: BLK 1
_CSR_1_bCurCtrdSize: ; Temp current centroid size
CSR_1_bCurCtrdSize: BLK 1
_CSR_1_bBiggestCtrdStartPos: ; Temp biggest centroid start position
CSR_1_bBiggestCtrdStartPos: BLK 1
_CSR_1_bBiggestCtrdSize: ; Temp biggest centroid size
CSR_1_bBiggestCtrdSize: BLK 1
_CSR_1_iCurPkValue: ; Temp current peak
CSR_1_iCurPkValue: BLK 2
_CSR_1_bCurPkPos: ; Temp current slider pointer
CSR_1_bCurPkPos: BLK 1
_CSR_1_bDiplexInfo: ; Temp flag for diplex of current group
CSR_1_bDiplexInfo: BLK 1
_CSR_1_bDiplexMSB: ; Temp that contains the address of the rom diplex table
CSR_1_bDiplexMSB: BLK 1
_CSR_1_bDiplexLSB:
CSR_1_bDiplexLSB: BLK 1
ENDIF
; Global variables
export _CSR_1_iaSwBaseline
export CSR_1_iaSwBaseline
export _CSR_1_iaSwDiff
export CSR_1_iaSwDiff
export _CSR_1_baBtnFThreshold
export CSR_1_baBtnFThreshold
export _CSR_1_baSwOnMask
export CSR_1_baSwOnMask
export _CSR_1_bBaselineUpdateTimer
export CSR_1_bBaselineUpdateTimer
export _CSR_1_fIsBLValid
export CSR_1_fIsBLValid
IF CSR_1_ESD_DETECTION
; ESD variables
export _CSR_1_iaSwDeriv
export CSR_1_iaSwDeriv
export _CSR_1_iaSwPrevResult
export CSR_1_iaSwPrevResult
export _CSR_1_baESDDebounce
export CSR_1_baESDDebounce
export _CSR_1_baBaselineResetCounter
export CSR_1_baBaselineResetCounter
export _CSR_1_bAbnormalTimer
export CSR_1_bAbnormalTimer
ENDIF
IF CSR_1_SLIDERS_EXIST
; Global slider variables
export _CSR_1_baCtrdStartPos
export CSR_1_baCtrdStartPos
export _CSR_1_baCtrdSize
export CSR_1_baCtrdSize
export _CSR_1_baCtrdPkPos
export CSR_1_baCtrdPkPos
export _CSR_1_iaCtrdPkValue
export CSR_1_iaCtrdPkValue
ENDIF
; Local variables
export _CSR_1_bDivBtwSw
export CSR_1_bDivBtwSw
export _CSR_1_fIsPressed
export CSR_1_fIsPressed
export _CSR_1_bEndOfArray
export CSR_1_bEndOfArray
export _CSR_1_bCurPos
export CSR_1_bCurPos
export _CSR_1_bCurPosMask
export CSR_1_bCurPosMask
export _CSR_1_bSwMaskPtr
export CSR_1_bSwMaskPtr
IF CSR_1_SLIDERS_EXIST
; Local slider variables
export _CSR_1_bCtrdPos
export CSR_1_bCtrdPos
export _CSR_1_iDenom
export CSR_1_iDenom
export _CSR_1_iNumer
export CSR_1_iNumer
export _CSR_1_iMultTempX
export CSR_1_iMultTempX
export _CSR_1_iMultTempY
export CSR_1_iMultTempY
export _CSR_1_bCurCtrdStartPos
export CSR_1_bCurCtrdStartPos
export _CSR_1_bCurCtrdSize
export CSR_1_bCurCtrdSize
export _CSR_1_bBiggestCtrdStartPos
export CSR_1_bBiggestCtrdStartPos
export _CSR_1_bBiggestCtrdSize
export CSR_1_bBiggestCtrdSize
export _CSR_1_iCurPkValue
export CSR_1_iCurPkValue
export _CSR_1_bCurPkPos
export CSR_1_bCurPkPos
export _CSR_1_bDiplexMSB
export CSR_1_bDiplexMSB
export _CSR_1_bDiplexLSB
export CSR_1_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 ah
NOISE_THRESHOLD: equ 5h
BASELINE_UPDATE_RATE: equ 10h
ESD_DEBOUNCE: equ 0h
; 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 0x1 groups counting the free switches.
CSR_1_Group_Table:
_CSR_1_Group_Table:
; Group Table:
; Origin Count Diplex? SliceMultiplier
db 0x0, 0x3, 0x0, 0x00 ; Buttons
db 0x3, 0x8, 0x3, 0x60 ; Slider 1
; 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
DiplexTable_1:
db 0,1,2,3,4,5,6,7,0,3,6,1,4,7,2,5 // 8 switch slider
CSR_1_Diplex_Table:
_CSR_1_Diplex_Table:
db >DiplexTable_0, <DiplexTable_0
db >DiplexTable_1, <DiplexTable_1
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSR_1_GetBaseline(void)
;
; DESCRIPTION:
; Gathers the baseline for all switches.
;-----------------------------------------------------------------------------
; STACK USAGE: none
;
; RAM VARIABLES USED: CSR_1_iaSwResult,
; CSR_1_iaSwBaseline, CSR_1_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.
;
CSR_1_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+CSR_1_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+CSR_1_iaSwBaseline+MSB], 0xff
mov [X+CSR_1_iaSwBaseline+LSB], 0xff
jmp .StoreNextSwitchesBaseline
.StoreRawIntoBaseline:
mov A, [X+CSR_1_iaSwResult+MSB]
mov [X+CSR_1_iaSwBaseline+MSB], A
IF CSR_1_ESD_DETECTION
mov [X+CSR_1_iaSwPrevResult+MSB], A
ENDIF
mov A, [X+CSR_1_iaSwResult+LSB]
mov [X+CSR_1_iaSwBaseline+LSB], A
IF CSR_1_ESD_DETECTION
mov [X+CSR_1_iaSwPrevResult+LSB], A
ENDIF
asl [X+CSR_1_iaSwBaseline+LSB] ; Multiply by four for IIR filter resolution
rlc [X+CSR_1_iaSwBaseline+MSB]
asl [X+CSR_1_iaSwBaseline+LSB]
rlc [X+CSR_1_iaSwBaseline+MSB]
.StoreNextSwitchesBaseline:
inc X
inc X
mov A, X
cmp A, CSR_1_TotalSwitchCount*2
jc .DefineSwitchBaseline
mov [CSR_1_bBaselineUpdateTimer], BASELINE_UPDATE_RATE ; reset the baseline counter
RAM_X_POINTS_TO_STACKPAGE
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSR_1_UpdateBaselineIIR(void)
;
; DESCRIPTION:
; Updates baseline with 1/8 + 7/8 IIR for all switches.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -