-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab2.c
More file actions
146 lines (125 loc) · 2.6 KB
/
Lab2.c
File metadata and controls
146 lines (125 loc) · 2.6 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "address_map_arm.h"
// stop watch on DE10 standard
volatile int * load_ptr = (int*)HPS_TIMER0_BASE;
volatile int * currVal_ptr = (int*)HPS_TIMER0_BASE + 1;
volatile int * ctrl_ptr = (int*)HPS_TIMER0_BASE + 2;
volatile int * endInterrupt_ptr = (int*)HPS_TIMER0_BASE + 3;
volatile int * interrupt_ptr = (int*)HPS_TIMER0_BASE + 4;
volatile int * hex_ptr = (int*)HEX3_HEX0_BASE;
volatile int * hex_ptr2 = (int*)HEX5_HEX4_BASE;
volatile int * Key_ptr = (int*)KEY_BASE;
void start()
{
int count = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count6 = 0;
int lookUpTable[10];
lookUpTable[0] = 0x3F;
lookUpTable[1] = 0x6;
lookUpTable[2] = 0x5B;
lookUpTable[3] = 0x4F;
lookUpTable[4] = 0x66;
lookUpTable[5] = 0x6D;
lookUpTable[6] = 0x7D;
lookUpTable[7] = 0x7;
lookUpTable[8] = 0x7F;
lookUpTable[9] = 0x6F;
*(hex_ptr) = 0x3F;
*(hex_ptr + 1) = 0x3F;
*(hex_ptr + 2) = 0x3F;
*(hex_ptr + 3) = 0x3F;
*(hex_ptr2) = 0x3F;
*(hex_ptr2 + 1) = 0x3F;
while (*(Key_ptr) == 0)
{
*(ctrl_ptr) &= 0x000;
*(load_ptr) |= 0xF4240;
*(ctrl_ptr) |= 0b011;
*(hex_ptr) = *lookUpTable + 1;
*(hex_ptr+1) = *lookUpTable + 1;
*(hex_ptr + 2) = *lookUpTable + 1;
*(hex_ptr+3) = *lookUpTable + 1;
*(hex_ptr2) = *lookUpTable;
*(hex_ptr2+1) = *lookUpTable + 1;
if ((*(interrupt_ptr) &= 0b1) == 1)
{
count++;
if (count == 10)
{
count = 0;
count2++;
if (count2 == 10)
{
count2 = 0;
count3++;
if (count3 == 10)
{
count3 = 0;
count4++;
if (count4 == 10)
{
count4 = 0;
count5++;
if (count5 == 10)
{
count5 = 0;
count6++;
if (count6 == 10)
{
count6 = 0;
}
}
}
}
}
}
}
}
}
void reset()
{
int lookUpTable[10];
lookUpTable[0] = 0x3F;
lookUpTable[1] = 0x6;
lookUpTable[2] = 0x5B;
lookUpTable[3] = 0x4F;
lookUpTable[4] = 0x66;
lookUpTable[5] = 0x6D;
lookUpTable[6] = 0x7D;
lookUpTable[7] = 0x7;
lookUpTable[8] = 0x7F;
lookUpTable[9] = 0x6F;
*(hex_ptr) = 0x3F;
*(hex_ptr + 1) = 0x3F;
*(hex_ptr + 2) = 0x3F;
*(hex_ptr + 3) = 0x3F;
*(hex_ptr2) = 0x3F;
*(hex_ptr2 + 1) = 0x3F;
}
void stop()
{
*(ctrl_ptr) &= 0x0;
}
int main(void) {
while (1)
{
if ((*(Key_ptr) &= 1) == 1)
{
start();
}
else if ((*(Key_ptr) &= 2) == 1)
{
stop();
}
else if ((*(Key_ptr) &= 4) == 1)
{
reset();
}
else
{
}
}
}