Chapter 7: Microcontroller Interrupts and Timers
dog ar the page before closing the book. Then
e and when the call is finished and you’ve put out the fire in
ga refer to the desecrations to your book and go right back to
an interrupt causes the microcontroller to stop
sufficient data so that later it can get back to what it was
, and when
using the
r
ome particularly pernicious
ger from memory and since
opped by an
f the integer before returning control to the part
ding the integer which then gets the second byte of the
ger l be wrong because it will be made half from the pre-
rrupt value and half from the post-interrupt value. The crazy making
is that the interrupt can happen at any time, maybe only very
ly d p and then locks up
kind of bug in your pacemaker. You
ven g interrupts before reading variables that can be
nged by interrupts then enabling them after you’ve got the correct number.
g some fairly intense code based on the Butterfly
ick. If you compare the software used in this
you might think I stole some of it. And you’d be
rect. That is one of the central principles of software engineering: if it ain’t
if it is nailed down, get a crowbar and rip it up. It’s
e stupid to reinvent the wheel by trying to
you have perfectly good code already
ilable. There are only two reasons to write stuff you can steal, one is that you
s to avoid a lawsuit - if the software doesn’t
can be used, then it is copyrighted. Hopefully, I won’t get
to the line you were reading and -e
you a
our
nswer the phon
y rage, you can
where you left off your reading.
From the hardware perspective
what it is doing, store
doing, look to see which interrupt happened, run the interrupt code
finished restore the machine to its state before the interrupt occurred
previously sto ed data.
Interrupts are great, but they provide an avenue for s
bugs. For example when your code is reading an inte
an integer is made of two bytes it gets the first byte, then is st
interrupt that changes the value o
o ode that was rea
. The integer wil
f the c
inte
inte
debugging problem
rare uring the integer read. Your system can run like a cham
for no apparent reason. You don’t want this
pre t this bug by disablin
cha
We’ll study interrupts by usin
software used to read the joyst
example to the Butterfly software
cor
nailed down - steal it. Heck,
also called ‘code reuse’ and you’d b
write something from scratch when
ava
want to learn by doing, and the other i
specifically state that it
sued.