Write the main background loop and all required set up code to configure and ena
ID: 2084529 • Letter: W
Question
Write the main background loop and all required set up code to configure and enable an IRQ-not interrupt. Then write an IRQ-not service routine that manipulates a counter called IRQCOUNT, delays for 1/2 second, then returns. Each time an interrupt event occurs (press of pushbutton), the counter should count up by 1. When the counter reaches 17, the counting direction should reverse (count down) until it reaches 0, then it should count up again, and continue this up down functionality. Test your code by wiring a pushbutton switch from the MCUSLK board to the IRQ-not input. The switches on the MCUSLK already have pull-up resistor installed as shown on the drawing below. Set a break point at the IRQ ISR and step through the logic (step over the delay) to make sure everything is working properly. Use the debugger software to monitor the value in IRQCOUNT as the switch is pressed. Remove breakpoints and watch the counter. which should change each time the switch is pressed. Note any inconsistencies in the sequence then note the current setting of the IRQ edge/level bit and change it. Compile and run the code again. Does the edge/level bit have an effect on the counting sequence? Does delay time have an effect on the counting sequence?Explanation / Answer
===================================
ORG C000 ;set PC to $C000
Entry:
; do some initialization
movb #input, porth_ddr ; set Port H to input
movb #output, portb_ddr ; set Port B to output
jsr DELAY
loop: movb #ledsoff, portb ; turn LEDs off
ldd #$0 ; initialize Port D
sw2: brset porth, #sw2on, sw3 ; if bit 3 Port H high, branch to sw3
movb #led2on, portb ; LED2 will light if Port H bit 3 low
ldd #sec
jsr DELAY ; delay time = (Reg D) * msec
sw3: brset porth, #sw3on, loop ; if bit 2 Port H high, branch to loop
movb #led3on, portb ; LED3 will light if Port H bit 2 low
ldd #five_sec
jsr DELAY ; delay time = (Reg D) * msec
bra loop
swi ; end the program
DELAY:
pshd
pshx
pshy
tfr D,Y ; (D) -> (Y)
starty: ldx #msec ; start y loop and set x loop to 1 msec
startx: dex ; start x loop - 4 cycles per startx loop if branch
bne startx
dey
bne starty
puly
pulx
puld
rts
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.