-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
51 lines (41 loc) · 1.12 KB
/
timer.c
File metadata and controls
51 lines (41 loc) · 1.12 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <pic32mx.h>
#include <stdint.h>
#include <stdbool.h>
#include <pic32mx.h>
#include "header.h"
// stolen from lab, written by us
void timer2(void)
{
T2CON = 0x70; // Pre-scale
/*T2CON |= 0xC000;
T2CON |= 0x4;*/
TMR2 = 0;
IEC(0) = (1 << 8);
IPC(2) = 4;
enable_interrupt(); // enable_interrupt from labwork.S
PR2 = 625; // 625; // Sätter delayen korrekt (3125 * 256 = 800 000) Räknar med pre-scale
T2CON |= 0x8000; // Starts the timer
}
int serveDelayCount = 0;
void user_isr(void)
{
// IFSCLR(0);
if (IFS(0) & 0x100) // If flag of timer 2 raised, reset flag. assignment 3e.
{
isTicked = true;
IFSCLR(0) = 0x100; // Code to reset flag. The sooner the better. Source: Trust me bro.
if (getServeDelay())
{
serveDelayCount++;
if (serveDelayCount >= 500)
{
setServeDelay(false);
startGame();
serveDelayCount = 0;
}
}
// IFS(0) = IFS(0) & 0x00000800;
}
// IFS(0) = 0; // Since there could be other flags raised.
return;
}