📄 timer8_1.lis
字号:
001A ; latched into the Counter register.
001A ;
001A ; THEORY of OPERATION:
001A ; Write data into the Period register.
001A ;
001A ;-----------------------------------------------------------------------------
001A Timer8_1_WritePeriod:
001A _Timer8_1_WritePeriod:
001A 492301 tst REG[Timer8_1_CONTROL_REG], bfCONTROL_REG_START_BIT
001D B019 jnz .CounterRunning
001F
001F ; Counter is stopped. Due to chip errata, we have to set the clock low for
001F ; the write to the period register to cause the data to be immediately transferred
001F ; into the Counter.
001F .CounterStopped:
001F 10 push X
0020 5C mov X, A ; save the period argument
0021 7110 or F, FlagXIOMask
0023 5D21 mov A, REG[Timer8_1_INPUT_REG] ; save the context of the clock - input register
0025 08 push A
0026 4121F0 and REG[Timer8_1_INPUT_REG], F0h ; set the clock signal low
0029 70EF and F, ~FlagXIOMask
002B 5B mov A, X
002C 6021 mov REG[Timer8_1_PERIOD_REG], A ; set the period register with the new period
002E 18 pop A
002F 7110 or F, FlagXIOMask
0031 6021 mov REG[Timer8_1_INPUT_REG], A ; restore the clock
0033 70EF and F, ~FlagXIOMask
0035 20 pop X
0036 7F ret
0037
0037 ; Counter is running - write the period into the period register.
0037 ; Upon Terminal Count this value will get loaded into the counter.
0037 .CounterRunning:
0037 6021 mov REG[Timer8_1_PERIOD_REG], A
0039 7F ret
003A
003A
003A ;-----------------------------------------------------------------------------
003A ; FUNCTION NAME: Timer8_1_WriteCompareValue
003A ;
003A ; DESCRIPTION:
003A ; Writes compare value into the CompareValue register.
003A ;
003A ; NOTE! The Timer user module must be STOPPED in order to write
003A ; the CompareValue register.
003A ;
003A ; ARGUMENTS:
003A ; BYTE bCompareValue - compare value count - passed in Accumulator.
003A ;
003A ; RETURNS:
003A ; none.
003A ;
003A ; SIDE EFFECTS:
003A ; none.
003A ;
003A ; THEORY of OPERATION:
003A ; Write data into the CompareValue register.
003A ;
003A ;-----------------------------------------------------------------------------
003A Timer8_1_WriteCompareValue:
003A _Timer8_1_WriteCompareValue:
003A 6022 mov REG[Timer8_1_COMPARE_REG], A
003C 7F ret
003D
003D
003D ;-----------------------------------------------------------------------------
003D ; FUNCTION NAME: bTimer8_1_ReadCompareValue
003D ;
003D ; DESCRIPTION:
003D ; Reads the CompareValue register.
003D ;
003D ; ARGUMENTS:
003D ; none.
003D ;
003D ; RETURNS:
003D ; BYTE bCompareValue - value read from CompareValue register - returned
003D ; in the Accumulator.
003D ;
003D ; SIDE EFFECTS:
003D ; none.
003D ;
003D ; THEORY of OPERATION:
003D ; Read the CompareValue register and return value in A.
003D ;
003D ;-----------------------------------------------------------------------------
003D bTimer8_1_ReadCompareValue:
003D _bTimer8_1_ReadCompareValue:
003D 5D22 mov A, REG[Timer8_1_COMPARE_REG]
003F 7F ret
0040
0040
0040 ;-----------------------------------------------------------------------------
0040 ; FUNCTION NAME: bTimer8_1_ReadTimerSaveCV
0040 ;
0040 ; DESCRIPTION:
0040 ; Reads the count in the Counter register. This function preserves the
0040 ; contents of the CompareValue register. However, the cost of doing so
0040 ; is that the counter is halted. This may cause the timer to miss one or
0040 ; more counts, depending on the speed of the input clock.
0040 ;
0040 ; ARGUMENTS:
0040 ; none.
0040 ;
0040 ; RETURNS:
0040 ; WORD bCount - current count value in Count register.
0040 ; Returned in A register
0040 ;
0040 ; SIDE EFFECTS:
0040 ; 1) May cause an interrupt, if interrupt on CompareValue is enabled.
0040 ; 2) The user module is stopped momentarily while the compare value is
0040 ; restored. This may cause the Count register to miss one or more
0040 ; counts depending on the input clock speed.
0040 ; 3) Interrupts are momentarily disabled - this may cause other interrupt
0040 ; latency issues.
0040 ;
0040 ; THEORY of OPERATION:
0040 ; 1) Read and save the CompareValue register.
0040 ; 2) Read the Counter register, causing its data to be latched into
0040 ; the CompareValue register.
0040 ; 3) Read and save the Counter value, now in the CompareValue register,
0040 ; to the buffer.
0040 ; 4) Disable global interrupts
0040 ; 5) Halt the timer
0040 ; 6) Restore the CompareValue register values
0040 ; 7) Start the Counter again
0040 ; 8) Restore global interrupt state
0040 ;
0040 ;-----------------------------------------------------------------------------
0040 bTimer8_1_ReadTimerSaveCV:
0040 _bTimer8_1_ReadTimerSaveCV:
0040 bTimer8_1_ReadCounter: ; OBSOLETE
0040 _bTimer8_1_ReadCounter: ; OBSOLETE
0040
0000 CpuFlags: equ 0
0001 bCount: equ 1
0040
0040 ; setup a stack frame to save bCount and CPU flags on the stack
0040 ; X now points to the MSB of the returned data - stored on stack
0040 4F mov X, SP
0041 3802 ADD SP, 2
0043
0043 ; save the control register on the stack
0043 5D23 mov A, reg[Timer8_1_CONTROL_REG]
0045 08 push A
0046
0046 ; save the CompareValue register value
0046 5D22 mov A, reg[Timer8_1_COMPARE_REG]
0048 08 push A
0049
0049 ; Read the LSB counter. This latches the counter data into the
0049 ; CompareValue register of all bytes of chained PSoC blocks!
0049 ; This may cause an interrupt.
0049 5D20 mov A, reg[Timer8_1_COUNTER_REG]
004B
004B ; Read the CompareValue register, which contains the counter value
004B ; and store the result in the stack frame
004B 5D22 mov A, reg[Timer8_1_COMPARE_REG]
004D 5401 mov [X+bCount], A
004F
004F ; determine current interrupt state and save in stack frame
004F 5000 mov A, 0
0051 49FF80 tst reg[CPU_SCR], CPUSCR_GIEMask
0054 A003 jz .SetupStatusFlag
0056 5001 mov A, FlagGlobalIE
0058 .SetupStatusFlag:
0058 5400 mov [X+CpuFlags], A
005A
005A ; disable interrupts for the time being
005A 70FE and F, ~FlagGlobalIE
005C
005C ; stop the timer
005C 4123FE and reg[Timer8_1_CONTROL_REG], ~bfCONTROL_REG_START_BIT
005F
005F ; Restore the CompareValue register
005F 18 pop A
0060 6022 mov reg[Timer8_1_COMPARE_REG], A
0062
0062 ; restore start state of the timer
0062 18 pop A
0063 6023 mov reg[Timer8_1_CONTROL_REG], A
0065
0065 ; Return result stored in stack frame - just pop them off!
0065 18 pop A
0066
0066 ; processor status flag is still on the stack! Use the RETI
0066 ; command to restore it.
0066 7E reti
0067
0067
0067 ;-----------------------------------------------------------------------------
0067 ; FUNCTION NAME: bTimer8_1_ReadTimer
0067 ;
0067 ; DESCRIPTION:
0067 ; Performs a software capture of the Counter register. A synchronous
0067 ; read of the counter register is performed. The timer is NOT stopped.
0067 ;
0067 ; WARNING - this will cause loss of the CompareValue register data.
0067 ;
0067 ; ARGUMENTS:
0067 ; none.
0067 ;
0067 ; RETURNS:
0067 ; BYTE bCount - current count value in Count register.
0067 ; Returned in A register
0067 ;
0067 ; SIDE EFFECTS:
0067 ; May cause an interrupt.
0067 ;
0067 ; THEORY of OPERATION:
0067 ; 1) Read the CounterRegister - this causes the count value to be
0067 ; latched into the CompareValue registers.
0067 ; 2) Read and return the count register values from the CompareValue
0067 ; registers into the return buffer.
0067 ;
0067 ;-----------------------------------------------------------------------------
0067 bTimer8_1_ReadTimer:
0067 _bTimer8_1_ReadTimer:
0067 bTimer8_1_CaptureCounter: ; OBSOLETE - saved for backwards compatibility
0067 _bTimer8_1_CaptureCounter: ; OBSOLETE - saved for backwards compatibility
0067
0067 ; Read the counter. This latches the counter data into the
0067 ; CompareValue register. This may cause an interrupt.
0067 5D20 mov A, REG[Timer8_1_COUNTER_REG]
0069
0069 ; Read the CompareValue register, which contains the counter value
0069 ; and store ther return result
0069 5D22 mov A, REG[Timer8_1_COMPARE_REG]
006B
006B 7F ret
006C
006C ; end of Timer8 API code
006C
006C
006C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -