AVR Microcontroller and Embedded Systems
AVR Microcontroller and Embedded Systems
main ()
DDRA = OxFF;
DDRD = OxFF;
DDRB |= 0x40;
PORTB |= 0x01;
TCNTO = -200;
TCCRO = 0x06;
TCNT1H = (-31250) 8;
TCNT1L = (31250)&0xFF;
TCCR1A = 0x00;
TCCR1B = 0x04;
while (1)
PORTD = PINC;
//wait here
I
SR
{
I
SR
{
}
(TIMERl_OVF_vect)
TCNT1H = (-31250)> > 8;
TCNT1L = (31250)&0xFF;
PORTA
++;
DDRB [= 0x20;
OCRO 40;
TCCRO = 0x09;
TIMSK = (lOCIE0) ;
sei ();
DDRC = 0x00;
DDRD = GxFF;
while (1)
PORT
D
ISR (TIMERO_COMP_vect)
PORTB A= 0x20;
}
//toggle PORTB.5
#include "avr/io.h"
frinclude
"avr/interrupt.h"
int main ()
{
DDRC = 13;
PORTD = 12;
GICR = (1INT0) ;
sei () ;
while (1);
//wait here
ISR (INT0_vect)
{
PORTC A= (13) ;
GICR = (1INT0);
sei ();
while (1);
}
ISR
(INTO vect)
{
PORTC A= (13);
//PC3 as an output
//pull-up activated
//make INTO falling edge triggered
SUMMARY
An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Every interrupt has a program
associated with it called the I SR, or interrupt service routine. The AVR has many
sources of interrupts, depending on the family member. Some of the most widely
used interrupts are for the timers, external hardware interrupts, and serial communication. When an interrupt is activated, the IF (interrupt flag) bit is raised.
The AVR can be programmed to enable (unmask) or disable (mask) an
interrupt, which is done with the help of the I (global interrupt enable) and IE
(interrupt enable) bits. This chapter also showed how to program AVR interrupts
in both Assembly and C languages.
PROBLEMS
SECTION 10.1: AVR INTERRUPTS
1. Which technique, interrupt or polling, avoids tying down the microcontroller?
2. List some of the interrupt sources in the AVR.
3. In the ATmega32 what memory area is assigned to the interrupt vector table?
4. True or false. The AVR programmer cannot change the memory address location assigned to the interrupt vector table.
5. What memory address is assigned to the TimerO overflow interrupt in the
interrupt vector table?
6. What memory address is assigned to the Timerl overflow interrupt in the
interrupt vector table?
7. Do we have a memory address assigned to the TimeO compare match
interrupt in the interrupt vector table?
8. Do we have a memory address assigned to the external INTO interrupt in the
interrupt vector table?
9. To which register does the I bit belong?
10. Why do we put a JMP instruction at address 0?
11. What is the state of the I bit upon power-on reset, and what does it mean?
12. Show the instruction to enable the TimerO compare match interrupt.
13. Show the instruction to enable the Timerl overflow interrupt.
14. The TOIEO bit belongs to register_________.
15. True or false. The TIMSK register is not a bit-addressable register.
16. With a single instruction, show how to disable all the interrupts.
17. Show how to disable the INTO interrupt.
18. True or false. Upon reset, all interrupts are enabled by the AVR.
19. In the AVR, how many bytes of program memory are assigned to the reset?
SECTION 10.2: PROGRAMMING TIMER INTERRUPTS
20. True or false. For each of TimerO and Timerl, there is a unique address in the
interrupt vector table.