[STM8] 第二个灯亮了后就返回水了主程序,什么情况啊?求助

[复制链接]
 楼主| tianli1980 发表于 2013-11-10 19:41 | 显示全部楼层 |阅读模式
intel
infinite_loop.l
;----初始化定时器TIM1-----
  MOV TIM1_SMCR,#00H
BRES TIM1_ETR,#6          ;清中断标志
  MOV TIM1_PSCRH,#00H
MOV TIM1_PSCRL,#01H
MOV TIM1_ARRH,#9H
MOV TIM1_ARRL,#0c4H
MOV TIM1_RCR,#00H
MOV TIM1_CR1,#04H
BSET TIM1_EGR,#0
BSET TIM1_IER,#0
BSET TIM1_CR1,#0

;定义输出模式
MOV PB_DDR,#0ffH          ;选择输出模式
MOV PB_CR1,#0ffH          ;选择推挽输出
  MOV ITC_SPR3,#00H         
RIM                       ;定义中断优先级,开中断
MOV R01,#0FEH             ;LED灯的花式
  MOV PB_ODR,R01
CALL DELAY
MOV R10,#20
DELAY:
D1:   
MOV R02,#50
D2:
  MOV R03,#100
D3:
  MOV R04,#100
DEC R04
JRNE D3
DEC R03
JRNE D2
DEC R02
JRNE D1
  interrupt TIM1_Interrupt_Over  ;中断开始伪指令
TIM1_Interrupt_Over.l
  BRES TIM1_SR1,#0
  DEC R10
JRNE TIM1_Interrupt_Over_EXIT
MOV R10,#20
MOV R01,#0FDH
MOV PB_ODR,R01

TIM1_Interrupt_Over_EXIT.L
  IRET
IRET
IRET
IRET
IRET

  motorola
为什么返回不了主程序啊
我的主程序是让第一个亮

我的主程序是让第一个LED灯亮,中断程序是让第两个亮
为何亮了第二个后返回不了主程序啊

黄小俊 发表于 2013-11-10 20:35 | 显示全部楼层
楼主不错。竟然用汇编。请大神吧。
596142041 发表于 2013-11-10 21:26 | 显示全部楼层
楼主牛啊!全部汇编!!!!!!!!!!!
戈卫东 发表于 2013-11-10 22:11 | 显示全部楼层
这什么处理器的汇编语言?
戈卫东 发表于 2013-11-10 22:11 | 显示全部楼层
不是51,不是ARM....没见过.....
拿起书本 发表于 2013-11-11 10:24 | 显示全部楼层
这个我也不知道啊,帮忙顶了,希望有朋友能帮到你。
lei129210 发表于 2013-11-11 11:12 | 显示全部楼层
现在用汇编写软件的,要不就是超级高手,要不就是装逼的菜鸟
杨爱林林 发表于 2013-11-11 11:40 | 显示全部楼层
以前在学校 还写过一点简单的汇编  
现在 真的一点都看不懂啦
syj2055 发表于 2013-11-11 14:29 | 显示全部楼层
用汇编语言有难度。
grant_jx 发表于 2013-11-11 14:39 | 显示全部楼层
本帖最后由 grant_jx 于 2013-11-11 14:42 编辑

你的代码很奇怪,Call Delay后,再跑一遍Delay,主循环呢,Call函数没有RET?

我没仔细看你对定时器的代码,但看到的说明电灯的代码在中断中,你有没有在线Debug,是否是没清中断标志?通常定时器进去了要清相应的中断标志,要不进去了出不来的。
还有你的IRET怎么这么多?多了会搞乱堆栈的。

给你一段汇编代码你参考吧,不是我写的,是ST之前内部的一个汇编版本的库里面的片段。也是定时器延时,翻转GPIO。
  1. stm8/
  2. ; TIM1 Channel1 generating a 2-second delay time is used as a TIMER with the clock fixed at 2MHz.
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  4. ; Example description

  5. ; This example shows how to configure the TIM1 peripheral as a common timer.
  6. ; 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 ).
  7. ; TIM1 frequency is defined as follows:
  8. ; - TIM1 frequency = TIM1 counter clock / (TIM1_Period + 1) = 30.5Hz.
  9. ; The PH0 is on for 2 seconds and then off for 2 seconds after numerous repetitions.
  10. ; For example(delaying 2s): 2s/(1/30.5Hz)=61.0, so we can define a variable(for repeating count)
  11. ; with the calue of 61(0x3D). The CCR1_Val is set according to fractional part.
  12. ; CCR1_Val=Fractional part(here 0.0)/(1/fTim1).If eqauls to 0, write the CCR1_value with 0xffff.

  13. ; Directory Contents:
  14. ; ; - stm8s_conf.inc
  15. ; ; - stm8s207m.inc
  16. ; ; - stm8s207m.asm
  17. ; ; - stm8s_gpio.inc
  18. ; ; - stm8s_gpio.asm
  19. ; ; - stm8s_tim1.inc
  20. ; ; - stm8s_tim1.asm
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  22.         #include "mapping.inc"
  23.         #include "stm8s_conf.inc"
  24.   
  25.         #define CCR1_Val $ffff         ; TIM1 Channel1 Compare value.
  26.         #define CCR_Val $ffff          ; TIM1_Period defination
  27. ; The variable is stored in ram0. 8 bit address
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29.         segment 'ram0'
  30. .AddTime ds.b 1

  31. ; The variable is stored in ram1. 16 bit address
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  33.         segment 'ram1'

  34. ; 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.
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36.         segment 'rom'
  37. main.l
  38.   mov AddTime,#$3d
  39.         TIM1_DeInit   ; Load the reset default value to TIM1 registers.
  40.         TIM1_TimeBaseInit $00,TIM1_COUNTERMODE_UP,CCR_Val       ; TIM1 Basic Configuration: frequency prescaler: 0x00; counter mode: up; TIM1 frequency= =2MHz/65535=30.5Hz.
  41.         GPIO_Init PH_ODR,GPIO_PIN_0,GPIO_MODE_OUT_PP_LOW_SLOW   ; PH0 Configuration: Output push-pull, low level, 2MHz.  
  42.   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.
  43.         TIM1_ITConfig TIM1_IT_CC1                               ; Enable the Compare/Capture channel1 interrupt.
  44.         rim           ; Enable interrupts
  45.         TIM1_Start    ; TIM1 counter starts.
  46. HERE JRA HERE   ; Insert a breakpoint here.

  47. ; Interrupt programs
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. TIM1_OC1_TIMING:
  50.         TIM1_ClearIT TIM1_IT_CC1  ; Clear IT pending bit
  51.         LD A,AddTime      ; Move the AddTime Value to A first
  52.         DEC A                                 
  53.         JREQ TIM1_NEXT1   ; If equals to 0, jump to TIM1_NEXT1
  54.         LD AddTime,A      ; Then returns the value after decreased to A.
  55.         JRA TIM1_NEXT2    ; Jump to TIM1_NEXT2
  56. TIM1_NEXT1
  57.   GPIO_WriteReverse PH_ODR,GPIO_PIN_0    ; Write Reverse level of PH0.        
  58.         MOV AddTime,#$3D  ; If the AddTime equals to 0, write a new value to AddTime.   
  59. TIM1_NEXT2
  60.   IRET
  61.   
  62.         interrupt NonHandledInterrupt
  63. NonHandledInterrupt.l
  64.         iret

  65.         segment 'vectit'
  66.         dc.l {$82000000+main}                                                                        ; reset
  67.         dc.l {$82000000+NonHandledInterrupt}        ; trap
  68.         dc.l {$82000000+NonHandledInterrupt}        ; irq0
  69.         dc.l {$82000000+NonHandledInterrupt}        ; irq1
  70.         dc.l {$82000000+NonHandledInterrupt}        ; irq2
  71.         dc.l {$82000000+NonHandledInterrupt}        ; irq3
  72.         dc.l {$82000000+NonHandledInterrupt}        ; irq4
  73.         dc.l {$82000000+NonHandledInterrupt}        ; irq5
  74.         dc.l {$82000000+NonHandledInterrupt}        ; irq6
  75.         dc.l {$82000000+NonHandledInterrupt}        ; irq7
  76.         dc.l {$82000000+NonHandledInterrupt}        ; irq8
  77.         dc.l {$82000000+NonHandledInterrupt}        ; irq9
  78.         dc.l {$82000000+NonHandledInterrupt}        ; irq10
  79.         dc.l {$82000000+NonHandledInterrupt}        ; irq11
  80.         dc.l {$82000000+TIM1_OC1_TIMING}        ; irq12
  81.         dc.l {$82000000+NonHandledInterrupt}        ; irq13
  82.         dc.l {$82000000+NonHandledInterrupt}        ; irq14
  83.         dc.l {$82000000+NonHandledInterrupt}        ; irq15
  84.         dc.l {$82000000+NonHandledInterrupt}        ; irq16
  85.         dc.l {$82000000+NonHandledInterrupt}        ; irq17
  86.         dc.l {$82000000+NonHandledInterrupt}        ; irq18
  87.         dc.l {$82000000+NonHandledInterrupt}        ; irq19
  88.         dc.l {$82000000+NonHandledInterrupt}        ; irq20
  89.         dc.l {$82000000+NonHandledInterrupt}        ; irq21
  90.         dc.l {$82000000+NonHandledInterrupt}        ; irq22
  91.         dc.l {$82000000+NonHandledInterrupt}        ; irq23
  92.         dc.l {$82000000+NonHandledInterrupt}        ; irq24
  93.         dc.l {$82000000+NonHandledInterrupt}        ; irq25
  94.         dc.l {$82000000+NonHandledInterrupt}        ; irq26
  95.         dc.l {$82000000+NonHandledInterrupt}        ; irq27
  96.         dc.l {$82000000+NonHandledInterrupt}        ; irq28
  97.         dc.l {$82000000+NonHandledInterrupt}        ; irq29

  98.         end
  1. stm8/
  2.      
  3.   #include "stm8s_conf.inc"

  4. ; The approaching program is stored in rom.
  5. ; 16 bit address if code size is less 32k.
  6. ; 24 bit address if code size over 32k.
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.    segment 'rom'

  9. ; 函数功能:TIM1的时钟设置,包括TIM1的分频,TIM1的计数模式和TIM1的自动重装载值(AutoReload值)。
  10. ; 输出参数:TIM1_Prescaler--- TIM1的分频因子,此参数可为$0000-$FFFF任意值。
  11. ;           TIM1_CounterMode--- TIM1的计数模式,此参数可在此文件的TIM1计数模式宏定义中选择。
  12. ;           TIM1_Period--- TIM1的自动重转载值,此参数可以为$0000-$FFFF任意值。
  13. ; 返回值:无
  14. ; 备注:1、配置的寄存器:TIM1_CR1,TIM1_PSCRH,TIM1_PSCRL,TIM1_ARRH,TIM1_ARRL,TIM1_EGR和TIM1_RCR.
  15. ;       2、用到的CPU寄存器:A,X,Y。
  16. ;       3、说明:为了减少参数,这里默认设置 TIM1更新事件产生时重新初始化计数器;重复计数器的值为0。可以根据实际需要进行修改。
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. .TIME1BASEINIT:
  19.           BRES TIM1_CR1,#4   ; Clear the TIM1_CR1_CMS and TIM1_CR1_DIR bits.
  20.           BRES TIM1_CR1,#5
  21.           BRES TIM1_CR1,#6                                       
  22.                                         OR A,TIM1_CR1      ; Select the Counter Mode
  23.                                         LD TIM1_CR1,A         
  24.                                   LD A,XH            ; Set the Autoreload value. Load the TIM1_Period value to TIM1_ARR.
  25.                                         LD TIM1_ARRH,A
  26.                                         LD A,XL
  27.                                         LD TIM1_ARRL,A
  28.                                         LD A,YH            ; Set the Prescaler value. Load the TIM1_Prescaler value to TIM1_PSCR.
  29.                                         LD TIM1_PSCRH,A
  30.                                         LD A,YL
  31.                                         LD TIM1_PSCRL,A
  32. ; 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".
  33.                                         BSET TIM1_EGR,#0   ; Prescaler Loaded at the update event.
  34. ;         BRES TIM1_EGR,#0         ; Prescaler Loaded Immediately                                
  35.                                        
  36.                                         MOV TIM1_RCR,#$0   ; Set the Repetition Counter value. The default TIM1_RepetitionCounter value is 0. Change the value if needed.
  37.           RET

  38. ; 函数功能:配置TIM1的通道1成所需要的输出比较模式。
  39. ; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
  40. ;           TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
  41. ;           TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
  42. ; 返回值:无
  43. ; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR1,TIM1_CCR1H,TIM1_CCR1L和TIM1_BKR.
  44. ;       2、用到的CPU寄存器:A,X,Y。
  45. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
  46. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  47. .TIM1_OC1INIT:
  48. ; Configure the TIM1 channel1 output state from the next two selections. The default configuration is Enable state.                  
  49.                                         BSET TIM1_CCER1,#0 ; Enable TIM1 Channel1 output.
  50. ;         BRES TIM1_CCER1,#0 ; Disable TIM1 Channel1 output.

  51. ; Configure the TIM1 channel1N output state from the next two selections. The default configuration is Enable state.           
  52.                                         BSET TIM1_CCER1,#2 ; Enable TIM1 Channel1N output.
  53. ;         BRES TIM1_CCER1,#2 ; Disable TIM1 Channel1N output.

  54. ; 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".                                       
  55. ;                                        BRES TIM1_CCER1,#1 ; Configure TIM1 Channel1 OC polarity High level.
  56.                                         BSET TIM1_CCER1,#1 ; Configure TIM1 Channel1 OC polarity Low level.

  57. ; 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".
  58. ;                                        BRES TIM1_CCER1,#3 ; Configure TIM1 Channel1N OC polarity High level.
  59.                                         BSET TIM1_CCER1,#3 ; Configure TIM1 Channel1N OC polarity Low level.

  60.                                         BRES TIM1_CCMR1,#4 ; Clear 4-6 bits of TIM1_CCMR1.
  61.                                         BRES TIM1_CCMR1,#5
  62.                                         BRES TIM1_CCMR1,#6
  63.                                         LD A,YL
  64.                                         OR A,TIM1_CCMR1    ; Set the Ouput Compare Mode.
  65.                                         LD TIM1_CCMR1,A
  66.                                         LD A,XH            ; Set the Pulse value
  67.                                         LD TIM1_CCR1H,A
  68.                                         LD A,XL
  69.                                         LD TIM1_CCR1L,A
  70. ; Configure TIM1_OC_Channel CCR1 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event               
  71.                                         BSET TIM1_CCMR1,#3 ; CCR1 Preload At the update event  
  72. ;         BRES TIM1_CCMR1,#3 ; CCR1 Preload Immediately

  73. ; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.                                         
  74.                                         BSET TIM1_BKR,#7   ; TIM1 Main Output Enable.
  75. ;         BRES TIM1_BKR,#7   ; TIM1 Main Output Disable.
  76.                                         RET

  77. ; 函数功能:配置TIM1的通道2成所需要的输出比较模式。
  78. ; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
  79. ;           TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
  80. ;           TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
  81. ; 返回值:无
  82. ; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR2,TIM1_CCR2H,TIM1_CCR2L和TIM1_BKR.
  83. ;       2、用到的CPU寄存器:A,X,Y。
  84. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
  85. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  86. .TIM1_OC2INIT:
  87. ; Configure the TIM1 channel2 output state from the next two selections. The default configuration is Enable state.                  
  88.                                         BSET TIM1_CCER1,#4  ; Enable TIM1 Channel2 output.
  89. ;                                        BRES TIM1_CCER1,#4  ; Disable TIM1 Channel2 output.

  90. ; Configure the TIM1 channel2N output state from the next two selections. The default configuration is Enable state.
  91.           BSET TIM1_CCER1,#6  ; Enable TIM1 Channel2N output.
  92. ;                                        BRES TIM1_CCER1,#6  ; Disable TIM1 Channel2N output.

  93. ; 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".
  94. ;                                        BRES TIM1_CCER1,#5  ; Configure TIM1 Channel2 OC polarity high level.
  95.           BSET TIM1_CCER1,#5  ; Configure TIM1 Channel2 OC polarity LOW level.

  96. ; 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".
  97. ;         BRES TIM1_CCER1,#7  ; Configure TIM1 Channel2N OC polarity high level. If low level needed, change "BRES" to "BSET"
  98.           BSET TIM1_CCER1,#7  ; Configure TIM1 Channel

  99.                                         BRES TIM1_CCMR2,#4  ; Clear 4-6 bits of TIM1_CCMR2.
  100.                                         BRES TIM1_CCMR2,#5
  101.                                         BRES TIM1_CCMR2,#6
  102.                                         LD A,YL
  103.                                         OR A,TIM1_CCMR2     ; Set the Ouput Compare Mode.
  104.                                         LD TIM1_CCMR2,A
  105.                                         LD A,XH             ; Set the Pulse value
  106.                                         LD TIM1_CCR2H,A
  107.                                         LD A,XL
  108.                                         LD TIM1_CCR2L,A
  109. ; Configure TIM1_OC_Channel CCR2 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event               
  110.                                         BSET TIM1_CCMR2,#3 ; CCR2 Preload At the update event  
  111. ;         BRES TIM1_CCMR2,#3 ; CCR2 Preload Immediately                                         

  112. ; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.                                         
  113.                                         BSET TIM1_BKR,#7    ; TIM1 Main Output Enable.
  114. ;         BRES TIM1_BKR,#7    ; TIM1 Main Output Disable.
  115.                                         RET

  116. ; 函数功能:配置TIM1的通道3成所需要的输出比较模式。
  117. ; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
  118. ;           TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
  119. ;           TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
  120. ; 返回值:无
  121. ; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR3,TIM1_CCR3H,TIM1_CCR3L和TIM1_BKR.
  122. ;       2、用到的CPU寄存器:A,X,Y。
  123. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. .TIM1_OC3INIT:
  126. ; Configure the TIM1 channel3 output state from the next two selections. The default configuration is Enable state.
  127.           BSET TIM1_CCER2,#0  ; Enable TIM1 Channel3 output.
  128. ;         BRES TIM1_CCER2,#0  ; Disable TIM1 Channel3 output.

  129. ; Configure the TIM1 channel3N output state from the next two selections. The default configuration is Enable state.
  130.                                         BSET TIM1_CCER2,#2  ; Enable TIM1 Channel3N output.
  131. ;         BRES TIM1_CCER2,#2  ; Disable TIM1 Channel3N output.

  132. ; 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".
  133. ;                                        BRES TIM1_CCER2,#1  ; Configure TIM1 Channel3 OC polarity high level.
  134.           BSET TIM1_CCER2,#1  ; Configure TIM1 Channel3 OC polarity low level.

  135. ; Configure the TIM1 channel3N output polarity from the next two selections. The default configuration is high level.
  136. ;         BRES TIM1_CCER2,#3  ; Configure TIM1 Channel3N OC polarity high level.
  137.           BSET TIM1_CCER2,#3  ; Configure TIM1 Channel3N OC polarity low level.

  138.                                         BRES TIM1_CCMR3,#4  ; Clear 4-6 bits of TIM1_CCMR3.
  139.                                         BRES TIM1_CCMR3,#5
  140.                                         BRES TIM1_CCMR3,#6
  141.                                         LD A,YL
  142.                                         OR A,TIM1_CCMR3     ; Set the Ouput Compare Mode.
  143.                                         LD TIM1_CCMR3,A
  144.                                         LD A,XH             ; Set the Pulse value
  145.                                         LD TIM1_CCR3H,A
  146.                                         LD A,XL
  147.                                         LD TIM1_CCR3L,A
  148. ; Configure TIM1_OC_Channel CCR3 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event               
  149.                                         BSET TIM1_CCMR3,#3 ; CCR3 Preload At the update event  
  150. ;         BRES TIM1_CCMR3,#3 ; CCR3 Preload Immediately

  151. ; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.                                         
  152.                                         BSET TIM1_BKR,#7    ; TIM1 Main Output Enable.
  153. ;         BRES TIM1_BKR,#7    ; TIM1 Main Output Disable.
  154.                                         RET
  155.                                        
  156. ; 函数功能:配置TIM1的通道3成所需要的输出比较模式。
  157. ; 输出参数:TIM1_Channel--- TIM1的输出通道选择,此参数可在此文件的TIM1输出通道宏定义中选择。
  158. ;           TIM1_OCMode--- TIM1的输出比较模式选择,此参数可 在此文件中的TIM1输出比较模式宏定义中选择。
  159. ;           TIM1_Pulse--- TIM1的输出比较值,此参数可以为$0000-$FFFF任意值。
  160. ; 返回值:无
  161. ; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR4,TIM1_CCR4H,TIM1_CCR4L和TIM1_BKR.
  162. ;       2、用到的CPU寄存器:A,X,Y。
  163. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输出使能和互补输出使能;相应通道的输出低电平有效,互补输出低电平有效。可以根据实际需要修改。
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. .TIM1_OC4INIT:
  166. ; Configure the TIM1 channel4 output state from the next two selections. The default configuration is Enable state.
  167.                                         BSET TIM1_CCER2,#4  ; Enable TIM1 Channel4 output.
  168. ;         BRES TIM1_CCER2,#4  ; Disable TIM1 Channel4 output.                                       

  169. ; 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".
  170. ;         BRES TIM1_CCER2,#5  ; Configure TIM1 Channel4 OC polarity high level.
  171.           BSET TIM1_CCER2,#5  ; Configure TIM1 Channel4 OC polarity low level.                                       
  172.                                        
  173.                                         BRES TIM1_CCMR4,#4  ; Clear 4-6 bits of TIM1_CCMR4.
  174.                                         BRES TIM1_CCMR4,#5
  175.                                         BRES TIM1_CCMR4,#6
  176.                                         LD A,YL
  177.                                         OR A,TIM1_CCMR4     ; Set the Ouput Compare Mode.
  178.                                         LD TIM1_CCMR4,A
  179.                                         LD A,XH             ; Set the Pulse value
  180.                                         LD TIM1_CCR4H,A
  181.                                         LD A,XL
  182.                                         LD TIM1_CCR4L,A
  183. ; Configure TIM1_OC_Channel CCR4 Preloaded Mode Immediate or At the update Event. The default setting is Preloaded at the Update Event               
  184.                                         BSET TIM1_CCMR4,#3 ; CCR4 Preload At the update event  
  185. ;         BRES TIM1_CCMR4,#3 ; CCR4 Preload Immediately

  186. ; Configure the TIM1 channel Main output state from the next two selections. The default configuration is Enable state.                                         
  187.                                         BSET TIM1_BKR,#7    ; TIM1 Main Output Enable.
  188. ;         BRES TIM1_BKR,#7    ; TIM1 Main Output Disable.
  189.                                         RET

  190. ; 函数功能:TIM1的通道1输入捕捉配置。
  191. ; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
  192. ;           TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
  193. ;           TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
  194. ; 返回值:无
  195. ; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR1
  196. ;       2、用到的CPU寄存器:A,X
  197. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
  198. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  199. .TIM1_IC1INIT
  200.           BRES TIM1_CCER1,#0   ; Disable the Channel 1: Reset the CCE Bit
  201.           PUSH A
  202.                                         LD A,#$0C
  203.                                         AND A,TIM1_CCMR1
  204.                                         LD TIM1_CCMR1,A
  205.                                         POP A                ; Select the Input and set the filter
  206.                                         SWAP A              
  207.                                         OR A,TIM1_CCMR1
  208.                                         LD TIM1_CCMR1,A
  209.                                         LD A,XL
  210.                                         OR A,TIM1_CCMR1
  211.                                         LD TIM1_CCMR1,A
  212. ; Configure TIM1_IC Channel1 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".                                         
  213.                                         BSET TIM1_CCER1,#1   ; IC polarity: falling.
  214. ;         BRES TIM1_CCER1,#1         ; IC polarity: rising.                                
  215.                                        
  216.                                         BSET TIM1_CCER1,#0   ; Set the CCE Bit
  217.                                         RET

  218. .TIM1_SETIC1PRESCALER
  219.                                   BRES TIM1_CCMR1,#2   ; Reset TIM1_CCMR1 Register bits[3:2] first
  220.                                         BRES TIM1_CCMR1,#3
  221.                                         OR A,TIM1_CCMR1      ; Then set TIM1_IC1 Prescaler
  222.                                         LD TIM1_CCMR1,A
  223.                                         RET
  224.                                        
  225. ; 函数功能:TIM1的通道2输入捕捉配置。
  226. ; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
  227. ;           TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
  228. ;           TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
  229. ; 返回值:无
  230. ; 备注:1、配置的寄存器:TIM1_CCER1,TIM1_CCMR2
  231. ;       2、用到的CPU寄存器:A,X
  232. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
  233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  234. .TIM1_IC2INIT
  235.           BRES TIM1_CCER1,#4   ; Disable the Channel 1: Reset the CCE Bit
  236.           PUSH A
  237.                                         LD A,#$0C
  238.                                         AND A,TIM1_CCMR2
  239.                                         LD TIM1_CCMR2,A
  240.                                         POP A                ; Select the Input and set the filter
  241.                                         SWAP A              
  242.                                         OR A,TIM1_CCMR2
  243.                                         LD TIM1_CCMR2,A
  244.                                         LD A,XL
  245.                                         OR A,TIM1_CCMR2
  246.                                         LD TIM1_CCMR2,A
  247. ; Configure TIM1_IC Channel2 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".                                         
  248.                                         BSET TIM1_CCER1,#5   ; IC polarity: falling.
  249. ;         BRES TIM1_CCER1,#5         ; IC polarity: rising.                                
  250.                                        
  251.                                         BSET TIM1_CCER1,#4   ; Set the CCE Bit
  252.                                         RET

  253. .TIM1_SETIC2PRESCALER
  254.                                         BRES TIM1_CCMR2,#2   ; Reset TIM1_CCMR2 Register bits[3:2] first
  255.                                         BRES TIM1_CCMR2,#3
  256.                                         OR A,TIM1_CCMR2      ; Then set TIM1_IC2 Prescaler
  257.                                         LD TIM1_CCMR2,A
  258.                                         RET
  259.                                        
  260. ; 函数功能:TIM1的通道3输入捕捉配置。
  261. ; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
  262. ;           TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
  263. ;           TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
  264. ; 返回值:无
  265. ; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR3
  266. ;       2、用到的CPU寄存器:A,X
  267. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. .TIM1_IC3INIT
  270.           BRES TIM1_CCER2,#0   ; Disable the Channel 1: Reset the CCE Bit
  271.           PUSH A
  272.                                         LD A,#$0C
  273.                                         AND A,TIM1_CCMR3
  274.                                         LD TIM1_CCMR3,A
  275.                                         POP A                ; Select the Input and set the filter
  276.                                         SWAP A              
  277.                                         OR A,TIM1_CCMR3
  278.                                         LD TIM1_CCMR3,A
  279.                                         LD A,XL
  280.                                         OR A,TIM1_CCMR3
  281.                                         LD TIM1_CCMR3,A
  282. ; Configure TIM1_IC Channel3 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".                                         
  283.                                         BSET TIM1_CCER2,#1   ; IC polarity: falling.
  284. ;         BRES TIM1_CCER2,#1         ; IC polarity: rising.                                
  285.                                        
  286.                                         BSET TIM1_CCER2,#0   ; Set the CCE Bit
  287.                                         RET

  288. .TIM1_SETIC3PRESCALER
  289.                                         BRES TIM1_CCMR3,#2   ; Reset TIM1_CCMR3 Register bits[3:2] first
  290.                                         BRES TIM1_CCMR3,#3
  291.                                         OR A,TIM1_CCMR3      ; Then set TIM1_IC3 Prescaler
  292.                                         LD TIM1_CCMR3,A
  293.                                         RET
  294.                                        
  295. ; 函数功能:TIM1的通道4输入捕捉配置。
  296. ; 输入参数:TIM1_ICSelection--- TIM1输入捕捉的通道的输入信号参数选择,此参数可在此文件 TIM1输入捕捉的通道的输入信号参数宏定义中选择。
  297. ;           TIM1_ICPrescaler--- TIM1的输入捕捉预分频,此参数可在此文件的输入捕捉预分频宏定义中选择。
  298. ;           TIM1_ICFilter--- TIM1输入捕捉滤波器,此参数值为$00-$FF之间任意值。
  299. ; 返回值:无
  300. ; 备注:1、配置的寄存器:TIM1_CCER2,TIM1_CCMR4
  301. ;       2、用到的CPU寄存器:A,X
  302. ;       3、说明:为了减少参数,这里默认设置 TIM1相应通道的输入捕捉发生在输入信号的下降沿。可以根据实际需要修改。
  303. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                        
  304. .TIM1_IC4INIT
  305.           BRES TIM1_CCER2,#4   ; Disable the Channel 1: Reset the CCE Bit
  306.           PUSH A
  307.                                         LD A,#$0C
  308.                                         AND A,TIM1_CCMR4
  309.                                         LD TIM1_CCMR4,A
  310.                                         POP A                ; Select the Input and set the filter
  311.                                         SWAP A              
  312.                                         OR A,TIM1_CCMR4
  313.                                         LD TIM1_CCMR4,A
  314.                                         LD A,XL
  315.                                         OR A,TIM1_CCMR4
  316.                                         LD TIM1_CCMR4,A
  317. ; Configure TIM1_IC Channel4 polarity. The default setting is falling. If rising polarity needed, change "BSET" to "BRES".                                         
  318.                                         BSET TIM1_CCER2,#5   ; IC polarity: falling.
  319. ;         BRES TIM1_CCER2,#5         ; IC polarity: rising.                                
  320.                                        
  321.                                         BSET TIM1_CCER2,#4   ; Set the CCE Bit
  322.                                         RET

  323. .TIM1_SETIC4PRESCALER
  324.                                         BRES TIM1_CCMR4,#2   ; Reset TIM1_CCMR4 Register bits[3:2] first
  325.                                         BRES TIM1_CCMR4,#3
  326.                                         OR A,TIM1_CCMR4      ; Then set TIM1_IC4 Prescaler
  327.                                         LD TIM1_CCMR4,A
  328.                                         RET
  329.                                        
  330.          end


wang168506 发表于 2013-11-11 16:11 | 显示全部楼层
楼上反汇编
huangfeng33 发表于 2013-11-11 16:18 | 显示全部楼层
学习汇编对硬件起到的帮助作用是不容质疑!怎么这么多的朋友说起汇编好像都……不说了,怕轰炸
sidafuzhihe 发表于 2013-11-11 16:35 | 显示全部楼层
有点难度
黑曼巴 发表于 2013-11-11 16:48 | 显示全部楼层
真心觉得,楼主挺牛的,全汇编,赞一个!
劭峰 发表于 2013-11-11 19:36 | 显示全部楼层
金融小数 发表于 2013-11-11 20:39 | 显示全部楼层
楼主请把程序贴全,才能确认你的代码问题出在什么地方
金融小数 发表于 2013-11-11 20:41 | 显示全部楼层
楼主请把程序贴全,才能确认你的代码问题出在什么地方
香水城主 发表于 2013-11-11 22:25 | 显示全部楼层
10楼已经说了,DELAY子程序没有RET,程序逻辑已经全不对了。
ganlianghanshi 发表于 2013-11-16 20:41 | 显示全部楼层
看着就牛,顶一个
cjhk 发表于 2013-11-17 09:40 | 显示全部楼层
汇编语言   真的很头疼  不是很懂  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

482

主题

2214

帖子

11

粉丝
快速回复 在线客服 返回列表 返回顶部