#include <avr/io.h> #include <util/delay.h> #include <asf.h> #include "tc.h" static void my_callback(void); int main(void) { pmic_init(); sysclk_init(); board_init(); PORTR_DIRSET= 0x03; PORTE_DIRCLR = 0x20; while (1) { if ((PORTE.IN & PIN5_bm)) { tc_enable(&TCC0); cpu_irq_enable(); tc_set_overflow_interrupt_callback(&TCC0, my_callback); tc_set_wgm(&TCC0,TC_WG_NORMAL); tc_write_period(&TCC0, 31250); tc_set_overflow_interrupt_level(&TCC0,TC_INT_LVL_LO); tc_set_resolution(&TCC0, 31250); } } } static void my_callback(void) { if (!(PORTE.IN & PIN5_bm)) { PORTR_OUTCLR = PIN0_bm; _delay_ms(400); PORTR_OUTSET = PIN0_bm; tc_clear_overflow(&TCC0); } // User code to execute when the overflow occurs here else if (PORTE.IN & PIN5_bm) { PORTR_OUTCLR = PIN1_bm; _delay_ms(400); PORTR_OUTSET = PIN1_bm; tc_clear_overflow(&TCC0); } }
Only when i put condition of a button press the overflow callback function is not getting called,if i normally do it without any button press condition its working fine and toggling the LED.I'm using atxmega256a3bu xplained.