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

📄 csa_1hl.asm

📁 电容感应程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;-----------------------------------------------------------------------------
;  STACK USAGE: 3 BYTES
;
;  ARGUMENTS: 
;      A => 1 if sensor is active, 0 otherwise
;    
;  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_bIsSensorActive:
_CSA_1_bIsSensorActive:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
   RAM_X_POINTS_TO_INDEXPAGE

   push A
   mov X,A
   RAM_SETPAGE_IDX >CSA_1_baBtnFThreshold
   mov A, [X+CSA_1_baBtnFThreshold]
   mov [CSA_1_wTmpBtnFThreshold+LSB], A
   mov [CSA_1_wTmpBtnFThreshold+MSB], 0

   pop A
   push A
   call CSA_1_GetOnMask
   RAM_SETPAGE_IDX >CSA_1_baSnsOnMask
   and A, [X+CSA_1_baSnsOnMask]
   jnz .WasOn

.WasOff:
   ; Check the difference counts against the threshold
   add [CSA_1_wTmpBtnFThreshold+LSB], CSA_1_HYSTERESIS
   adc [CSA_1_wTmpBtnFThreshold+MSB], 0
   pop A
   asl A
   mov X, A
   RAM_SETPAGE_IDX >CSA_1_waSnsDiff
   mov A, [X+CSA_1_waSnsDiff+LSB]
   sub A, [CSA_1_wTmpBtnFThreshold+LSB]
   mov A, [X+CSA_1_waSnsDiff+MSB]
   sbb A, [CSA_1_wTmpBtnFThreshold+MSB] 
   jc .NotActive
   jmp .Active

.WasOn:   
   ; Check the difference counts against the threshold
   sub [CSA_1_wTmpBtnFThreshold+LSB], CSA_1_HYSTERESIS
   sbb [CSA_1_wTmpBtnFThreshold+MSB], 0
   pop A
   asl A
   mov X, A
   RAM_SETPAGE_IDX >CSA_1_waSnsDiff
   mov A, [X+CSA_1_waSnsDiff+LSB]
   sub A, [CSA_1_wTmpBtnFThreshold+LSB]
   mov A, [X+CSA_1_waSnsDiff+MSB]
   sbb A, [CSA_1_wTmpBtnFThreshold+MSB] 
   jc .NotActive

.Active:
   mov A, X
   asr A
   call CSA_1_GetOnMask
   RAM_SETPAGE_IDX >CSA_1_baSnsOnMask
   or [X+CSA_1_baSnsOnMask], A
   mov A, 1
   jmp .EndIsSensorActive
.NotActive:
   mov A, X
   asr A
   call CSA_1_GetOnMask
   cpl A
   RAM_SETPAGE_IDX >CSA_1_baSnsOnMask
   and [X+CSA_1_baSnsOnMask], A   
   mov A, 0
.EndIsSensorActive:
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret

.ENDSECTION

 CSA_1_GetOnMask:
_CSA_1_GetOnMask:
   push A
   asr A
   asr A
   asr A
   mov X, A
   pop A
   and A, 7h
   index CSA_1_bitlookup
   ret

.LITERAL
CSA_1_bitlookup:
	db 01h, 02h, 04h, 08h, 10h, 20h, 40h, 80h
.ENDLITERAL 


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_SetDefaultFingerThresholds(void)
;
;  DESCRIPTION:
;    Sets the FingerThreshold RAM array to the user module parameter value
;
;-----------------------------------------------------------------------------
;
;  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_SetDefaultFingerThresholds:
_CSA_1_SetDefaultFingerThresholds:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_X_POINTS_TO_INDEXPAGE
   RAM_SETPAGE_IDX >CSA_1_baBtnFThreshold

   mov   A,CSA_1_TotalSensorCount                     ; Check if key value in range.
   dec   A
.ThresholdLoop:                                       ; Loop through all sensors and scan
   push  A
   mov   X, A
   mov   [X+CSA_1_baBtnFThreshold], FINGER_THRESHOLD
   pop   A
   dec   A
   jnc   .ThresholdLoop
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_InitializeBaselines(void)
;
;  DESCRIPTION:
;    Scans all sensors to find their initial raw count values and loads these
;    into the baseline
;
;-----------------------------------------------------------------------------
;
;  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_InitializeBaselines:
_CSA_1_InitializeBaselines:
   RAM_PROLOGUE RAM_USE_CLASS_3
   
   mov   A,CSA_1_TotalSensorCount                     ; Get sensor num
   dec   A
