本帖最后由 grant_jx 于 2013-11-11 14:42 编辑
你的代码很奇怪,Call Delay后,再跑一遍Delay,主循环呢,Call函数没有RET?
我没仔细看你对定时器的代码,但看到的说明电灯的代码在中断中,你有没有在线Debug,是否是没清中断标志?通常定时器进去了要清相应的中断标志,要不进去了出不来的。
还有你的IRET怎么这么多?多了会搞乱堆栈的。
给你一段汇编代码你参考吧,不是我写的,是ST之前内部的一个汇编版本的库里面的片段。也是定时器延时,翻转GPIO。stm8/
; TIM1 Channel1 generating a 2-second delay time is used as a TIMER with the clock fixed at 2MHz.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Example description
; This example shows how to configure the TIM1 peripheral as a common timer.
; TIM1CLK is fixed to 2 MHz, the TIM1 Prescaler is equal to 0 so the TIM1 counter clock used is 2 MHz. (By default, fTimer1= fMaster/8 ).
; TIM1 frequency is defined as follows:
; - TIM1 frequency = TIM1 counter clock / (TIM1_Period + 1) = 30.5Hz.
; The PH0 is on for 2 seconds and then off for 2 seconds after numerous repetitions.
; For example(delaying 2s): 2s/(1/30.5Hz)=61.0, so we can define a variable(for repeating count)
; with the calue of 61(0x3D). The CCR1_Val is set according to fractional part.
; CCR1_Val=Fractional part(here 0.0)/(1/fTim1).If eqauls to 0, write the CCR1_value with 0xffff.
; Directory Contents:
; ; - stm8s_conf.inc
; ; - stm8s207m.inc
; ; - stm8s207m.asm
; ; - stm8s_gpio.inc
; ; - stm8s_gpio.asm
; ; - stm8s_tim1.inc
; ; - stm8s_tim1.asm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include "mapping.inc"
#include "stm8s_conf.inc"
#define CCR1_Val $ffff ; TIM1 Channel1 Compare value.
#define CCR_Val $ffff ; TIM1_Period defination
; The variable is stored in ram0. 8 bit address
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment 'ram0'
.AddTime ds.b 1
; The variable is stored in ram1. 16 bit address
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment 'ram1'
; TIM1 is used in TIMING Mode. The timing time(count from the CNTR value 0 to CCR1Value)= 1/{f(master)/TIM1Presacler}*CCR1Value. If the f(master)=2MHz, the timing time is about 32.78ms.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment 'rom'
main.l
mov AddTime,#$3d
TIM1_DeInit ; Load the reset default value to TIM1 registers.
TIM1_TimeBaseInit $00,TIM1_COUNTERMODE_UP,CCR_Val ; TIM1 Basic Configuration: frequency prescaler: 0x00; counter mode: up; TIM1 frequency= =2MHz/65535=30.5Hz.
GPIO_Init PH_ODR,GPIO_PIN_0,GPIO_MODE_OUT_PP_LOW_SLOW ; PH0 Configuration: Output push-pull, low level, 2MHz.
TIM1_OCInit TIM1_CHANNEL_1,TIM1_OCMODE_TIMING,CCR1_Val ; TIM1 Channel1 TIMING time(from the CNTR value 0 to CCR1Value)= 1/{f(master)/TIM1Presacler}*CCR1Value.
TIM1_ITConfig TIM1_IT_CC1 ; Enable the Compare/Capture channel1 interrupt.
rim ; Enable interrupts
TIM1_Start ; TIM1 counter starts.
HERE JRA HERE ; Insert a breakpoint here.
; Interrupt programs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TIM1_OC1_TIMING:
TIM1_ClearIT TIM1_IT_CC1 ; Clear IT pending bit
LD A,AddTime ; Move the AddTime Value to A first
DEC A
JREQ TIM1_NEXT1 ; If equals to 0, jump to TIM1_NEXT1
LD AddTime,A ; Then returns the value after decreased to A.
JRA TIM1_NEXT2 ; Jump to TIM1_NEXT2
TIM1_NEXT1
GPIO_WriteReverse PH_ODR,GPIO_PIN_0 ; Write Reverse level of PH0.
MOV AddTime,#$3D ; If the AddTime equals to 0, write a new value to AddTime.
TIM1_NEXT2
IRET
interrupt NonHandledInterrupt
NonHandledInterrupt.l
iret
segment 'vectit'
dc.l {$82000000+main} ; reset
dc.l {$82000000+NonHandledInterrupt} ; trap
dc.l {$82000000+NonHandledInterrupt} ; irq0
dc.l {$82000000+NonHandledInterrupt} ; irq1
dc.l {$82000000+NonHandledInterrupt} ; irq2
dc.l {$82000000+NonHandledInterrupt} ; irq3
dc.l {$82000000+NonHandledInterrupt} ; irq4
dc.l {$82000000+NonHandledInterrupt} ; irq5
dc.l {$82000000+NonHandledInterrupt} ; irq6
dc.l {$82000000+NonHandledInterrupt} ; irq7
dc.l {$82000000+NonHandledInterrupt} ; irq8
dc.l {$82000000+NonHandledInterrupt} ; irq9
dc.l {$82000000+NonHandledInterrupt} ; irq10
dc.l {$82000000+NonHandledInterrupt} ; irq11
dc.l {$82000000+TIM1_OC1_TIMING} ; irq12
dc.l {$82000000+NonHandledInterrupt} ; irq13
dc.l {$82000000+NonHandledInterrupt} ; irq14
dc.l {$82000000+NonHandledInterrupt} ; irq15
dc.l {$82000000+NonHandledInterrupt} ; irq16
dc.l {$82000000+NonHandledInterrupt} ; irq17
dc.l {$82000000+NonHandledInterrupt} ; irq18
dc.l {$82000000+NonHandledInterrupt} ; irq19
dc.l {$82000000+NonHandledInterrupt} ; irq20
dc.l {$82000000+NonHandledInterrupt} ; irq21
dc.l {$82000000+NonHandledInterrupt} ; irq22
dc.l {$82000000+NonHandledInterrupt} ; irq23
dc.l {$82000000+NonHandledInterrupt} ; irq24
dc.l {$82000000+NonHandledInterrupt} ; irq25
dc.l {$82000000+NonHandledInterrupt} ; irq26
dc.l {$82000000+NonHandledInterrupt} ; irq27
dc.l {$82000000+NonHandledInterrupt} ; irq28
dc.l {$82000000+NonHandledInterrupt} ; irq29
end
stm8/
#include "stm8s_conf.inc"
; The approaching program is stored in rom.
; 16 bit address if code size is less 32k.
; 24 bit address if code size over 32k.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment 'rom'
; 函数功能:TIM1的时钟设置,包括TIM1的分频,TIM1的计数模式和TIM1的自动重装载值(AutoReload值)。
; 输出参数:TIM1_Prescaler--- TIM1的分频因子,此参数可为$0000-$FFFF任意值。
; TIM1_CounterMode--- TIM1的计数模式,此参数可在此文件的TIM1计数模式宏定义中选择。
; TIM1_Period--- TIM1的自动重转载值,此参数可以为$0000-$FFFF任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CR1,TIM1_PSCRH,TIM1_PSCRL,TIM1_ARRH,TIM1_ARRL,TIM1_EGR和TIM1_RCR.
; 2、用到的CPU寄存器:A,X,Y。
; 3、说明:为了减少参数,这里默认设置 TIM1更新事件产生时重新初始化计数器;重复计数器的值为0。可以根据实际需要进行修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIME1BASEINIT:
BRES TIM1_CR1,#4 ; Clear the TIM1_CR1_CMS and TIM1_CR1_DIR bits.
BRES TIM1_CR1,#5
BRES TIM1_CR1,#6
OR A,TIM1_CR1 ; Select the Counter Mode
LD TIM1_CR1,A
LD A,XH ; Set the Autoreload value. Load the TIM1_Period value to TIM1_ARR.
LD TIM1_ARRH,A
LD A,XL
LD TIM1_ARRL,A
LD A,YH ; Set the Prescaler value. Load the TIM1_Prescaler value to TIM1_PSCR.
LD TIM1_PSCRH,A
LD A,YL
LD TIM1_PSCRL,A
; Configure Prescaler Preloaded mode. The default setting is loaded at the update event. If If reset( The Prescaler is loaded immediately) needed, change "BSET" to "BRES".
BSET TIM1_EGR,#0 ; Prescaler Loaded at the update event.
; BRES TIM1_EGR,#0 ; Prescaler Loaded Immediately
MOV TIM1_RCR,#$0 ; Set the Repetition Counter value. The default TIM1_RepetitionCounter value is 0. Change the value if needed.
RET
; 函数功能:配置TIM1的通道1成所需要的输出比较模式。
; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
; TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
; TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR1,TIM1_CCR1H,TIM1_CCR1L和TIM1_BKR.
; 2、用到的CPU寄存器:A,X,Y。
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_OC1INIT:
; Configure the TIM1 channel1 output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER1,#0 ; Enable TIM1 Channel1 output.
; BRES TIM1_CCER1,#0 ; Disable TIM1 Channel1 output.
; Configure the TIM1 channel1N output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER1,#2 ; Enable TIM1 Channel1N output.
; BRES TIM1_CCER1,#2 ; Disable TIM1 Channel1N output.
; Configure the TIM1 channel1 output polarity from the next two selections. The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER1,#1 ; Configure TIM1 Channel1 OC polarity High level.
BSET TIM1_CCER1,#1 ; Configure TIM1 Channel1 OC polarity Low level.
; Configure the TIM1 channel1N output polarity from the next two selections. The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER1,#3 ; Configure TIM1 Channel1N OC polarity High level.
BSET TIM1_CCER1,#3 ; Configure TIM1 Channel1N OC polarity Low level.
BRES TIM1_CCMR1,#4 ; Clear 4-6 bits of TIM1_CCMR1.
BRES TIM1_CCMR1,#5
BRES TIM1_CCMR1,#6
LD A,YL
OR A,TIM1_CCMR1 ; Set the Ouput Compare Mode.
LD TIM1_CCMR1,A
LD A,XH ; Set the Pulse value
LD TIM1_CCR1H,A
LD A,XL
LD TIM1_CCR1L,A
; Configure TIM1_OC_Channel CCR1 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event
BSET TIM1_CCMR1,#3 ; CCR1 Preload At the update event
; BRES TIM1_CCMR1,#3 ; CCR1 Preload Immediately
; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.
BSET TIM1_BKR,#7 ; TIM1 Main Output Enable.
; BRES TIM1_BKR,#7 ; TIM1 Main Output Disable.
RET
; 函数功能:配置TIM1的通道2成所需要的输出比较模式。
; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
; TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
; TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR2,TIM1_CCR2H,TIM1_CCR2L和TIM1_BKR.
; 2、用到的CPU寄存器:A,X,Y。
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_OC2INIT:
; Configure the TIM1 channel2 output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER1,#4 ; Enable TIM1 Channel2 output.
; BRES TIM1_CCER1,#4 ; Disable TIM1 Channel2 output.
; Configure the TIM1 channel2N output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER1,#6 ; Enable TIM1 Channel2N output.
; BRES TIM1_CCER1,#6 ; Disable TIM1 Channel2N output.
; Configure the TIM1 channel2 output polarity from the next two selections.The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER1,#5 ; Configure TIM1 Channel2 OC polarity high level.
BSET TIM1_CCER1,#5 ; Configure TIM1 Channel2 OC polarity LOW level.
; Configure the TIM1 channel2N output polarity from the next two selections. The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER1,#7 ; Configure TIM1 Channel2N OC polarity high level. If low level needed, change "BRES" to "BSET"
BSET TIM1_CCER1,#7 ; Configure TIM1 Channel
BRES TIM1_CCMR2,#4 ; Clear 4-6 bits of TIM1_CCMR2.
BRES TIM1_CCMR2,#5
BRES TIM1_CCMR2,#6
LD A,YL
OR A,TIM1_CCMR2 ; Set the Ouput Compare Mode.
LD TIM1_CCMR2,A
LD A,XH ; Set the Pulse value
LD TIM1_CCR2H,A
LD A,XL
LD TIM1_CCR2L,A
; Configure TIM1_OC_Channel CCR2 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event
BSET TIM1_CCMR2,#3 ; CCR2 Preload At the update event
; BRES TIM1_CCMR2,#3 ; CCR2 Preload Immediately
; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.
BSET TIM1_BKR,#7 ; TIM1 Main Output Enable.
; BRES TIM1_BKR,#7 ; TIM1 Main Output Disable.
RET
; 函数功能:配置TIM1的通道3成所需要的输出比较模式。
; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
; TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
; TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR3,TIM1_CCR3H,TIM1_CCR3L和TIM1_BKR.
; 2、用到的CPU寄存器:A,X,Y。
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_OC3INIT:
; Configure the TIM1 channel3 output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER2,#0 ; Enable TIM1 Channel3 output.
; BRES TIM1_CCER2,#0 ; Disable TIM1 Channel3 output.
; Configure the TIM1 channel3N output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER2,#2 ; Enable TIM1 Channel3N output.
; BRES TIM1_CCER2,#2 ; Disable TIM1 Channel3N output.
; Configure the TIM1 channel3 output polarity from the next two selections. The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER2,#1 ; Configure TIM1 Channel3 OC polarity high level.
BSET TIM1_CCER2,#1 ; Configure TIM1 Channel3 OC polarity low level.
; Configure the TIM1 channel3N output polarity from the next two selections. The default configuration is high level.
; BRES TIM1_CCER2,#3 ; Configure TIM1 Channel3N OC polarity high level.
BSET TIM1_CCER2,#3 ; Configure TIM1 Channel3N OC polarity low level.
BRES TIM1_CCMR3,#4 ; Clear 4-6 bits of TIM1_CCMR3.
BRES TIM1_CCMR3,#5
BRES TIM1_CCMR3,#6
LD A,YL
OR A,TIM1_CCMR3 ; Set the Ouput Compare Mode.
LD TIM1_CCMR3,A
LD A,XH ; Set the Pulse value
LD TIM1_CCR3H,A
LD A,XL
LD TIM1_CCR3L,A
; Configure TIM1_OC_Channel CCR3 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event
BSET TIM1_CCMR3,#3 ; CCR3 Preload At the update event
; BRES TIM1_CCMR3,#3 ; CCR3 Preload Immediately
; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.
BSET TIM1_BKR,#7 ; TIM1 Main Output Enable.
; BRES TIM1_BKR,#7 ; TIM1 Main Output Disable.
RET
; 函数功能:配置TIM1的通道3成所需要的输出比较模式。
; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
; TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
; TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR4,TIM1_CCR4H,TIM1_CCR4L和TIM1_BKR.
; 2、用到的CPU寄存器:A,X,Y。
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_OC4INIT:
; Configure the TIM1 channel4 output state from the next two selections. The default configuration is Enable state.
BSET TIM1_CCER2,#4 ; Enable TIM1 Channel4 output.
; BRES TIM1_CCER2,#4 ; Disable TIM1 Channel4 output.
; Configure the TIM1 channel4 output polarity from the next two selections. The default configuration is Low level. If low level needed, change "BSET" to "BRES".
; BRES TIM1_CCER2,#5 ; Configure TIM1 Channel4 OC polarity high level.
BSET TIM1_CCER2,#5 ; Configure TIM1 Channel4 OC polarity low level.
BRES TIM1_CCMR4,#4 ; Clear 4-6 bits of TIM1_CCMR4.
BRES TIM1_CCMR4,#5
BRES TIM1_CCMR4,#6
LD A,YL
OR A,TIM1_CCMR4 ; Set the Ouput Compare Mode.
LD TIM1_CCMR4,A
LD A,XH ; Set the Pulse value
LD TIM1_CCR4H,A
LD A,XL
LD TIM1_CCR4L,A
; Configure TIM1_OC_Channel CCR4 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event
BSET TIM1_CCMR4,#3 ; CCR4 Preload At the update event
; BRES TIM1_CCMR4,#3 ; CCR4 Preload Immediately
; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.
BSET TIM1_BKR,#7 ; TIM1 Main Output Enable.
; BRES TIM1_BKR,#7 ; TIM1 Main Output Disable.
RET
; 函数功能:TIM1的通道1输入捕捉配置。
; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
; TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
; TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR1
; 2、用到的CPU寄存器:A,X
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_IC1INIT
BRES TIM1_CCER1,#0 ; Disable the Channel 1: Reset the CCE Bit
PUSH A
LD A,#$0C
AND A,TIM1_CCMR1
LD TIM1_CCMR1,A
POP A ; Select the Input and set the filter
SWAP A
OR A,TIM1_CCMR1
LD TIM1_CCMR1,A
LD A,XL
OR A,TIM1_CCMR1
LD TIM1_CCMR1,A
; Configure TIM1_IC Channel1 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".
BSET TIM1_CCER1,#1 ; IC polarity: falling.
; BRES TIM1_CCER1,#1 ; IC polarity: rising.
BSET TIM1_CCER1,#0 ; Set the CCE Bit
RET
.TIM1_SETIC1PRESCALER
BRES TIM1_CCMR1,#2 ; Reset TIM1_CCMR1 Register bits[3:2] first
BRES TIM1_CCMR1,#3
OR A,TIM1_CCMR1 ; Then set TIM1_IC1 Prescaler
LD TIM1_CCMR1,A
RET
; 函数功能:TIM1的通道2输入捕捉配置。
; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
; TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
; TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR2
; 2、用到的CPU寄存器:A,X
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_IC2INIT
BRES TIM1_CCER1,#4 ; Disable the Channel 1: Reset the CCE Bit
PUSH A
LD A,#$0C
AND A,TIM1_CCMR2
LD TIM1_CCMR2,A
POP A ; Select the Input and set the filter
SWAP A
OR A,TIM1_CCMR2
LD TIM1_CCMR2,A
LD A,XL
OR A,TIM1_CCMR2
LD TIM1_CCMR2,A
; Configure TIM1_IC Channel2 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".
BSET TIM1_CCER1,#5 ; IC polarity: falling.
; BRES TIM1_CCER1,#5 ; IC polarity: rising.
BSET TIM1_CCER1,#4 ; Set the CCE Bit
RET
.TIM1_SETIC2PRESCALER
BRES TIM1_CCMR2,#2 ; Reset TIM1_CCMR2 Register bits[3:2] first
BRES TIM1_CCMR2,#3
OR A,TIM1_CCMR2 ; Then set TIM1_IC2 Prescaler
LD TIM1_CCMR2,A
RET
; 函数功能:TIM1的通道3输入捕捉配置。
; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
; TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
; TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR3
; 2、用到的CPU寄存器:A,X
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_IC3INIT
BRES TIM1_CCER2,#0 ; Disable the Channel 1: Reset the CCE Bit
PUSH A
LD A,#$0C
AND A,TIM1_CCMR3
LD TIM1_CCMR3,A
POP A ; Select the Input and set the filter
SWAP A
OR A,TIM1_CCMR3
LD TIM1_CCMR3,A
LD A,XL
OR A,TIM1_CCMR3
LD TIM1_CCMR3,A
; Configure TIM1_IC Channel3 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".
BSET TIM1_CCER2,#1 ; IC polarity: falling.
; BRES TIM1_CCER2,#1 ; IC polarity: rising.
BSET TIM1_CCER2,#0 ; Set the CCE Bit
RET
.TIM1_SETIC3PRESCALER
BRES TIM1_CCMR3,#2 ; Reset TIM1_CCMR3 Register bits[3:2] first
BRES TIM1_CCMR3,#3
OR A,TIM1_CCMR3 ; Then set TIM1_IC3 Prescaler
LD TIM1_CCMR3,A
RET
; 函数功能:TIM1的通道4输入捕捉配置。
; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
; TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
; TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
; 返回值:无
; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR4
; 2、用到的CPU寄存器:A,X
; 3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.TIM1_IC4INIT
BRES TIM1_CCER2,#4 ; Disable the Channel 1: Reset the CCE Bit
PUSH A
LD A,#$0C
AND A,TIM1_CCMR4
LD TIM1_CCMR4,A
POP A ; Select the Input and set the filter
SWAP A
OR A,TIM1_CCMR4
LD TIM1_CCMR4,A
LD A,XL
OR A,TIM1_CCMR4
LD TIM1_CCMR4,A
; Configure TIM1_IC Channel4 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".
BSET TIM1_CCER2,#5 ; IC polarity: falling.
; BRES TIM1_CCER2,#5 ; IC polarity: rising.
BSET TIM1_CCER2,#4 ; Set the CCE Bit
RET
.TIM1_SETIC4PRESCALER
BRES TIM1_CCMR4,#2 ; Reset TIM1_CCMR4 Register bits[3:2] first
BRES TIM1_CCMR4,#3
OR A,TIM1_CCMR4 ; Then set TIM1_IC4 Prescaler
LD TIM1_CCMR4,A
RET
end
|