#define F_CPU 3333333UL #include #include #include #define LED1 0 // port B #define LED2 1 // port B #define LED3 4 // Port B int main(void) { /* In this exercise we will get LEDs to blink at even intervals using interrupts First set up the LEDs like in the previous exercise. You can either copy paste from the previous exercise or start fresh. */ /*We will be using timer A that will trigger an overflow interupt. This is a 16 bit timer that can run in 2 modes -single mode as 1 16-bit timer -dual/split mode as 2 8-bit timers We will be using single mode in this exercise. Hint because the register names can be hard to understand: TCA0.SINGLE.CTRLA addresses the control A register for timer A First we set the prescaler to clk=clk/256 and enable the timer. This is done by setting the right bits in the control A register. */ //Next we Enable timer interupt for overflow on timer A. //Finally we have to set the max value of the timer, the top. //This defines the period of the interrupt (which hints at the register's name.) //Note that this is a 16 bit value! //To be able to react to the interrupts from the module we have to enable interrupts globally. //This is done in the function sei(), whih is located in the already included header file sei(); while(1){ //Do other things? //Remember to fill in the ISR at the bottom of the file, else nothing will happen! } } ISR(TCA0_OVF_vect){ //Do something with the led(s), like toggle. //Clear the interrupt flag. //If we do not clear the flag, we will instantly jump back into the ISR again }