Hi,
I'm trying to get a button to work on a Teensy 2.0 with C + Makefile but to no avail.
Here's the code:
I get weird results. When I turn on the Teensy I see no interrupts. When my hand gets near the wires of the button a deluge of interrupts occurs continuously. When I press and hold down the button the interrupts stop. When I release the button the interrupt deluge starts anew.
I'm trying to get a button to work on a Teensy 2.0 with C + Makefile but to no avail.
Here's the code:
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h> // _delay_ms()
#include "print.h" // print debug output through usb port
#include "macros.h" // set_bit(), clear_bit(), LED_ON, LED_OFF
int main(void)
{
usb_init(); // init usb port to send debugging information
_delay_ms(2000);
DDRD &= ~(1 << DDD0); // Clear the PD0 pin
PORTD |= (1 << PORTD0); // turn On the Pull-up
EICRA |= (1 << ISC00); // set INT0 to trigger on ANY logic change
EIMSK |= (1 << INT0); // Turns on INT0
sei(); // turn on interrupts
while(1)
{
/*main program loop here */
}
}
ISR (INT0_vect)
{
print("Button pressed\n");
}
I get weird results. When I turn on the Teensy I see no interrupts. When my hand gets near the wires of the button a deluge of interrupts occurs continuously. When I press and hold down the button the interrupts stop. When I release the button the interrupt deluge starts anew.
Attachments
Last edited: