我刚学avr汇编,写了一个用一位数码管循环显示0-9的小程序,但仿真没达到预期效果,不知道是怎么回事,请各位指教!!!
;一位数码管循环显示数字0-9程序
.include"m16def.inc"
.def Time =r20
.def count=r17 ;中断次数计数器
.org $0000
rjmp main
.org $010
rjmp time1_ovf
tab:.db 0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F ;0-9数字段码表,共阴极
main:
ldi r16,0xff
out ddrd,r16
ldi r16,0x00
out tccr1a,r16
ldi r16,0x1E
out tcnt1l,r16 ;计数器1赋初值
ldi r16,0xfb
out tcnt1h,r16
ldi r16,$04
out timsk,r16 ;开定时器1溢出中断
ldi r16,0x01 ;1分频
out tccr1b,r16
;clr count
;clr time
sei ;开全局中断
Display:
ldi zh,high(tab*2)
ldi zl,low(tab*2)
add zl,Time ;取数字段码
lpm
out portd,r0 ;段码从PD口输出
rjmp Display ;循环显示
time1_ovf:
ldi r16,0x1E
out tcnt1l,r16
ldi r16,0xfb
out tcnt1h,r16
inc count ;中断100次,中断时间为10ms
cpi count,100 ;100x10=1S
brlo M ;小于100则退出,继续等待中断
clr count ;达到100次则清零中断计数器
inc Time
cpi Time,9 ;小于9则退出
brlo M
clr Time ;计数大于9则清零
M: reti |