有人能发现为什么这段代码无法输出恒定脉冲吗?至少我的福禄克不能触发高脉冲,似乎它来来去去有点随机..
这是我的第一个 asm 程序,所以请记住它可能是代码中的幼稚错误
;INITIAL
.include "tn10def.inc" ; Include file for Attiny10
.org $0000
rjmp RESET ; ISR reset vector (also start of prog)
.org $0008
rjmp WDT ; Watchdog reset vector
.def t = r16 ; temp register
.def PWM_c1 = r24 ; PWM counter register 1
.def PWM_c2 = r25 ; PWM counter register 2
.def PWM_c3 = r17 ; PWM counter register 3
RESET:
;INIT_STACK:
ldi t, low(RAMEND) ; init high and low bytes for stack pointer
out spl, t
ldi t, high(RAMEND)
out sph, t
;INIT_SLEEP:
ldi t, (0<<SM2)|(1<<SM1)|(0<<SM0)|(1<<SE)
out SMCR, t ; set power down mode at sleep command
;INIT_ISR
sei ; enable global interrupts
;INIT_POWERSAVER
ldi t, (1<<ADC1D)|(1<<ADC0D)
out DIDR0, t
;INIT_CLOCK
ldi t, 0xD8 ; write signature
out CCP, t
ldi t, (1<<CLKPS3)|(0<<CLKPS2)|(0<<CLKPS1)|(0<<CLKPS0)
out CLKPSR, t ; prescale by 256
MAIN_LOOP:
rcall PWM_INIT
rcall POWER_DOWN ; WDT power down
rjmp MAIN_LOOP
PWM_INIT:
ldi PWM_c3, 255 ; total number of pulses
PWM_START:
sbi PORTB, led ; set out high
ldi PWM_c1, 0
ldi PWM_c2, 0
PWM_LOOP:
inc PWM_c1
cpi PWM_c1, 16 ; target count (PWM high)
breq PWM_OUT_LOW
cpi PWM_c1, 208
brne PWM_LOOP ; first loop counts to 208
inc PWM_c2
cpi PWM_c2, 5
brne PWM_LOOP ; second loop counts to 5
dec PWM_c3
brne PWM_START ; counts down number of pulses
ret
PWM_OUT_LOW:
cbi PORTB, led
rjmp PWM_LOOP