📄 cmx_adc_chan.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; adcMux8.asm
;; @Version@
;;
;;
;; DESCRIPTION: Low level 8 channel mux for any incremental ADC. This
;; code provides storage for 8 integer results and defines
;; the simple state machine to collect the data.
;;
;;-----------------------------------------------------------------------------
;; Copyright (c) Cypress MicroSystems 2004. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "m8c.inc"
include "memory.inc"
include "Driverdecl.inc"
include "ADC10.inc"
export AdcScanReset
export _AdcScanReset
export AdcScan
export _AdcScan
export iGetAinChanCounts
export _iGetAinChanCounts
export aiADC_Results
export _aiADC_Results
export bADC_Index
export _bADC_Index
export bADC_Mode
export _bADC_Mode
AREA InterruptRAM (RAM, REL, CON)
_bTemp:
bTemp: BLK 2
_bADC_Index:
bADC_Index: BLK 1 ; Index of next scan
_aiADC_Results: ; ADC result RAM allocation
aiADC_Results: BLK (2*CMX_MVOLTS_IN_CHAN_COUNT) ; 2 Bytes per channel
_bADC_Mode:
bADC_Mode: BLK 1 ; 0 => Don't Scan
; 1 => Scan
AREA UserModules (ROM, REL)
.literal
_MVOLTSChannelPins:
MVOLTSChannelPins:
db 00h // MVOLTS_00 connects to Port_0_0
db 07h // MVOLTS_07 connects to Port_0_7
FILTER_TABLE:
_FILTER_TABLE:
db 00 // Disable
db 00 // Disable
muxpinlu:
db 01h, 02h, 04h, 08h, 10h, 20h, 40h, 80h
.endliteral
;-----------------------------------------------------------------------------
; FUNCTION NAME: void AdcGetReset( void )
;
; DESCRIPTION:
; Reset scanning index to zero, and set up input mux for next reading.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; none
;
; RETURNS:
; none
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
AdcScanReset:
_AdcScanReset:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >bADC_Index
mov A,0x00
mov [bADC_Index],A ; Reset index
mov [bADC_Mode],0 ; Don't start scanning yet
// Set up mux for first channel
index MVOLTSChannelPins ; Get port/pin value of first channel
push A ; save it
and A, F0h ; if !port0
jnz .not_port0
pop A
mov reg[ACE01CR1],69h ; switch column 1 comparator input to be the column mux
lcall AMUX8_InputSelect
jmp .the_end
.not_port0:
pop A
mov reg[ACE01CR1],6Fh ; switch column 1 comparator input to be the analog mux bus
lcall GlobalMux_InputSelect
.the_end:
RAM_EPILOGUE RAM_USE_CLASS_4
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: int iGetAinChanCounts(BYTE chan)
;
; DESCRIPTION:
; Returns an integer value from the ADC scanning system
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A => Index of value to return
;
; RETURNS:
; A:X => Integer value returned
; A = MSB
; X = LSB
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
iGetAinChanCounts:
_iGetAinChanCounts:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_IDX >aiADC_Results
asl A ; Mult by 2, since values are ints.
mov X,A ; Set up for indexed read
M8C_DisableGInt ; Disable global interrupts while retrieving
; result to ensure that the MSB and LSB come
; from the same result.
mov A,[X+aiADC_Results] ; Get MSB of integer value
inc X ; Advance to LSB
mov X,[X+aiADC_Results] ; Get LSB of integer value
M8C_EnableGInt
swap A,X ; Put MSB in A and LSB in X
RAM_EPILOGUE RAM_USE_CLASS_3
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: void AdcScan(int iResult)
;
; DESCRIPTION:
; Returns an integer value from the ADC scanning system
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; Latest ADC result
; A:X => Integer value returned
; A = MSB
; X = LSB
;
; RETURNS: none
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
; A => MSB
; X => LSB
HighByte: equ 0
LowByte: equ 1
AdcScan:
_AdcScan:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >bADC_Index
RAM_SETPAGE_IDX >aiADC_Results
tst [bADC_Mode],0x01 ; Don't scan until ADC Cal is complete
jz .AdcScanEnd
push X ; Push LSB
push A ; Push MSB
mov A,[bADC_Index] ; Get current index
asl A ; mult by to for correct index (2 byte ints)
mov X,A ; Setup index register for result array.
asr A
index FILTER_TABLE
jz .no_filter ; jump if no filtering required
.filter:
mov A,[X+aiADC_Results] ; previous MSB
push A ; store previous MSB
mov [bTemp+HighByte],A ; prestore MSB
inc X ; point to LSB
mov A,[X+aiADC_Results] ; previous LSB
mov [bTemp+LowByte],A ; prestore LSB
asl [bTemp+LowByte] ; mult LSB by 2
rlc [bTemp+HighByte] ; mult MSB by 2
add [bTemp+LowByte],A ; add to LSB
pop A ; restore previous MSB
adc [bTemp+HighByte],A ; add to MSB
pop A ; New MSB
add [bTemp+HighByte],A ; add new MSB
pop A ; New LSB
add [bTemp+LowByte],A ; add new LSB
adc [bTemp+HighByte],0x00 ; add carry flag
asr [bTemp+HighByte] ; dividing sum
rrc [bTemp+LowByte] ; by 4 to obtain
asr [bTemp+HighByte] ; 3/4 + 1/4
rrc [bTemp+LowByte] ; filter
mov A,[bTemp+LowByte]
mov [X+aiADC_Results],A ; write LSB to array
dec X ; point to MSB
mov A,[bTemp+HighByte]
mov [X+aiADC_Results],A ; write MSB to array
jmp .next_scan
.no_filter:
pop A ; Pop result
mov [X+aiADC_Results],A ; Write it to array
inc X ; Advance pointer to LSB
pop A ; Pop LSB of result
mov [X+aiADC_Results],A ; Write it to array
.next_scan:
mov A,[bADC_Index] ; Get current index
index MVOLTSChannelPins ; Get port/pin value of channel
and A, F0h ; if port0
jz .skip_InputClear
RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
lcall GlobalMux_InputClear ; Disconnect from the bus
RAM_RESTORE_NATIVE_PAGING ; Restore native paging
.skip_InputClear:
inc [bADC_Index] ; Advance to next value
cmp [bADC_Index],(CMX_MVOLTS_IN_CHAN_COUNT) ; Check to see if we have if index should be reset.
jc .SetMux
mov [bADC_Index],0x00 ; Reset index back to zero
.SetMux:
mov A,[bADC_Index] ; Get current index
index MVOLTSChannelPins ; Get port/pin value of channel
push A ; save it
and A, F0h ; if !port0
jnz .not_port0
pop A
mov reg[ACE01CR1],69h ; switch column 1 comparator input to be the column mux
RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
lcall AMUX8_InputSelect
RAM_RESTORE_NATIVE_PAGING ; Restore native paging
jmp .AdcScanEnd
.not_port0:
pop A
mov reg[ACE01CR1],6Fh ; switch column 1 comparator input to be the analog mux bus
RAM_CHANGE_PAGE_MODE( FLAG_PGMODE_11b )
lcall GlobalMux_InputSelect
RAM_RESTORE_NATIVE_PAGING ; Restore native paging
.AdcScanEnd:
RAM_EPILOGUE RAM_USE_CLASS_4
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: GlobalMux_InputSelect
;
; DESCRIPTION:
; Place the signal from one of fifty I/O port pins on the Global Input bus.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A contains a port/pin packed byte
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
GlobalMux_InputSelect:
_GlobalMux_InputSelect:
RAM_PROLOGUE RAM_USE_CLASS_2
M8C_SetBank1
push A
and A,F0h
asr A
asr A
asr A
asr A
cmp A,4
jnc .port4_or_greater
mov X,A ; get the port offset in X
pop A
and A,0Fh
index muxpinlu ; changes pin number to mask
mov reg[X+MUX_CR0],A ; enable the mux connection
jmp EndInputSelect
.port4_or_greater:
sub A,4
mov X,A ; get the port offset in X
pop A
and A,0Fh
index muxpinlu ; changes pin number to mask
mov reg[X+ECh],A ; MUX_CR4 equ ECh, enable the mux connection
EndInputSelect:
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: GlobalMux_InputClear
;
; DESCRIPTION:
; Clears the Global Mux Bus on a given port.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A contains a port/pin packed byte
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;-----------------------------------------------------------------------------
GlobalMux_InputClear:
_GlobalMux_InputClear:
RAM_PROLOGUE RAM_USE_CLASS_2
M8C_SetBank1
and A,F0h
asr A
asr A
asr A
asr A
cmp A,4
jnc .port4_or_greater
mov X,A ; get the port offset in X
mov reg[X+MUX_CR0],0 ; disable the mux connection
jmp EndInputClear
.port4_or_greater:
sub A,4
mov X,A ; get the port offset in X
mov reg[X+ECh],0 ; MUX_CR4 equ ECh, disable the mux connection
EndInputClear:
M8C_SetBank0
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -