summaryrefslogtreecommitdiff
path: root/final_project/clock.c
blob: 7c216fc883615674300708a78dc655b717f6d806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * clock.c
 *
 * Created: 4/3/2024 10:29:19 AM
 *  Author: bsw9xd
 */ 
#include "clock.h"

void timer_init_ctc() {
	TCCR1A = 0x00; //WGM10 = 0, WGM11 = 0 (CTC mode when combined with WGM12 in TCCR1B)
	TCCR1B = (1 << WGM12);
	TCNT1 = 0; // initialize timer at 0
	//TIMSK1 |= (1<<OCIE1A); // enable int at timer1

}

void start_timer() {
	TCNT1 = 0;
	OCR1A = 0x3d09; // 1 second
	if(TIFR1 & (1 << OCF1A)) TIFR1 |= (1 << OCF1A);
	TCCR1B |=  (1<<CS12) | (1 << CS10); //start timer with 1024 prescalar
}

void stop_timer() {
	if(TIFR1 & (1 << OCF1A)) TIFR1 |= (1 << OCF1A);
	TIMSK1 = (1 << WGM12);
}

bool timer_done() {
	return (TIFR1 & (1 << OCF1A)); 
}