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

📄 csd2x_1hl.asm

📁 带触摸按键的高端电磁炉设计 该方案采用CYPRESS的新器件CY8C22545,是一款专门针对中高端的家电触摸产品设计。除了集成触摸按键功能外
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;  ARGUMENTS:
;      A => sensor index
;
;  RETURNS:
;      A => 1 if sensor is active, 0 otherwise
;
;  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.
;
 CSD2X_1_bIsSensorActive:
_CSD2X_1_bIsSensorActive:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   push A
   mov X,A
   RAM_SETPAGE_IDX >CSD2X_1_baBtnFThreshold
   mov A, [X+CSD2X_1_baBtnFThreshold]
   mov [CSD2X_1_wTmpBtnFThreshold+LSB], A
   mov [CSD2X_1_wTmpBtnFThreshold+MSB], 0

   pop A
   push A
   call CSD2X_1_GetOnMask
   RAM_SETPAGE_IDX >CSD2X_1_baSnsOnMask
   and A, [X+CSD2X_1_baSnsOnMask]
   jnz .WasOn

.WasOff:
   ; Check the difference counts against the threshold
   mov A, [CSD2X_1_bHysteresis]
   add [CSD2X_1_wTmpBtnFThreshold+LSB], A
   adc [CSD2X_1_wTmpBtnFThreshold+MSB], 0
   pop A
   asl A
   mov X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsDiff
   mov A, [X+CSD2X_1_waSnsDiff+LSB]
   sub A, [CSD2X_1_wTmpBtnFThreshold+LSB]
   mov A, [X+CSD2X_1_waSnsDiff+MSB]
   sbb A, [CSD2X_1_wTmpBtnFThreshold+MSB]
   jc .NotActive
   mov A, X
   asr A
   mov X, A
   RAM_SETPAGE_IDX >CSD2X_1_baSnsDebounce
   mov A, [X+CSD2X_1_baSnsDebounce]
   dec A
   mov [X+CSD2X_1_baSnsDebounce], A
   push A
   mov A, X
   asl A
   mov X, A
   pop A
   jnz .NotActiveDebouncing
   jmp .Active

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

.Active:
   mov A, X
   asr A
   call CSD2X_1_GetOnMask
   RAM_SETPAGE_IDX >CSD2X_1_baSnsOnMask
   or [X+CSD2X_1_baSnsOnMask], A
   mov A, 1
   jmp .EndIsSensorActive
.NotActive:
   mov A, X
   asr A
   push A
   call CSD2X_1_GetOnMask
   cpl A
   RAM_SETPAGE_IDX >CSD2X_1_baSnsOnMask
   and [X+CSD2X_1_baSnsOnMask], A
   RAM_SETPAGE_IDX >CSD2X_1_baSnsDebounce
   pop X
   mov A, [CSD2X_1_bDebounce]
   mov [X+CSD2X_1_baSnsDebounce], A
   mov A, 0
   jmp .EndIsSensorActive
.NotActiveDebouncing:
   mov A, X
   asr A
   call CSD2X_1_GetOnMask
   cpl A
   RAM_SETPAGE_IDX >CSD2X_1_baSnsOnMask
   and [X+CSD2X_1_baSnsOnMask], A
   mov A, 0
.EndIsSensorActive:
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret

.ENDSECTION

 CSD2X_1_GetOnMask:
_CSD2X_1_GetOnMask:
   push A
   asr A
   asr A
   asr A
   mov X, A
   pop A
   and A, 7h
   index CSD2X_1_bitlookup
   ret

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


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_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.
;
 CSD2X_1_SetDefaultFingerThresholds:
_CSD2X_1_SetDefaultFingerThresholds:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_IDX >CSD2X_1_baBtnFThreshold

   mov   X, CSD2X_1_TotalSensorCount-1                ; Check if key value in range.
.ThresholdLoop:                                       ; Loop through all sensors and scan
   mov   A, X
   index CSD2X_1_FingerThreshold_Table
   mov   [X+CSD2X_1_baBtnFThreshold], A
   dec   X
   jnc   .ThresholdLoop
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_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.
;
 CSD2X_1_InitializeBaselines:
_CSD2X_1_InitializeBaselines:
   RAM_PROLOGUE RAM_USE_CLASS_3
   
   call CSD2X_1_ScanAllSensors
   
   mov   A,CSD2X_1_TotalLeftSensorCount                ; Scan all left sensors
   dec   A
   mov   X,CSD2X_1_TotalRightSensorCount               ; Scan all right sensors
   dec   X
.ScanLoop:                                                ; Loop through all sensors and scan
   push  X
   push  A
   call  CSD2X_1_ScanSensor                            ; Scan left and right sensors
   
   ; Fill Left Value
   RAM_X_POINTS_TO_INDEXPAGE
   pop   A                                                 ; Restore sensor number
   push A
   index CSD2X_1_Order_Table_Left                      ; Get sensor location in memory
   asl   A
   mov   X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult                ; Fill baseline array
   mov A, [X+CSD2X_1_waSnsResult+LSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+LSB], A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult
   mov A, [X+CSD2X_1_waSnsResult+MSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+MSB], A

   ; Right Value
   RAM_X_POINTS_TO_INDEXPAGE
   pop A                                                   ; Restore sensor number
   pop X 
   push A
   push X
   mov A, X
   index CSD2X_1_Order_Table_Right                     ; Get sensor location in memory
   asl   A
   mov   X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult                ; Fill baseline array
   mov A, [X+CSD2X_1_waSnsResult+LSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+LSB], A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult
   mov A, [X+CSD2X_1_waSnsResult+MSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+MSB], A
   
   pop   X                                                 ; Restore right sensor number
   mov A, X
   cmp A, 0FFh                                             ; Is this end of right sensors?
   jnc .Dec0
   dec   X                                                 ; Scan next right sensor
.Dec0:
   pop   A                                                 ; Restore left sensor number
   cmp A, 0FFh                                             ; Is this end of left sensors?
   jnc .Check
   dec   A                                                 ; Scan next left sensor
   jnc .ScanLoop
.Check:                                                    ; Check right sensors for the end of range
   swap A, X
   cmp A, 0FFh                                             ; Is this end of right sensors?
   jnc .End
   swap A, X
   jmp .ScanLoop                                           ; Scan enxt pair of sensors
.End: 
   
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_InitializeSensorBaseline(BYTE bSensorNum)
;
;  DESCRIPTION:
;    Scans selected sensor to find initial raw count value and load this
;    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.
;
 CSD2X_1_InitializeSensorBaseline:
_CSD2X_1_InitializeSensorBaseline:
   RAM_PROLOGUE RAM_USE_CLASS_3
   
   push  A                                             ; Save sensor number
   
   ; Look into left order array to find selected sensor
   mov X, CSD2X_1_TotalLeftSensorCount                 ; Loop throught all left sensors
   dec X
.FindLoop:
   mov A, X
   index CSD2X_1_Order_Table_Left                      ; Get sensor order number
   mov [CSD2X_1_bSensorNum], A                         ; Save value
   pop A
   push A
   cmp A, [CSD2X_1_bSensorNum]                         ; Compare selected sensor number and order number
   jnz .Inc                                            ; Go to scan if equal
   jc .Inc
   mov A, X
   mov X, 0FFh                                         ; Right sensor is not scanned
   jmp .Assign
.Inc: 
   dec X                                               ; Try with next sensor
   jnc .FindLoop

   ; Look into right order array to find selected sensor
   mov X, CSD2X_1_TotalRightSensorCount                ; Loop throught all right sensors
   dec X
.FindLoop1:
   mov A, X
   index CSD2X_1_Order_Table_Right                     ; Get sensor order number
   mov [CSD2X_1_bSensorNum], A                         ; Save value
   pop A
   push A
   cmp A, [CSD2X_1_bSensorNum]                         ; Compare selected sensor number and order number
   jnz .Inc1                                           ; Go to scan if equal
   jc .Inc1
   mov A, 0FFh                                         ; Right sensor is not scanned
   jmp .Assign
.Inc1: 
   dec X                                               ; Try with next sensor
   jnz .FindLoop1
   
.Assign:
   call  CSD2X_1_ScanSensor                            ; Scan sensor
   RAM_X_POINTS_TO_INDEXPAGE
   pop A                                               ; Restore initial sensor number
   asl   A
   mov   X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult                ; Copy sensor raw count to baseline
   mov A, [X+CSD2X_1_waSnsResult+LSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+LSB], A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult
   mov A, [X+CSD2X_1_waSnsResult+MSB]
   RAM_SETPAGE_IDX >CSD2X_1_waSnsBaseline
   mov [X+CSD2X_1_waSnsBaseline+MSB], A
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_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.
;
 CSD2X_1_bIsAnySensorActive:
_CSD2X_1_bIsAnySensorActive:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area

   mov [CSD2X_1_fIsPressed], 0
   mov   A,CSD2X_1_TotalSensorCount
   dec   A
.ThresholdLoop:                                       ; Loop through all sensors
   push  A
   call  CSD2X_1_bIsSensorActive
   cmp   A, 1
   jnz    .NotActive
   mov [CSD2X_1_fIsPressed], 1
.NotActive:
   pop   A
   dec   A
   jnc   .ThresholdLoop
   mov   A, [CSD2X_1_fIsPressed]

.NoneActive:
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_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.
;
 CSD2X_1_UpdateAllBaselines:
_CSD2X_1_UpdateAllBaselines:
   RAM_PROLOGUE RAM_USE_CLASS_4

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

   RAM_EPILOGUE RAM_USE_CLASS_4
   ret

⌨️ 快捷键说明

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