嵌入式系统代写代做代考 Embedded Systems Reconfigurable computing

Reconfigurable computing

Small Embedded Systems

Unit 3.5 External Interrupts using
AVR Special Function Registers

Introduction
The ATmega 328P is a member of the AVR architecture series
We’ll look at an external interrupt example for AVR
We’ll see
Why the interrupt is useful
How it is done with Arduino library functions
How it is done by manipulating the AVR special function registers

Example
When we press the button the LED will light up

Let’s zoom in a bit

Example
When we press the button the LED will light up

It works fine
But that example is too simple
What if there were lots of other tasks to do?

Our Example has a Problem
Let’s make things more realistic

I have to hold the button for 3 seconds to get response
Response may be very slow
No good!

We’ll emulate the effect of other tasks that take 3 sec

External Interrupt Pins

The ATmega 328P has two external interrupt pins:
INT0 on pin 2
INT1 on pin3
We’re gong to use INT0 to switch our LED

Now we use an external interrupt

Everything is fine, even when there are other time consuming tasks

Fix the Problem with an Interrupt

Fix the Problem with an Interrupt

Interrupt service routine flips LED state
State of LED must be volatile

Button change triggers interrupt

This is using Arduino functions
How do we do it with AVR special function registers?

Step 1: Do the I/O with Registers

Data Sheet: Choose the Interrupt
EIMSK determines which interrupt we will use

EIMSK |= (1<