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

📄 csd2x_1.asm

📁 带触摸按键的高端电磁炉设计 该方案采用CYPRESS的新器件CY8C22545,是一款专门针对中高端的家电触摸产品设计。除了集成触摸按键功能外
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;  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_SetLeftRefValue:
_CSD2X_1_SetLeftRefValue:
    RAM_PROLOGUE RAM_USE_CLASS_1

	asl A                                                 ; Shift left for multiply on two
	asl A                                                 ; Shift left for multiply on two
	M8C_SetBank1
    mov reg[VDAC50CR0], A                              ; Set new reference value
	M8C_SetBank0

    RAM_EPILOGUE RAM_USE_CLASS_1
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_SetRightRefValue
;  DESCRIPTION:
;        Set Right Channel Reference Value
;-----------------------------------------------------------------------------
;  ARGUMENTS: A = Reference value 0...7
;  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_SetRightRefValue:
_CSD2X_1_SetRightRefValue:
   RAM_PROLOGUE RAM_USE_CLASS_1

	asl A                                                 ; Shift left for multiply on two
	asl A                                                 ; Shift left for multiply on two
	M8C_SetBank1
    mov reg[VDAC51CR0], A                             ; Set new reference value
	M8C_SetBank0

    RAM_EPILOGUE RAM_USE_CLASS_1
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_SetLeftDACValue
;  DESCRIPTION:
;      Set Left Channel DAC Value
;-----------------------------------------------------------------------------
;  ARGUMENTS: A = Reference value 0...255
;  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_SetLeftDACValue:
_CSD2X_1_SetLeftDACValue:
   RAM_PROLOGUE RAM_USE_CLASS_1

	mov reg[IDACL_D], A                                  ; Write new DAC value

   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_SetRightDACValue
;  DESCRIPTION:
;       Set Right Channel DAC Value
;-----------------------------------------------------------------------------
;  ARGUMENTS: A = Reference value 0...255
;  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_SetRightDACValue:
_CSD2X_1_SetRightDACValue:
   RAM_PROLOGUE RAM_USE_CLASS_1

	mov reg[IDACR_D], A                                  ; Write new DAC value

   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_SetDACRange
;  DESCRIPTION:
;       Set DAC range for both channels
;-----------------------------------------------------------------------------
;  ARGUMENTS: A = Range constant
;  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_SetDACRange:
_CSD2X_1_SetDACRange:
   RAM_PROLOGUE RAM_USE_CLASS_1

	mov X, A                                             ; Save range value

	M8C_SetBank1

	; Range 16x
	mov A, reg[DAC_CR0]                                   ; Read range value
    and A, ~08h                                        ; Clear range bit
	mov [CSD2X_1_bBitMask], A                             ; Store DAC register
	mov A, X                                              ; Restore range value
	and A, ~01h                                           ; Clear 2X range bit
    or [CSD2X_1_bBitMask], A                           ; Set 16X range bit
	mov A, [CSD2X_1_bBitMask]
	mov reg[DAC_CR0], A                                   ; Write new range x 16

	; Range 2x/4x
	mov A, reg[DAC_CR1]                                   ; Read range value
    and A, ~01h                                        ; Clear range bit
	mov [CSD2X_1_bBitMask], A                             ; Store DAC register
	mov A, X                                              ; Restore range value
	and A, ~08h                                           ; Clear 16X range bit
    or [CSD2X_1_bBitMask], A                           ; Set 2X range bit
	mov A, [CSD2X_1_bBitMask]
	mov reg[DAC_CR1], A                                   ; Write new range x 2

	M8C_SetBank0

   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

IF CSD2X_1_AUTOCALIBRATION
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: CSD2X_1_Calibrate
;  DESCRIPTION:
;       Set optimal level of DAC ranges
;-----------------------------------------------------------------------------
;  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_Calibrate:
_CSD2X_1_Calibrate:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR 0

   ; Left part
   mov   A,CSD2X_1_TotalLeftSensorCount
   dec   A

.ScanLoopL:                                                ; Loop through all left sensors and scan
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineL
   mov X, A
   mov [X+CSD2X_1_baDACCodeBaselineL], 80h             ; Set left DAC value as half of range
   mov   [CSD2X_1_wTmp2+LSB], 8                        ; Fill loop counter
   mov   [CSD2X_1_wTmp2+MSB], 80h                      ; Set DAC register mirror

   push  A                                                 ; Save current sensor number
   index CSD2X_1_Resolution_Table_Left                 ; A contains the resolution number
   index CSD2X_1_Timer_Res_Table                       ; A contains the resolution value
   asr A                                                   ; Value to calibrate is half of range
   mov [CSD2X_1_bSensorNum], A                         ; Save calibration value
