-
Notifications
You must be signed in to change notification settings - Fork 1
/
motor.c
161 lines (137 loc) · 3.89 KB
/
motor.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
#define EXTIO_SCAN_ASCII (*(volatile unsigned int *)0x0310)
#define EXTIO_SCAN_REQ (*(volatile unsigned int *)0x030c)
#define EXTIO_SCAN_STROKE (*(volatile unsigned int *)0x0308)
#define SCAN_STRORING (unsigned int)0xffffffff
#define EXTIO_PRINT_STROKE (*(volatile unsigned int *) 0x0300)
#define EXTIO_PRINT_ASCII (*(volatile unsigned int *) 0x0304)
#define TRUE 0x1
#define FALSE 0x0
#define GPIO0 (*(volatile unsigned int *) 0x0320)
void my_motor();
void my_motor_re();
void ext_out();
void my_scan();
void my_print();
main() {
unsigned int command[16];
unsigned int input_str[16];
input_str[0] = 'N'; input_str[1] = 'E';
input_str[2] = 'X'; input_str[3] = 'T';
input_str[4] = '='; input_str[5] = '\0';
my_print(input_str);
my_scan(command);
if (command[0] == 'R') {
while(TRUE){
my_motor_re();
}
}
while(TRUE){
my_motor();
}
}
void my_motor() {
ext_out(8);
ext_out(4);
ext_out(2);
ext_out(1);
}
void my_motor_re() {
ext_out(1);
ext_out(2);
ext_out(4);
ext_out(8);
}
void ext_out(unsigned int num) {
unsigned int i;
GPIO0 = num;
}
/* キーボードから入力された文字列を str[] に記憶する関数 */
void my_scan(str)
unsigned int *str;
{
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_REQ = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
while (EXTIO_SCAN_ASCII == SCAN_STRORING) {
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
}
while ((*str = EXTIO_SCAN_ASCII) != (unsigned int)0x3e) { // 0x3e=RETURN
if ((*str >= 1) && (*str <= 26)) {
*str = 'A' + *str - 1;
} else if ((*str >= 48) && (*str <= 57)) {
*str = '0' + *str - 48;
} else {
if (*str == 0) {
*str = '@';
} else if (*str == 27) {
*str = '[';
} else if (*str == 29) {
*str = ']';
} else if ((*str >= 32) && (*str <= 47)) {
*str = ' ' + *str - 32;
} else if (*str == 58) {
*str = '?';
} else if (*str == 59) {
*str = '=';
} else if (*str == 60) {
*str = ';';
} else if (*str == 61) {
*str = ':';
} else if (*str == 62) {
*str = '\n';
} else {
*str = '@';
}
}
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
str++;
}
*str = '\0';
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_REQ = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
}
/* 文字列 str[] を表示する関数 */
void my_print(str)
unsigned int *str;
{
while (*str != '\0') {
EXTIO_PRINT_STROKE = (unsigned int)0x00000000;
if ((*str >= 'A') && (*str <= 'Z')) {
EXTIO_PRINT_ASCII = *str - 'A' + 1;
} else if ((*str >= 'a') && (*str <= 'z')) {
EXTIO_PRINT_ASCII = *str - 'a' + 1;
} else if ((*str >= '0') && (*str <= '9')) {
EXTIO_PRINT_ASCII = *str - '0' + 48;
} else {
if (*str == '@') {
EXTIO_PRINT_ASCII = (unsigned int)0;
} else if (*str == '[') {
EXTIO_PRINT_ASCII = (unsigned int)27;
} else if (*str == ']') {
EXTIO_PRINT_ASCII = (unsigned int)29;
} else if ((*str >= ' ') && (*str <= '/')) {
EXTIO_PRINT_ASCII = *str - ' ' + 32;
} else if (*str == '?') {
EXTIO_PRINT_ASCII = (unsigned int)58;
} else if (*str == '=') {
EXTIO_PRINT_ASCII = (unsigned int)59;
} else if (*str == ';') {
EXTIO_PRINT_ASCII = (unsigned int)60;
} else if (*str == ':') {
EXTIO_PRINT_ASCII = (unsigned int)61;
} else if (*str == '\n') {
EXTIO_PRINT_ASCII = (unsigned int)62;
} else {
EXTIO_PRINT_ASCII = (unsigned int)0x00000000;
}
}
EXTIO_PRINT_STROKE = (unsigned int)0x00000001;
str++;
}
}