-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
118 lines (105 loc) · 3 KB
/
config.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "compiler_defs.h"
#include "C8051F040_defs.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Timer_Init()
{
SFRPAGE = TIMER01_PAGE;
TCON = 0x41;
TMOD = 0x21;
CKCON = 0x18;
TH1 = 0xAF;
SFRPAGE = TMR3_PAGE;
TMR3CN = 0x04;
TMR3CF = 0x1A;
RCAP3L = 0xDC;
RCAP3H = 0x0B;
}
void UART_Init()
{
SFRPAGE = UART0_PAGE;
SCON0 = 0x70;
}
void SPI_Init()
{
SFRPAGE = SPI0_PAGE;
SPI0CFG = 0x40;
SPI0CN = 0x01;
SPI0CKR = 0x7C;
}
void Port_IO_Init()
{
// P0.0 - TX0 (UART0), Push-Pull, Digital
// P0.1 - RX0 (UART0), Open-Drain, Digital
// P0.2 - SCK (SPI0), Push-Pull, Digital
// P0.3 - MISO (SPI0), Open-Drain, Digital
// P0.4 - MOSI (SPI0), Push-Pull, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Push-Pull, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Open-Drain, Digital
// P3.5 - Unassigned, Open-Drain, Digital
// P3.6 - Unassigned, Open-Drain, Digital
// P3.7 - Unassigned, Open-Drain, Digital
SFRPAGE = CONFIG_PAGE;
P0MDOUT = 0x15;
P2MDOUT = 0x08;
XBR0 = 0x06;
XBR2 = 0x40;
}
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
OSCICN = 0x00;
}
void Interrupts_Init()
{
IE = 0x91;
IP = 0xC1;
EIE2 = 0x01;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
Timer_Init();
UART_Init();
SPI_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}