.L0:
   pop A                                                   ; Restore sensor number
   push A                                                  ; Save current sensor number

   mov X, 0FFh                                             ; Scan only left sensors
   call  CSD2X_1_ScanSensor                            ; Scan current sensor
   RAM_PROLOGUE RAM_USE_CLASS_3                            ; Restore paging mode after function call

   pop A
   push A                                                  ; Get sensor number
   index CSD2X_1_Order_Table_Left                      ; Get sensor location in memory
   asl A
   mov X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult                ; Compare Raw counts to half of resolution range
   mov   A, [X+CSD2X_1_waSnsResult+LSB]
   cmp   A, 0FFh
   mov   A, [X+CSD2X_1_waSnsResult+MSB]
   sbb   A, [CSD2X_1_bSensorNum]
   jnc   .L1
   pop X                                                   ; if rawcounts < range/2
   push X
   mov   A, [CSD2X_1_wTmp2+MSB]
   cpl   A                                                 ; Decrease DAC
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineL
   and [X+CSD2X_1_baDACCodeBaselineL], A               ; Write new value to memory
.L1:
   pop X                                                   ; Restore sensor number
   push X
   asr   [CSD2X_1_wTmp2+MSB]                           ; Increase IDAC mirror
   and   [CSD2X_1_wTmp2+MSB], ~80h
   mov   A, [CSD2X_1_wTmp2+MSB]
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineL
   or    [X+CSD2X_1_baDACCodeBaselineL], A             ; Increase IDAC value
   dec   [CSD2X_1_wTmp2+LSB]                           ; Decrement loop counter
   jnz   .L0

   pop   A                                                 ; Restore sensor number
   dec   A                                                 ; Scan enxt sensor
   jnc   .ScanLoopL

; Right Part
   mov   A,CSD2X_1_TotalRightSensorCount               ; Loop through all right sensors and scan
   dec   A

.ScanLoopR:
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineR
   mov X, A
   mov [X+CSD2X_1_baDACCodeBaselineR], 80h             ; Set left DAC value as half of range
   mov   [CSD2X_1_wTmp2+LSB], 8                        ; Set loop counter
   mov   [CSD2X_1_wTmp2+MSB], 80h                      ; Set DAC mirror

   push  A                                                 ; Save current sensor number
   index CSD2X_1_Resolution_Table_Right                ; A contains the resolution number
   index CSD2X_1_Timer_Res_Table                       ; A contains the resolution value
   asr A                                                   ; Set calibration value as half of range
   mov [CSD2X_1_bSensorNum], A
.L2:
   pop X                                                   ; Restore sensor number
   push X

   mov A, 0FFh                                             ; Scan only Right sensors
   call  CSD2X_1_ScanSensor
   RAM_PROLOGUE RAM_USE_CLASS_3                            ; Restore paging mode after function call

   pop A                                                   ; Restore sensor number
   push A
   index CSD2X_1_Order_Table_Right                     ; Get sensor location in memory
   asl A
   mov X, A
   RAM_SETPAGE_IDX >CSD2X_1_waSnsResult                ; Conpare raw counts and resolution value
   mov   A, [X+CSD2X_1_waSnsResult+LSB]
   cmp   A, 0FFh
   mov   A, [X+CSD2X_1_waSnsResult+MSB]
   sbb   A, [CSD2X_1_bSensorNum]
   jnc   .L3
   pop X                                                   ; if rawcounts < range/2
   push X
   mov   A, [CSD2X_1_wTmp2+MSB]
   cpl   A                                                 ; decrease IDAC
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineR
   and [X+CSD2X_1_baDACCodeBaselineR], A               ; Write new value to memory
.L3:
   pop X                                                   ; Restore sensor number
   push X
   asr   [CSD2X_1_wTmp2+MSB]                           ; Increase IDAC
   and   [CSD2X_1_wTmp2+MSB], ~80h
   mov   A, [CSD2X_1_wTmp2+MSB]
   RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineR
   or    [X+CSD2X_1_baDACCodeBaselineR], A             ; Write new IDAC value
   dec   [CSD2X_1_wTmp2+LSB]                           ; Decrease loop counter
   jnz   .L2

   pop   A                                                  ; Restore sensor number
   dec   A                                                  ; Scan next sensor
   jnc   .ScanLoopR

   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION
ENDIF

⌨️ 快捷键说明

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