PICAXE PRIMER
interrupted. (We'll discuss this point
in a little more detail later, as well.)
The only complicated part of all
this is how you specify the input
condition(s) that you want to trigger
the interrupt. Since the setint command
is a little simpler than the setintflags
command, let's use it for our first
example. The full syntax is "setint
input, mask" where input refers to the
desired input condition(s) and mask
refers to (what else?) the mask. So, if
your pushbutton is on input1 and
pressing it makes the input high, you
want the "input" parameter to equal
"%00000010" — remember, the "%"
indicates binary data and, in this
context, that's easier to understand
than a decimal number would be
because the "1" in the bit1 position
makes it clear that this is the input in
which we are interested. However,
without the mask we would be
saying that we want input1 to be
high and all the other inputs to be
low, which is not what we mean and
might never occur anyway. The mask
solves this dilemma as follows: If you
want a specific bit to be included in
the input specification, place a "1" in
the corresponding bit position of the
mask; if you want to ignore a bit,
place a "0" in the corresponding bit
position of the mask. So, in our
example, the complete command
would be "setint %00000010,
%00000010" — the second
parameter (mask) says "just check
input1 and ignore all the others" and
the first parameter (input) says
"whenever input1 is high, execute the
interrupt code." You can also set up
an interrupt to respond to multiple
input specifications, but we're going
to keep it (relatively) simple for now.
Whenever an interrupt routine is
executed, the interrupt is immediately
disabled. If this weren't the case and
we pressed the button for even a
fraction of a second, the interrupt
would interrupt itself dozens of times
— not usually what you want to
happen (but see the documentation
for an example of what to do when
that is exactly what you do want
to happen). However, since you
probably want the interrupt to occur
again on the next button-press, you
need to re-enable the interrupt by
re-issuing the same setint command
just before you return from the
interrupt subroutine.
Once you have a fairly clear
understanding of how PICAXE
interrupts function, we're ready to
move on to the setintflags command,
which is the one we're going to use
to retrieve the serial data that is
automatically being received from
the IRMB. The X1 chips contain a
built-in system "flags" byte and bit5 of
this byte is the "hserflag" — it usually
equals 0 but whenever a serial byte is
received on the "ser rx" pin (pin 18
on the 28X1), hserflag is immediately
set to 1. We can use the setintflags
command to trigger an interrupt
whenever this transition occurs. The
complete syntax is "setintflags flags,
mask" and it functions very similarly
to the setint command. Since
we want to trigger an interrupt
The Newest Products and
Technologies are Only a Click
Away!
mouser.com
• Over A Million Products Online
• More Than 366 Manufacturers
• Easy Online Ordering
• No Minimum Order
• Fast Delivery, Same-day Shipping
(800) 346-6873
The Newest Products
For Your Newest Designs
Mouser and Mouser Electronics are registered trademarks of Mouser Electronics, Inc. Other products, logos, and
company names mentioned herein, may be trademarks of their respective owners.
February 2009 19