■ FIGURE 3
were pressed.
While all this is going on, the Atom
flashes a separate LED on C0 (Atom P8) in the
main loop to represent other functions that
can happen while waiting for the interrupt
to occur.
HARDWARE SETUP
The schematic shows the connections for
this project. The four switches are tied to P4
through P7 with a pull-up resistor to Vdd (five
volts). All the switches are connected to the
P0 external interrupt pins through the diodes.
The diodes have the anodes tied to the B0 pin
and the cathode connected to the switches.
This allows the B0 pin to see a low (0.7 V) signal when a switch is pressed. The LEDs that
indicate which switch was pressed are connected to the C4 through C7 pins. The LED
connected to the C0 pin is the continuously-flashing LED in the project picture. All this is
done easily with one of my Ultimate OEM
modules, but you can build it with a bare PIC
16F876A or Atom 28 pin Interpreter PIC
16F876A chip.
ATOM SOFTWARE
MULTIPLE INTERRUPTS WITH ATOM
This next example shows how easy it is to use the
external interrupt (EXTINT interrupt) in Atom Basic. This
example also shows a method many beginners would
not have thought of: use the external interrupt to
capture more than one event by using it as a multiplexed
interrupt. The setup is shown in Figure 2 and the
schematic is in Figure 3. This same setup can be used
with PICBasic Pro, but you will see how the Atom
makes it even easier because we don’t have to set up all
the registers.
The hardware connections tie several switch inputs
to the P0 pin through diodes, so different I/O pins can
activate the external interrupt. In fact, the project has
four switches connected to the P4 through P7 pins, and
all of them multiplex connected to the P0 pin through
diodes. When any of the switches are pressed, the
Atom program is interrupted from what it was doing and
reads the P4 to P7 ports to see which switch was
pressed. Then it lights LED(s) connected to PIC pins C4
through C7 (Atom P12 through P15) that line up with
the switch position(s) to show which switch or switches
The software program (shown in Listing 2)
is really not that complex for something so
useful. This is considered an advanced topic
for the beginning Atom user, but you will see
that it’s not that difficult to understand. This
is because the Atom software makes using
interrupts very easy.
HOW IT WORKS
The program first establishes and sets up the external
interrupt and defines the label of where to go when the
external interrupt occurs.
OnInterrupt ExtInt, ProgInt ‘ Setup the external interrupt
The external interrupt can happen when the P0 port
transitions from a low-to-high or high-to-low state. We
choose high-to-low with the SETEXTINT command and the
EXT_H2L option. This will make the interrupt happen when
we press the switch rather than when we let it go
(EXT_L2H).
setextint EXT_H2L
‘ Interrupt on High to Low signal
Even though I show pull-up resistors on the
schematic for the switches, I initially didn’t include one
for the P0 pin, which was a mistake. It needs one to
make sure the P0 pin is sitting at a known state, so I
84
June 2006