我正在尝试使用中断作为 6502 Teensy 微控制器上计时动作的一种方式。我设法创建了一个计数器,通过触发中断来更快地添加位:
%uasm65
; v.002
; Increment port 0A200h at a rate of once increment
; per second. Use the timer based interrupt handler
; to control the time delay.
T1LL: equ B006h
T1LH: equ B007h
IER: equ B00Eh
ACR: equ B00Bh
COUNTDOWN: equ 500d
IRQVect: equ 0002d
OutChar: equ 0e003h
PrntMess: equ 0e00ch
org 0200h
lda #0d
sta IER ; Disable all interrupts.
lda #11000000b
sta ACR ; Set to T1 free running mode;
lda #COUNTDOWN<
sta T1LL ; Low byte of latch.
lda #COUNTDOWN>
sta T1LH ; High byte of latch.
; Initialize the interrupt vector.
lda #InterruptHandler<
sta IRQVect
lda #InterruptHandler>
sta IRQVect+1d
lda #01000000b
sta IER ; Enable all interrupts
cli ; Enable interrupts
MainLoop:
nop
jmp MainLoop
InterruptHandler:
;Save registers on the stack.
php
pha
txa
pha
tya
pha
inc 0a200h
;Restore registers from the stack.
pla
tay
pla
tax
pla
plp
cli ; Enable interrupts.
rti ; Return from interrupt.
end
%/uasm65
我要做的是每秒打印一次“你好”到控制台,并在按下 IRQ 时打印“那里”,触发中断。我会使用延迟循环,例如:
Delay:
;Save registers on the stack.
pha
txa
pha
tya
pha
;Change the number that is being loaded into the
; 'A' register in order to change the delay time.
lda 0a600h
OutLoop:
ldx #0dfh
InLoop1:
ldy #0ffh
InLoop2:
dey
bne InLoop2
dex
bne InLoop1
sec
sbc #1d
bne OutLoop
;Restore registers from the stack.
pla
tay
pla
tax
pla
rts
end
还是我需要一些由中断计时的东西?任何指导都会有所帮助。