Adding some comments to explain the interrupts.

This commit is contained in:
David A. Mellis 2006-11-29 19:35:43 +00:00
parent 514a74849a
commit d21eb97de4
2 changed files with 8 additions and 1 deletions

View File

@ -41,7 +41,13 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
intFunc[interruptNum] = userFunc; intFunc[interruptNum] = userFunc;
if (interruptNum == 0) { if (interruptNum == 0) {
// Configure the interrupt mode (trigger on low input, any change, rising
// edge, or falling edge). The mode constants were chosen to correspond
// to the configuration bits in the hardware register, so we simply shift
// the mode into place.
MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
// Enable the interrupt.
GICR |= (1 << INT0); GICR |= (1 << INT0);
} else { } else {
MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
@ -53,6 +59,7 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
void detachInterrupt(uint8_t interruptNum) { void detachInterrupt(uint8_t interruptNum) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
if (interruptNum == 0) if (interruptNum == 0)
// Disable the interrupt.
GICR &= ~(1 << INT0); GICR &= ~(1 << INT0);
else else
GICR &= ~(1 << INT1); GICR &= ~(1 << INT1);

View File

@ -41,7 +41,7 @@
// Define constants and variables for buffering incoming serial data. We're // Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the // using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail // location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read // is the index of the location from which to read.
#define RX_BUFFER_SIZE 128 #define RX_BUFFER_SIZE 128
unsigned char rx_buffer[RX_BUFFER_SIZE]; unsigned char rx_buffer[RX_BUFFER_SIZE];