请问马老师,我的第一个汇编程序,为什么没结果出来?
我用马老师的实验板想实现一个PA0口使LED亮一秒灭一秒的实验,可是就是没结果出来,马老师能否帮我看一下如下的汇编程序,我不知道问题出在哪里!!!谢谢了!!!
程序如下:
.include "m16def.inc"
.def count =r17
.def flag_1s=r18
.def temp =r19
.org $000
rjmpreset ;复位处理
nop
reti ;IRQ0 Handler
nop ; 不用的可以用RETI和NOP代替
reti ;IRQ1 Handler
nop
reti ;Timer2 Compare Handler
nop
reti ;Timer2 Overflow Handler
nop
reti ;Timer1 Capture Handler
nop
reti ;Timer1 Compare-A Handler
nop
reti ;Timer1 Compare-B Handler
nop
reti ;Timer1 Overflow Handler
nop
reti ;Timer0 Overflow Handler
nop
reti ;SPI Transfer Complete Handler
nop
reti ;USART RX Complete Handler
nop
reti ;USART UDR Empty Handler
nop
reti ;USART TX Complete Handler
nop
reti ;ADC Conversion Complete Handler
nop
reti ;E2PROM Ready Handler
nop
reti ;Analog Comparator Handler
nop
reti ;Two-wire Serial Interface Handler
nop
reti ;IRQ2 Handler
nop
rjmp Timer0_com ;Timer0 Compare Handler
nop
reti ;SPM Ready Handler
nop
.org $02A
reset:
ldi r16, high(RAMEND)
out sph, r16
ldi r16, low(RAMEND)
out spl, r16
ldi temp, 0x01
out ddra, temp
ser temp
out porta, temp
ldi flag_1s, 0x00
ldi count, 0x7d
;T0初始化
ldi temp, 0x2c
out tccr0, temp ;4M 256分频,CTC模式,
ldi temp,0x00
out tcnt0,temp
ldi temp, 0x7c ;OCR0=125 4000000/256/125=125
out ocr0, temp
ldi temp, 0x02
out timsk, temp
sei
;主程序
main:
cpi flag_1s, 0xff
brne loop
cbi porta, 0
rjmp main
loop:
sbi porta, 0
rjmp main
;T0中断处理
Timer0_com:
in r16, sreg
push r16
dec count
cpi count, 0x00
brne tim0_ret
com flag_1s
pop r16
out sreg, r16
tim0_ret:
reti 先改一个地方,否则你的堆栈就暴了。
另外你的count初值为0x7d,在中断中减到0后,是否还需要再设置成0x7d?
其它留给你自己分析吧。
;T0中断处理
Timer0_com:
in r16, sreg
push r16
dec count
cpi count, 0x00
brne tim0_ret
com flag_1s
tim0_ret:
pop r16
out sreg, r16
reti 谢谢马老师,问题我已经解决了!
页:
[1]