📄 csa_1.asm
字号:
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_1_wGetPortPin(BYTE bSensor)
;
; DESCRIPTION:
; Returns the port and pin mask from a given sensor number. This
; function uses the table CSA_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.
;
CSA_1_wGetPortPin:
_CSA_1_wGetPortPin:
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 CSA_1_Sensor_Table ; 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 CSA_1_Sensor_Table ; A contains bitMask, X has port number
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_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.
;
CSA_1_EnableSensor:
_CSA_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 [CSA_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,[CSA_1_bBitMask]
mov reg[X+DM1_OFFSET],A
xor [CSA_1_bBitMask],FFh ; Invert bitmask
mov A,reg[X+DM0_OFFSET] ; Clear DM0 bit to 0
and A,[CSA_1_bBitMask]
mov reg[X+DM0_OFFSET],A
xor [CSA_1_bBitMask],FFh ; Invert bitmask to get original mask
pop X
mov A,reg[X+MUX_OFFSET]
or A,[CSA_1_bBitMask]
mov reg[X+MUX_OFFSET],A
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_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.
;
CSA_1_DisableSensor:
_CSA_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 [CSA_1_bBitMask],A ; Store bit mask in temp location
M8C_SetBank1
mov A,reg[X+MUX_OFFSET]
and A,[CSA_1_bBitMask]
mov reg[X+MUX_OFFSET],A
M8C_SetBank0
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,[CSA_1_bBitMask]
mov reg[X+DM1_OFFSET],A
xor [CSA_1_bBitMask],FFh ; Invert bitmask back to normal
mov A,reg[X+DM0_OFFSET] ; Set DM0 bit to 1
or A,[CSA_1_bBitMask]
mov reg[X+DM0_OFFSET],A
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_1_ScanSensor(BYTE bStrtIdx)
;
; DESCRIPTION:
; Uses the CapSense switching circuitry to charge to the starting voltage.
; Then a fixed slope ramp is used to measure the starting voltage with a
; 16 bit timer.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A => Sensor Index
;
; 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_ScanSensor:
_CSA_1_ScanSensor:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
RAM_SETPAGE_IDX >CSA_1_baDACCodeBaseline
push A
mov [CSA_1_bSensorNum], A
call CSA_1_wGetPortPin
call CSA_1_EnableSensor
pop X
mov A, [X+CSA_1_baDACCodeBaseline]
.Retry:
mov reg[IDAC_D], A
or reg[CSA_1_CapSense_CR0_REG], 01h ; Enable the CapSense block
mov a, CSA_1_SettlingTime ; Settling Time
.ChargeLoop:
dec a
jnc .ChargeLoop
M8C_DisableGInt
and reg[CSA_1_CapSense_CR0_REG], ~01h ; Disable the CapSense block
or [CSA_1_bfStatus], CSA_1_SCAN_ACTIVE ; Set scan active flag
mov reg[CSA_1_INT_CLR_REG], ~CSA_1_INT_MASK
CSA_1_EnableInt_M ; Enable the CapSense interrupt
mov reg[CSA_1_CapSense_CR2_REG], 00h ; Disable the IDAC
mov reg[IDAC_D], CSA_1_IDACSetting
or reg[CSA_1_CapSense_TIMER_REG], 80h ; Set the ILOW Bit
mov reg[CSA_1_CapSense_CR2_REG], 10h ; Enable the IDAC
or reg[CSA_1_CapSense_CR0_REG], 01h ; Enable the Counter
M8C_EnableGInt
.waitforinterrupt:
tst [CSA_1_bfStatus], CSA_1_SCAN_ACTIVE ; Set scan active flag
jnz .waitforinterrupt
CSA_1_DisableInt_M
tst reg[CSA_1_CapSense_STAT_REG], 20h ; Check for overflow
jz .NoOverflow
.Overflow:
and reg[CSA_1_CapSense_CR0_REG], ~01h ; Disable the Counter
mov reg[CSA_1_CapSense_CR2_REG], 84h ; Restore SA setup
and reg[CSA_1_CapSense_TIMER_REG], ~80h ; Clear the ILOW Bit
; DAC Code Baseline is out of range
call CSA_1_bFindDACCodeBaseline
mov X, [CSA_1_bSensorNum]
mov [X+CSA_1_baDACCodeBaseline], A
jmp .Retry
.NoOverflow:
and reg[CSA_1_CapSense_CR0_REG], ~01h ; Disable the Counter
mov reg[CSA_1_CapSense_CR2_REG], 84h ; Restore SA setup
and reg[CSA_1_CapSense_TIMER_REG], ~80h ; Clear the ILOW Bit
mov A, [CSA_1_bSensorNum]
call CSA_1_wGetPortPin
call CSA_1_DisableSensor
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_1_ScanAllSensors(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_ScanAllSensors:
_CSA_1_ScanAllSensors:
RAM_PROLOGUE RAM_USE_CLASS_4
mov A,CSA_1_TotalSensorCount ; Check if key value in range.
dec A
.ScanLoop: ; Loop through all sensors and scan
push A
call CSA_1_ScanSensor
pop A
dec A
jnc .ScanLoop
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSA_1_wReadSensor(BYTE bSensor)
;
; DESCRIPTION:
; Returns the sensor scan value in A (LSB) and X (MSB)
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A = Sensor number
; RETURNS:
; Scan value of sensor LSB in A and MSB in X
; 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 preserve their values across calls to fastcall16
; functions.
;
CSA_1_wReadSensor:
_CSA_1_wReadSensor:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_IDX >CSA_1_waSnsResult
asl A ; Multiply by two since results are INTs
mov X,A
CSA_1_DisableInt_M
mov A,[X+(CSA_1_waSnsResult+LSB)]
mov X,[X+(CSA_1_waSnsResult+MSB)]
CSA_1_EnableInt_M
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -