-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
172 lines (154 loc) · 2.54 KB
/
main.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Circle LED (12LED for LPC1114FN28 DIP)
// License: CC BY http://fukuno.jig.jp/
// Hardware & Description http://fukuno.jig.jp/790
#include "LPC1100.h"
#include "uart.h"
#include "xprintf.h"
#include "util.h"
/*
12LED
http://www.aitendo.com/product/6524
PIO0_8 x
PIO0_9 x
PIO0_10 x
PIO0_11 D1
PIO0_5 x
PIO0_6 D3
VDDA
VSSA
PIO1_0 D12
PIO1_1 D10
PIO1_2 D8
PIO1_3 D6
PIO1_4 D4
PIO1_5 D2
PIO0_7 x
PIO0_4 x
PIO0_3 D9
PIO0_2 D11
ISP
RESET
VSS
VDD
XTALIN
XTALOUT
PIO1_9 D7
PIO1_8 D5
TXD
RXD
*/
void init() {
IOCON_PIO0_3 = 0xd0;
GPIO0DIR |= 1 << 3;
IOCON_PIO0_2 = 0xd0;
GPIO0DIR |= 1 << 2;
IOCON_PIO1_9 = 0xd0;
GPIO1DIR |= 1 << 9;
IOCON_PIO1_8 = 0xd0;
GPIO1DIR |= 1 << 8;
IOCON_R_PIO0_11 = 0xd1;
GPIO0DIR |= 1 << 11;
IOCON_PIO0_6 = 0xd0;
GPIO0DIR |= 1 << 6;
IOCON_R_PIO1_0 = 0xd1;
GPIO1DIR |= 1 << 0;
IOCON_R_PIO1_1 = 0xd1;
GPIO1DIR |= 1 << 1;
IOCON_R_PIO1_2 = 0xd1;
GPIO1DIR |= 1 << 2;
IOCON_SWDIO_PIO1_3 = 0xd1;
GPIO1DIR |= 1 << 3;
IOCON_PIO1_4 = 0xd0; // 使わないほうがよかったかも
GPIO1DIR |= 1 << 4;
IOCON_PIO1_5 = 0xd0;
GPIO1DIR |= 1 << 5;
}
void circleled_on(int n) {
/*
PIO0_11 D1
PIO1_5 D2
PIO0_6 D3
PIO1_4 D4
PIO1_8 D5
PIO1_3 D6
PIO1_9 D7
PIO1_2 D8
PIO0_3 D9
PIO1_1 D10
PIO0_2 D11
PIO1_0 D12
*/
int pos[] = { 11, 105, 6, 104, 108, 103, 109, 102, 3, 101, 2, 100 };
int set0 = 0;
int set1 = 0;
for (int i = 0; i < 12; i++) {
if (n & (1 << i)) {
int m = pos[i];
if (m < 100) {
set0 |= 1 << m;
} else {
set1 |= 1 << (m - 100);
}
}
}
/*
PIO0_2 D11
PIO0_3 D9
PIO0_6 D3
PIO0_11 D1
PIO1_0 D12
PIO1_1 D10
PIO1_2 D8
PIO1_3 D6
PIO1_4 D4
PIO1_5 D2
PIO1_8 D5
PIO1_9 D7
*/
GPIO0MASKED[0b100001001100] = set0;
GPIO1MASKED[0b001100111111] = set1;
}
// uart
void uart() {
#define SIZE_BUF 128
char buf[SIZE_BUF];
int nbuf = 0;
for (int i = 0;; i++) {
while (uart0_test()) {
int c = uart0_getc();
if (c == '\n') {
buf[nbuf] = '\0';
if (startsWith(buf, "'CLED ")) {
int n = parseInt(buf + 9);
circleled_on(n);
}
nbuf = 0;
continue;
} else if (c == '\r') {
} else {
if (nbuf < SIZE_BUF - 1)
buf[nbuf++] = c;
}
}
}
}
void test() {
for (int i = 0;; i++) {
for (int j = 0; j < 12; j++) {
circleled_on(1 << j);
wait(10);
if (uart0_test()) {
return;
}
}
}
}
int main() {
InitSysTick(200);
init();
circleled_on(0);
uart_init();
test();
uart();
return 0;
}