main.c 1.64 KB
Newer Older
BuildTools's avatar
BuildTools committed
1
2
3
4
5
6
7
8
9


#define F_CPU 3333333UL


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

BuildTools's avatar
BuildTools committed
10
11
12
#define LED1 4 // port D
#define LED2 5 // port D

BuildTools's avatar
BuildTools committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64


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 <avr/interrupt.h>
	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
	
}