NOTE: While most of what you need for interrupts is on this page, not all interrupt registers are discussed here. Only those that relate to the Interrupt How To. See the Interrupt chapter in datasheet for more information on Internal Interrupts and moving the vector table.
DDRB - Data Direction Register (for Port B)
7 6 5 4 3 2 1 0
DDRB = DDRB | ~(1 << PB2); (read: DDRB equals itself ORed with 0 shifted into the PB2/Pin 3 bit.)
Here, we set the direction of PB2 to 0, thus specifying it as an input. This corresponds to the PB2/Pin 3 on the Atmega324p that a button can be wired to. If we wanted this pin to be an output we would set it 1 instead.
PORTB - Data Register for Port B
We use this register to set the value high or low for the pin while it is set as input for out button interrupt. I this case we are not using the pull-up resistor.
Example:
PORTB = PORTB | (0<<PORTB2);
See the datasheet for I/O Ports for more details.
sei():
This command will enable the global interrupt system. After you have completed setting up your interrupt registers ( enabling the local interrupt(s) ) you must use this command to enable the entire interrupt system.
EIMSK - External Interrupt Mask
7 6 5 4 3 2 1 0
Bits 7 - 3 are reserved bits. Bits 2-0 represent INT2 -0 and correspond to the Pin you have chosen on the Atmega324p for your interrupt. In the Interrupts How To, this is INT2 which is Pin 3 and also called PB2 (Port B Pin 2). (See the Quick Pin Map). Setting a 1 in the bit for INT2 enables the interrupt for using this PIN.
For example, to enable the interrupt for a button wired to Pin 3 on the Atmega324p you set the INT2 bit to 1 with the command: PORTB = PORTB | (1 << PB2). You want to OR Port B with the bit you want to set to avoid changing the state of any of the rest of its pins in this port. It is a common mistake to do set this pin by executing: PORTB = 0xff. If you do this, you will set all of the pins in this port to 1. But what if you need some of those pin to be 0? For more on bit shifting and masking see the Kehrnigan and Richie ANSI C Programming book.
EIFR - External Interrupt Flag Register
Here, the INT2 bit will be set to 1 when the corresponding EIMSK bit is set to one. The same bit will be set to 0 when the ISR is triggered. It is also cleared when the interrupt is set to trigger an ISR on a level interrupt. These bit can be manually set as well.
EIRCA - External Interrupt Control Register
ISCxx Bits:
For the interrupt How To, this was set to trigger an interrupt on a rising edge.
The Vector Table:
In general, the Vector Table tells you what memory address is associated with the interrupt you are working with. This address then contains the address of the ISR. It also tells you how to reference the memory location when writing your ISR. For example: ISR(INT2_vect) as seen in the code for the Interrupt How To. In the definition of the ISR, the "ISR" name tells the Atmega the function is an interrupt routine and the "INT2" in INT2_vect is the name taken from the table for the appropriate interrupt vector address.
Below are just the first 4 entries in the table. The last entry represents the vector we need in the ISR for our ISR in the Interrupt How To. The rest of the table can be found in the Interrupt section of the datasheet.