- #1
Jiggy-Ninja
- 309
- 1
I'm messing around with an 8051 microcontroller (DS89C450 if it makes a difference) and I'm trying to get a handle on how interrupts work, and what they can and can't do.
I'm working with Assembly right now, not C.
The program I made has a few songs in it's memory (very simple ones like "We Three Kings" and "Star-Spangled Banner"), and will start playing one at start up. Which one it plays depends on how a couple switches are set.
What I want to do is hook a pair of push buttons to the interrupt pins on P3; INT0 will reset and repeat the current song from the beginning regardless of the switch settings, and INT1 will reset and reload a new song.
Details aside, the essence of what I want to do is to make the interrupts cause a permanent branch to a specific location, at which point the interrupt ends and the program keeps running from that point. I don't want it to pick up where it left off after the interrupt is done.
So far, the only way I can think of doing this is something rather kludgy, like this:
* Song is a label in the code.
Needs to be modified a bit to protect the original value of DPTR, but you should get the basic concept.
For the record, I understand that polling the buttons might be a better solution,and would be trivially easy to do in my program. I already have a main loop that polls the timers (Though I might change one of them to an interrupt), so adding two more polls isn't much of a hassle. I'm not trying to do this for the most efficient or workable program, I'm trying to do this in order to understand interrupts better.
I'm working with Assembly right now, not C.
The program I made has a few songs in it's memory (very simple ones like "We Three Kings" and "Star-Spangled Banner"), and will start playing one at start up. Which one it plays depends on how a couple switches are set.
What I want to do is hook a pair of push buttons to the interrupt pins on P3; INT0 will reset and repeat the current song from the beginning regardless of the switch settings, and INT1 will reset and reload a new song.
Details aside, the essence of what I want to do is to make the interrupts cause a permanent branch to a specific location, at which point the interrupt ends and the program keeps running from that point. I don't want it to pick up where it left off after the interrupt is done.
So far, the only way I can think of doing this is something rather kludgy, like this:
Code:
mov DPTR, #Song
pop R1
pop R1 ; Popping the original return address from stack
push DPH ; Push the new address onto the stack
push DPL ; or whatever order these two need to be in
reti
Needs to be modified a bit to protect the original value of DPTR, but you should get the basic concept.
For the record, I understand that polling the buttons might be a better solution,and would be trivially easy to do in my program. I already have a main loop that polls the timers (Though I might change one of them to an interrupt), so adding two more polls isn't much of a hassle. I'm not trying to do this for the most efficient or workable program, I'm trying to do this in order to understand interrupts better.