-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathCommon.c
67 lines (62 loc) · 1.43 KB
/
Common.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
//////////////////////////////////////////////////////////////////////////////
//
// Filename: Common.c
// Version:
// Data:
//
// Author: Liu, Zemin
// Company: JYE Tech
//
//-----------------------------------------------------------------------------
//
// Target: STM32F103C8
// Tool chain: CodeSourcery G++
//
//
//-----------------------------------------------------------------------------
// Required files:
//
//-----------------------------------------------------------------------------
// Notes:
//
//
//-----------------------------------------------------------------------------
// Revision History:
//
///////////////////////////////////////////////////////////////////////////////
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "Common.h"
void Delay(volatile U16 count)
{
while(count) {
count--;
}
}
// -------------------------------------------------------------------------
// Convert binary to hexical digit string. 'size' is in bytes.
//
U8* BinToHexStr(U32 bin, U8 *str, U8 size)
{
U8 tmp0;
size = 2 * size + 2;
*(str + size) = 0; // end of string
size--;
while(size >= 2) {
tmp0 = 0x0000000F & bin;
if(tmp0 <= 9) {
tmp0 |= 0x30;
}
else {
tmp0 += 0x37;
}
*(str + size) = tmp0;
bin >>= 4;
size--;
}
*(str + size--) = 'x';
*(str + size) = '0';
return str;
}