-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.txt
220 lines (177 loc) · 4.01 KB
/
code.txt
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/***********************************************************************************
FILE NAME : main.c
DESCRIPTION : Empty proejct set up for RSKM16C62P
Copyright : 2005 Renesas Technology Europe Ltd.
Copyright : 2005 Renesas Technology Corporation.
All Rights Reserved
***********************************************************************************/
/***********************************************************************************
Revision History
DD.MM.YYYY OSO-UID Description
21.01.2006 RTA-MGF First Release
***********************************************************************************/
/**********************************************************************************
System Includes
***********************************************************************************/
/**********************************************************************************
User Includes
***********************************************************************************/
#include "sfr62p.h"
/* rskM16C62p_def.h defines some common definitions */
#include "rskM16C62Pdef.h"
#include "main.h"
#include "lcd.h"
#include "stdlib.h"
#pragma INTERRUPT timer_a0
#pragma INTERRUPT sw1
#pragma INTERRUPT sw2
#pragma INTERRUPT sw3
//Global variables
//***********************************************************************************/
int toggle = 5;
int i;
int ball_pos = 1;
int count = 1;
int direction = 0; // 0 - to right; 1 - to left
int sw1_pos = 0; // 0 - up ; 1 - down
int sw2_pos = 0; // 0 - up ; 1 - down
char str_line1[8];
char str_line2[8];
char ball = 'o';
long int delay_val = 200000;
//User Program Code
//***********************************************************************************/
void update_display(void)
{
if(sw2_pos == 0)
{
str_line1[0] = '|';
str_line2[0] = ' ';
} else
{
str_line1[0] = ' ';
str_line2[0] = '|';
}
for(i = 1; i < 7; i++)
{
if(i == ball_pos) str_line1[i] = ball;
else str_line1[i] = ' ';
str_line2[i] = ' ';
}
if(sw1_pos == 0)
{
str_line1[7] = '|';
str_line2[7] = ' ';
} else
{
str_line1[7] = ' ';
str_line2[7] = '|';
}
DisplayString(LCD_LINE1, str_line1);
DisplayString(LCD_LINE2, str_line2);
}
void timer_a0(void)
{
update_display();
if(++count == 100)
{
count = 1;
if(direction == 0)
{
ball_pos++;
if(ball_pos == 6) direction = 1;
}
else
{
ball_pos--;
if(ball_pos == 1) direction = 0;
}
}
}
void delay(void) {
long int j;
for(j = 0; j < delay_val; j++) {}
}
void delay_to_bounce(void) {
long int j;
for(j = 0; j < 200000; j++) {}
}
void rotate_left(void)
{// this is only for the part1
int i;
for( i = 0; i < 4; ++i)
{
if (toggle == 0) toggle = 1;
p4 |= 0x0F;
p4 &= ~( 1 << i );
delay();
}
delay_to_bounce();
if (toggle == 1)
{
p4_0 = 0;
p4_1 = 0;
p4_2 = 0;
p4_3 = 0;
toggle = 5;
}
}
void rotate_right(void)
{// this is only for the part1
for(i = 3; i >= 0; --i)
{
if (toggle == 1) toggle = 0;
p4 |= 0x0F;
p4 &= ~( 1 << i );
delay();
}
delay_to_bounce();
if (toggle == 0)
{
p4_0 = 0;
p4_1 = 0;
p4_2 = 0;
p4_3 = 0;
toggle = 5;
}
}
void sw1(void)
{
toggle = 1;
if(++sw1_pos == 2) sw1_pos = 0;
}
void sw2 (void)
{
toggle = 0;
if(++sw2_pos == 2) sw2_pos = 0;
}
void sw3(void)
{
delay_val -= 10000;
if (delay_val <= 0) delay_val = 200000;
}
void part1(void) {
if (toggle == 5) return;
if (toggle)
rotate_left();
else
rotate_right();
}
void part2(void) {
InitialiseDisplay();
asm ( "FSET I" ); /* enable interrupts */
ta0mr = 0b01000000; /* f8 = 3MHz */
ta0 = 29999; /* 10 * 10^(-3) * 3 * 10^(6) -1 meaning 10ms @3MHz */
ta0ic = 0x04; /* interrupt priority level 1 (first non-zero lowest lvl) */
ta0s = 1;
int0ic = 0x01;
int1ic = 0x01;
int2ic = 0x01;
}
void main(void)
{
part2();
while(1) {
part1();
}
}