-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_task.c
104 lines (86 loc) · 2.27 KB
/
parallel_task.c
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
/*******************************
* HK Transfield
*
* Parallel Task
*******************************/
#include "wramp.h"
/**
* Shows numbers in the SSD as a hexadecimal number
* by shifting the number logical right.
*
* @param n The number that will be written
*/
void writeHexSSD(int n)
{
WrampParallel->LowerRightSSD = n;
n >>= 4;
WrampParallel->LowerLeftSSD = n;
n >>= 4;
WrampParallel->UpperRightSSD = n;
n >>= 4;
WrampParallel->UpperLeftSSD = n;
}
/**
* Shows numbers in the SSD as a decimal number by
* calculating the remainder and dividing the number
* by 10.
*
* @param n The number that will be written
*/
void writeDecSSD(int n)
{
int rem = 0;
rem = n % 10;
WrampParallel->LowerRightSSD = rem;
n /= 10;
rem = n % 10;
WrampParallel->LowerLeftSSD = rem;
n /= 10;
rem = n % 10;
WrampParallel->UpperRightSSD = rem;
n /= 10;
rem = n % 10;
WrampParallel->UpperLeftSSD = rem;
}
/**
* Main entry point to the parallel task
*/
void parallel_main()
{
// declare variables
int switches = 0; // stores the value of the parallel switches
int buttons = 0; // stores the value of the parallel push buttons
int pressed = 0; // tracks the last button pressed
while (1)
{ // begin infinite loop
// read values from parallel ports
switches = WrampParallel->Switches;
buttons = WrampParallel->Buttons;
if (buttons == 1 || buttons == 2 || buttons == 4) // any push button has been pressed
{
while (1)
{
// continuing reading from the parallel port registers
switches = WrampParallel->Switches;
buttons = WrampParallel->Buttons;
if (buttons == 1 || pressed == 1)
{
pressed = 1;
writeHexSSD(switches);
}
if (buttons == 2 || pressed == 2)
{
pressed = 2;
writeDecSSD(switches);
}
if (buttons == 4)
return;
}
}
else
{
// if no buttons have been pressed, print switches as hex
writeHexSSD(switches);
}
}
}