Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


errupt, if a bit is
is enabled to trigger the PCI1 interrupt. A
le the buttons of interest:

x

’t care what that bit is. Since some other part of
to leave it as is. The statement:

|(1<<PINB7))

as they were. As a
1, 0|1=1, and 0|0=0. So the 1 bits
e 0 bits will set the
it was already 0. If this is still
a bit. It is a critical

several places in our
ill simplify our lives, the #define

1<<PINB6)|(1<<PINB7))

rectives and before the main() function,
ubstitute ((1<<PINB4)|(1<<PINB6)|(1<<PINB7)) for each
B_MASK in the code. So we can write:

PCMSKB = PINB_MASK;

file but the C compiler will see:

= ((1<<PINB4)|(1<<PINB6)|(1<<PINB7))

r, EIMSK, and External Interrupt Flag
egister, EIFR are discussed on page 78 of the data book. We set them to enable

The PCMSK1 register controls, which pins contribute to the int
set to 1 the corresponding bit in Port B
0 disables the interrupt for a pin. To enab


Port B bit position 7 6 5 4 3 2 1 0
PCMSK1 1 1 x 1 x x xbit


We use ‘x’ to indicate that we don
the software might be using that bit, we want


PCMSK1 |= ((1<<PINB4)|(1<<PINB6)

Changes bits 4, 6, and 7 to 1 and leaves the rest of the bits
review, remember what the ‘|’ does: 1|1=1, 1|0=
will set to one no matter what they were in PCMSK1 and th
PCMSK1 bit to 1 if it was already 1 and to 0 if
obscure get out the pencil-and-paper-computer and play with it
concept for understanding microcontrollers.


We are going to use: (1<<PINB4)|(1<<PINB6)|(1<<PINB7)
code, so let’s look at a new item that w
preprocessor directive. If we put:


#define PINB_MASK ((1<<PINB4)|(

In our code, usually after the #include di
the preprocessor will s
occurrence of PIN


in our source


PCMSK1

The External Interrupt Mask Registe
R
the PCI1 interrupt as follows:

Free download pdf