Вы находитесь на странице: 1из 35

CSE 315

Microprocessors & Microcontrollers


Tanvir Ahmed Khan
Department of Computer Science and Engineering
Bangladesh University of Engineering and Technology.

September 20, 2014

Recap

ATmega16 Interrupts

Interrupts vs. Polling

Efficiency

Monitoring several devices

Priority

Ignoring a device request

ATmega16 Interrupts

Interrupts Service Routine

program associated with the interrupt

Interrupt Vector Table

group of memory locations


holding the addresses of ISR

Interrupt Execution

Steps in Interrupt Execution

finishes the instruction currently executing

acknowledges the interrupt

saves Program Counter (also current context) onto stack

jumps to interrupt vector table which redirects to the address


of the interrupt service routine

executes ISR upto RETI statement

retrieves the original context and PC by popping the first byte


of stack

Todays Topic

Interrupt Programming in C

Overview

Two Simple C programs for,

Overview

Two Simple C programs for,


I

Timer Interrupt

Overview

Two Simple C programs for,


I

Timer Interrupt

External Interrupt

Interrupt Programming Steps

Interrupt Programming Steps

include interrupt header file


I

#include <avr/interrupt.h>

Interrupt Programming Steps

include interrupt header file


I

#include <avr/interrupt.h>

enable global interrupt subsystem


I

sei();

Interrupt Programming Steps

include interrupt header file


I

enable global interrupt subsystem


I

#include <avr/interrupt.h>
sei();

define ISR for a specific interrupt


I

ISR(INT0 vect){}

Interrupt Programming Steps

include interrupt header file


I

enable global interrupt subsystem


I

sei();

define ISR for a specific interrupt


I

#include <avr/interrupt.h>

ISR(INT0 vect){}

enable that specific interrupt


I

TIMSK = TIMSK | 0b00000001;

Interrupt Programming Steps

include interrupt header file


I

enable global interrupt subsystem


I

ISR(INT0 vect){}

enable that specific interrupt


I

sei();

define ISR for a specific interrupt


I

#include <avr/interrupt.h>

TIMSK = TIMSK | 0b00000001;

configure other relevant registers

Timer Basic Registers Revisited

Our Simple Blink Example Using Timer0

Polling Approach

Our Simple Blink Example Using Timer0

Using Interrupt
Polling Approach

Programming External Hardware Interrupts

3 external hardware interrupts in ATmega16,

Programming External Hardware Interrupts

3 external hardware interrupts in ATmega16,


I

INT0, PD2-16

Programming External Hardware Interrupts

3 external hardware interrupts in ATmega16,


I

INT0, PD2-16

INT1, PD3-17

Programming External Hardware Interrupts

3 external hardware interrupts in ATmega16,


I

INT0, PD2-16

INT1, PD3-17

INT2, PB2-3

Enabling External Interrupt

Specifying External Events

Specifying External Events

Sample External Interrupt Program

ATmega16 Interrupts

ATmega16 Interrupts

Interrupt priority

ATmega16 Interrupts

Interrupt priority

Interrupt inside an interrupt

ATmega16 Interrupts

Interrupt priority

Interrupt inside an interrupt

RET vs. RETI

Reference

The avr microcontroller & embedded system, Chapter 10


I
I
I

Muhammad Ali Mazidi


Sarmad Naimi
Sepehr Naimi

Вам также может понравиться