I have to modify this assembly code in order to make it use interrupts. Right now, when I push button 1 on the microprocessor the count increments once (the LED's count in binary, using only 3 LED's and only counting to 7 in binary). The second button on the microprocessor, when pushed, resets the count. I have the addreses for both button in the code.
However, my trouble is modifying this code. I HAVE to use interrupts. I need a lot of help with this!! I don't even know where to start putting the code in for this!! The interrupts are supposed to be timer interrupts and when they happen, use a poll to count up or count down. I guess I'm supposed to have code in there that enables them??
Here's my working code right now with NO interrupts...
;This program is a binary debouncing counter. Each press of switch 1 will count forward in binary with the board LEDs. Once count 8 is reached, the counter will reset itself back to count/state 0. At any time, switch 2 can be pressed to fully reset the counter.
gaddr equ fe8H ; Port G address register
gddr equ fe9H ; Port G data direction register
gout equ febH ; Port G output register
eaddr equ fe0H ; Port E address register
eddr equ fe1H ; Port E data direction register
eout equ fe3H ; Port E output register
din equ fdeH ; Port D input register
fin equ fe6H ; Port D input register
reg equ ffdH ; Working register set
sphi equ ffeH ; Stack pointer high
splo equ fffH ; Stack pointer low
org 002H ; Initializing the reset vector
start:
dw 0038H ; Restart at this address
org 038H ; Start in first available memory location
ldx reg, #00H ; Select working register set
ldx splo, #20H ; Set low byte of stack pointer
ldx sphi, #02H ; Set high byte of stack pointer
reset:
ldx r4, #00H ; Set register to state counter of 0
call initLED ; Access both DDRs and make all bits outputs
call allOff ; Turn off all LEDs
endless:
call delay ; Delay for debouncing the switch
SW1:
ldx r1, din ; Load r1 with SW1's value
and r1, #08H ; See if the switch was pressed
jp ne, SW2 ; If switch was not pressed do not increment the state
inc r4 ; Increment state if pressed
N1:
cp r4, #1 ; Switch (r4) ?= 1
jp ne, N2 ; If not equal, check next number
call allOff ; Turn off all LEDs
call oneOn ; LED: 001
call latchClk ; Latch clock for LED
jp caseOut ; break
N2:
cp r4, #2 ; Switch (r4) ?= 2
jp ne, N3 ; If not equal, check next number
call allOff ; Turn off all LEDs
call twoOn ; LED: 010
call latchClk ; Latch clock for LED
jp caseOut ; break
N3:
cp r4, #3 ; Switch (r4) ?= 3
jp ne, N4 ; If not equal, check next number
call allOff ; Turn off all LEDs
call threeOn ; LED: 011
call latchClk ; Latch clock for LED
jp caseOut ; break
N4:
cp r4, #4 ; Switch (r4) ?= 4
jp ne, N5 ; If not equal, check next number
call allOff ; Turn off all LEDs
call fourOn ; LED: 100
call latchClk ; Latch clock for LED
jp caseOut ; break
N5:
cp r4, #5 ; Switch (r4) ?= 5
jp ne, N6 ; If not equal, check next number
call allOff ; Turn off all LEDs
call fiveOn ; LED: 101
call latchClk ; Latch clock for LED
jp caseOut ; break
N6:
cp r4, #6 ; Switch (r4) ?= 6
jp ne, N7 ; If not equal, check next number
call allOff ; Turn off all LEDs
call sixOn ; LED: 110
call latchClk ; Latch clock for LED
jp caseOut ; break
N7:
cp r4, #7 ; Switch (r0r4) ?= 7
jp ne, N8 ; If not equal, check next number
call allOff ; Turn off all LEDs
call sevenOn ; LED: 111
call latchClk ; Latch clock for LED
jp caseOut ; break
N8:
cp r4, #8 ; Switch (r4) ?= 8
jp eq, reset ; If 8, reset
caseOut: ; End of case
SW2:
ldx r1, fin ; See what Switch 2 is doing
and r1, #40H ; See if the switch was pressed
jp nz, waitLoop; If switch was not pressed do not reset
jp reset ; Reset if the switch was pressed
;-----------------------------
initLED:
ldx eaddr, #01H; select Port E DDR in address register
ldx eddr, #00H ; make all pins outputs
ldx gaddr, #01H; select port G DDR in address register
ldx gddr, #00H ; make all pins outputs
ret
waitLoop:
ldx r1, din ; Load r1 with SW1's value
and r1, #08H ; See if the switch was pressed
jp z, waitLoop; If switch is still pressed, loop again
jp endless
delay:
ld r2, #05H ; initialize r2 = 10
outer:
clr r0 ; set r0 = 0000H for maximum possible delay
clr r1 ; set r1 = 0000H for maximum possible delay
inner:
decw rr0 ; decrement rr0 (inner loop)
jp ugt, inner ; !=0, continue inner loop
dec r2 ; decrement r2 (outer loop)
jp ugt, outer ; !=0, continue outer loop
ret
oneOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1EH; enable the rightmost column
ret ; LED: 00001
twoOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1DH; enable the rightmost - 1 column
ret ; LED: 00010
threeOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1CH; enable the rightmost and rightmost -1 column
ret ; LED: 00011
fourOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1BH; enable the rightmost - 2 column
ret ; LED: 00100
fiveOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #1AH; enable the rightmost- 2 and rightmost column
ret ; LED: 00101
sixOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #19H ; enable the rightmost-2 and rightmost1column
ret ; LED: 00110
sevenOn:
ldx gout, #01H ; enable the topmost row
ldx eout, #18H ; enable the rightmost2,1,& rightmost column
ret ; LED: 00111
latchClk:
orx eout, #80H; drive D1's latches' clock high
andx eout, #7fH ; drive D1's latches' clock low
ret
allOff:
ldx gout, #00H ; disable all rows
ldx eout, #1fH ; disable all columns
orx eout, #e0H ; drive 3 Port E clocks high
andx eout, #1fH ; drive 3 Port E clocks low
orx gout, #80H ; drive 1 Port G clock high
andx gout, #7fH ; drive 1 Port G clock low
ret