.BaselineLoop:                                        ; Loop through all sensors and scan
   push  A
   call  CSA_1_ScanSensor
   RAM_X_POINTS_TO_INDEXPAGE
   pop   A
   push  A
   asl   A
   mov   X, A
   RAM_SETPAGE_IDX >CSA_1_waSnsResult
   mov A, [X+CSA_1_waSnsResult+LSB]
   RAM_SETPAGE_IDX >CSA_1_waSnsBaseline
   mov [X+CSA_1_waSnsBaseline+LSB], A
   RAM_SETPAGE_IDX >CSA_1_waSnsResult
   mov A, [X+CSA_1_waSnsResult+MSB]
   RAM_SETPAGE_IDX >CSA_1_waSnsBaseline
   mov [X+CSA_1_waSnsBaseline+MSB], A
   pop   A
   dec   A
   jnc   .BaselineLoop
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_bIsAnySensorActive(void)
;
;  DESCRIPTION:
;    Checks to see if any sensor is currently active
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None.
;  RETURNS:      1 if any active, 0 if none active
;  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_bIsAnySensorActive:
_CSA_1_bIsAnySensorActive:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   mov [CSA_1_fIsPressed], 0
   mov   A,CSA_1_TotalSensorCount
   dec   A
.ThresholdLoop:                                       ; Loop through all sensors
   push  A
   call  CSA_1_bIsSensorActive
   cmp   A, 1
   jnz    .NotActive
   mov [CSA_1_fIsPressed], 1
.NotActive:
   pop   A
   dec   A
   jnc   .ThresholdLoop
   mov   A, [CSA_1_fIsPressed]

.NoneActive:
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_UpdateAllBaselines(void)
;
;  DESCRIPTION:
;    Scans all sensors to find their raw count values
;
;-----------------------------------------------------------------------------
;
;  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_UpdateAllBaselines:
_CSA_1_UpdateAllBaselines:
   RAM_PROLOGUE RAM_USE_CLASS_4

   mov   A,CSA_1_TotalSensorCount
   dec   A
.ThresholdLoop:                                       ; Loop through all sensors
   push  A
   call  CSA_1_UpdateSensorBaseline
   pop   A
   dec   A
   jnc   .ThresholdLoop

   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

IF CSA_1_SLIDERS_EXIST
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSA_1_wGetCentroidPos(BYTE bSnsGroup)
;
;  DESCRIPTION:
;      Checks the difference array for a centroid.  If one exists, the offset 
;      (within the whole difference arrary) and length are placed in the 
;      bCentroidLength and bCentroidStart variables.
;
;      Then the function finds and returns the position of the centroid in the 
;      difference array.  
;     
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: 
;       A => Sensor Group
;       Sensor Group = 0 for the independent sensors group
;       Sensor Group = 1 for the first slider group
;       Sensor Group = 2 for the second slider group
;    
;  RETURNS:    
;      iCtrdPos -> position of the centroid
;
;  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_wGetCentroidPos:
_CSA_1_wGetCentroidPos:
; Legacy function name labels below, do not use for new designs
 CSA_1_bGetCentroidPos:
_CSA_1_bGetCentroidPos:
 CSA_1_iGetCentroidPos:
_CSA_1_iGetCentroidPos:
; End legacy function names
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
   RAM_X_POINTS_TO_INDEXPAGE

; First get the starting location and size of this sensor group
   asl A ; multiply by two to get diplex
   mov X, A
   index CSA_1_Diplex_Table ; get the diplex table MSB and LSB
   mov [CSA_1_bDiplexMSB], A
   mov A, X
   inc A
   index CSA_1_Diplex_Table
   mov [CSA_1_bDiplexLSB], A
   mov A, X
   mov [CSA_1_bStartIndex], A ; Use bStartIndex as a temp storage byte
   asl A				  
   add [CSA_1_bStartIndex], A
   mov A, [CSA_1_bStartIndex] ; A now has slider offset multiplied by six
   mov X, A
   index CSA_1_Group_Table ; get first sensor index
   mov [CSA_1_bEndOfArray], A
   mov [CSA_1_bCurPos], A
   mov [CSA_1_bStartIndex], A
   mov A, X
   inc A
   index CSA_1_Group_Table ; get size of group
   add [CSA_1_bEndOfArray], A ; Store for later
   mov A, X
   add A, 2
   index CSA_1_Group_Table ; get if diplexed or not and max size of centroid (data = 0 if not diplexed)
   mov [CSA_1_bDiplexInfo], A ; Store for later
   mov A, X

⌨️ 快捷键说明

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