-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathutil.c
69 lines (56 loc) · 2.03 KB
/
util.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
///
/// @file util.c
/// @author Kyeong Soo (Joseph) Kim <[email protected]>
/// @date 2012-02-21
///
/// @brief Implements utility and miscellaneous functions.
///
/// @remarks This program is based on Dr Tim Davies' assembly version of
/// micro mouse program and the C port of it by Mr Gareth Evans.
///
/// @copyright Copyright (C) 2012 Swansea University. All rights reserved.
///
/// @copyright This software is written and distributed under the GNU General
/// Public License Version 2 (http://www.gnu.org/licenses/gpl-2.0.html).
/// You must not remove this notice, or any other, from this software.
///
#include "mouse.h" // for the declaration of types, constants, variables and functions
//------------------------------------------------------------------------------
// Functions for bit handling
//------------------------------------------------------------------------------
// function to set a specific bit of an unsigned 8-bit integer
byte BitSet(byte Bit_position, byte Var_old)
{
byte Var_new;
Var_new = Var_old | (byte)(1<<Bit_position);
return Var_new;
}
// function to clear a specific bit of an unsigned 8-bit integer
byte BitClear(byte Bit_position, byte Var_old)
{
byte Var_new;
Var_new = Var_old & (~(byte)(1<<Bit_position));
return Var_new;
}
//--------------------------------------------------------
// Functions for delay
//--------------------------------------------------------
void Delay(int a)
{
int b=0,c=0;
for (b=0;b<a;b++){
for(c=0;c<100;c++);
}
}
//------------------------------------------------------------------------------
// Functions for ADC module (e.g., for read values from line sensors)
//------------------------------------------------------------------------------
byte ADCRead(byte ch)
{
word value;
ADC1SC1 = ch;
while (ADC1SC1_COCO != 1)
{ // wait until ADC conversion is completed
}
return ADC1RL; // lower 8-bit value out of 10-bit data from the ADC
}