📄 csd2x_1.asm
字号:
; Shield electrode configuration Right
IF CSD2X_1_RIGHT_SHIELD_ENABLE
and reg[DAC_CR1], ~40h ; Disable shield to GOO7 for Right channel
ENDIF
; Comparator Configuration
and reg[CSD2X_1_CMP_L_CR2], ~1 ; Disable Left Comparator power
and reg[CSD2X_1_CMP_R_CR2], ~1 ; Disable Right Comparator power
; Prechardge clock configuration
and reg[CMPCLK0], ~30h ; Clear CSD0/CSD1 clocks as left and right comparator clock sources
and reg[AMUXCFG1], ~09h ; Do not use CSD0/CSD1 as clocks sources for prechardge switches
; IDAC Configuration
and reg[DAC_CR0], ~1 ; Disable Right IDAC
and reg[DAC_CR1], ~80h ; Disable Left IDAC
and reg[IDACMODE], ~05h ; Disable IDAC On/Off switch following CSD_CNT_EN
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD2X_1_wGetPortPinLeft(BYTE bSensor)
;
; DESCRIPTION:
; Returns the port and pin mask from a given sensor number. This
; function uses the table CSD2X_1_Sensor_Table to retrieve this
; information.
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A => Sensor Number ( 0 to n )
; RETURNS:
; A <= Sensor Bitmap
; X <= Port Number
;
; 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_wGetPortPinLeft:
_CSD2X_1_wGetPortPinLeft:
RAM_PROLOGUE RAM_USE_CLASS_1
asl A ; Multiply index by 2 since table is 2 bytes per sensor
mov X,A ; Copy index*2 in x for next value
index CSD2X_1_Sensor_Table_Left ; A contains the port value
swap A,X ; Place port value in X and index*2 in A
inc A ; Advance to next value (bitMask)
index CSD2X_1_Sensor_Table_Left ; A contains bitMask, X has port number
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD2X_1_wGetPortPinRight(BYTE bSensor)
;
; DESCRIPTION:
; Returns the port and pin mask from a given sensor number. This
; function uses the table CSD2X_1_Sensor_Table to retrieve this
; information.
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A => Sensor Number ( 0 to n )
; RETURNS:
; A <= Sensor Bitmap
; X <= Port Number
;
; 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_wGetPortPinRight:
_CSD2X_1_wGetPortPinRight:
RAM_PROLOGUE RAM_USE_CLASS_1
asl A ; Multiply index by 2 since table is 2 bytes per sensor
mov X,A ; Copy index*2 in x for next value
index CSD2X_1_Sensor_Table_Right ; A contains the port value
swap A,X ; Place port value in X and index*2 in A
inc A ; Advance to next value (bitMask)
index CSD2X_1_Sensor_Table_Right ; A contains bitMask, X has port number
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD2X_1_EnableSensor(BYTE bSensorMask, BYTE bPort)
;
; DESCRIPTION:
; Configures sensor to be an input to be measured during next measurement
; cycle; places sensor pin's drive mode in Analog Hi-Z mode and connects
; to the analog mux bus.
;
; This function does not do anything with the previous sensor.
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; X => Port Number for given sensor
; A => Bit mask for given sensor
;
; 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_EnableSensor:
_CSD2X_1_EnableSensor:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
; Setup Mux for sensor
mov [CSD2X_1_bBitMask],A ; Store bit mask in temp location
push X
mov A,X ; Multiply port number by four for registor addresses
asl A
asl A
mov X,A ; Restore Port address in X
; Set mode do 10 (Hi-Z Analog) and connect to analog mux bus
M8C_SetBank1
mov A,reg[X+DM1_OFFSET] ; Set DM1 to 1
or A,[CSD2X_1_bBitMask]
mov reg[X+DM1_OFFSET],A
xor [CSD2X_1_bBitMask],FFh ; Invert bitmask
mov A,reg[X+DM0_OFFSET] ; Clear DM0 bit to 0
and A,[CSD2X_1_bBitMask]
mov reg[X+DM0_OFFSET],A
xor [CSD2X_1_bBitMask],FFh ; Invert bitmask to get original mask
pop X
mov A,X
cmp A,04h
jz _CSD2X_1_EnableSensor_1
mov A,reg[X+MUX_OFFSET]
or A,[CSD2X_1_bBitMask]
mov reg[X+MUX_OFFSET],A
M8C_SetBank0
jmp _CSD2X_1_EnableSensor_2
_CSD2X_1_EnableSensor_1:
mov A,reg[MUX_CR4]
or A,[CSD2X_1_bBitMask]
mov reg[MUX_CR4],A
M8C_SetBank0
_CSD2X_1_EnableSensor_2:
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD2X_1_DisableSensor(BYTE bMask, BYTE bPort)
;
; DESCRIPTION:
; Disconnects the desired sensor from the analog mux bus and shunts to
; ground.
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; X => Port Number for given sensor
; A => Bit mask for given sensor
;
; 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_DisableSensor:
_CSD2X_1_DisableSensor:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
; Disconnect sensor from mux
cpl A ; Invert bitmask
mov [CSD2X_1_bBitMask],A ; Store bit mask in temp location
mov A,X
cmp A,4h
jz _CSD2X_1_DisableSensor_1
M8C_SetBank1
mov A,reg[X+MUX_OFFSET]
and A,[CSD2X_1_bBitMask]
mov reg[X+MUX_OFFSET],A
M8C_SetBank0
jmp _CSD2X_1_DisableSensor_2
_CSD2X_1_DisableSensor_1:
M8C_SetBank1
mov A,reg[MUX_CR4]
and A,[CSD2X_1_bBitMask]
mov reg[MUX_CR4],A
M8C_SetBank0
_CSD2X_1_DisableSensor_2:
mov A,X ; Multiply port number by four for register address
asl A
asl A
mov X,A ; Restore Port address in X
; Set mode to 01 (Digital Strong)
M8C_SetBank1
mov A,reg[X+DM1_OFFSET] ; Set DM1 to 0
and A,[CSD2X_1_bBitMask]
mov reg[X+DM1_OFFSET],A
xor [CSD2X_1_bBitMask],FFh ; Invert bitmask back to normal
mov A,reg[X+DM0_OFFSET] ; Set DM0 bit to 1
or A,[CSD2X_1_bBitMask]
mov reg[X+DM0_OFFSET],A
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD2X_1_ScanSensor
; DESCRIPTION:
; Scan Selected pair of Sensors
;-----------------------------------------------------------------------------
; ARGUMENTS: A = Sensor Number Left, X = Sensor Number Left
; RETURNS:
; 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_ScanSensor:
_CSD2X_1_ScanSensor:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
mov [CSD2X_1_bSensorNumLeft], A ; Copy left sensor number
mov [CSD2X_1_bSensorNumRight], X ; Copy right sensor number
cmp [CSD2X_1_bSensorNumLeft], 0FFh ; Check is scan enabled
jnc .ScanRight
; Set Reference
index CSD2X_1_RefValue_Table_Left ; A contains the reference value
call CSD2X_1_SetLeftRefValue
; Set DAC values
IF (CSD2X_1_AUTOCALIBRATION)
mov A, [CSD2X_1_bSensorNumLeft]
mov X, A ; Get array index
RAM_SETPAGE_IDX >CSD2X_1_baDACCodeBaselineL
mov A, [X+CSD2X_1_baDACCodeBaselineL] ; Get left DAC value from memory
call CSD2X_1_SetLeftDACValue
ELSE
mov A, [CSD2X_1_bSensorNumLeft]
index CSD2X_1_DACL_Table ; A contains the left DAC value from ROM table
call CSD2X_1_SetLeftDACValue
ENDIF
; Enable Sensor
mov A, [CSD2X_1_bSensorNumLeft]
call CSD2X_1_wGetPortPinLeft ; Get sensor pin and port
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -