-
Notifications
You must be signed in to change notification settings - Fork 0
/
oldMAIN.c
460 lines (431 loc) · 10.6 KB
/
oldMAIN.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/* Blinky.C - LED Fla+-
sher for the Keil LPC900 EPM Emulator/Programmer Module */
#include <REG936.H> // register definition
#include <LIMITS.H>
#include <INTRINS.H>
#include <STDIO.H>
#include <CTYPE.H>
#include "LUTFreq.h"
#include "LUTsin.h"
#include "ITRIP.H"
//#include "test/adc.h"
/******************************* GLOBALS**************************************/
////#define JUST_BUTT
//#define BUT_DEL
//
//enum {
// UP_SWEEP,
// UP_SLOW_POLY,
// UP_SLOW_EVEN,
// UP_SYNC,
// UP_DOWN,
// UP_ALL_TOGETHER,
// UP_OFF_BEAT_DELAY,
// TONES_TWO_STEP,
// TONES_THREE_STEP,
// TONES_WIDE
//};
//#define MIN_STATE TONES_TWO_STEP
////#define MIN_STATE UP_SWEEP
//#define MAX_STATE TONES_WIDE
#define SPEED_DIV 1
#define FREQ_MIN 911
#define NUM_TRANS 12
//#define CENTER_FREQ (FREQ_MIN + NUM_TRANS/2)
#define FREQ_MAX 1011//(FREQ_MIN+SPEED_DIV) //high speed = lots of freqs
#define TUNE_IT 1333 //pumped into delay... UINT16_MAX ~1.5 HZ
#define TEMPO 16660
#define TEMPO_CNT (TEMPO/(TUNE_IT/SPEED_DIV))
#define FOUR_SECS 224
//REMEMBER!!! these are up timers... period = 0x0 - values...
//tempo
volatile byte periodH0 = 0;
volatile byte periodL0 = 0; //maybe 56Hz
volatile byte count0 = FOUR_SECS; //56; //maybe 1 HZ, damn close...
//pitch
volatile byte periodH1 = 0; //(0xff & (LUTFreq[0] >> 8));
volatile byte periodL1 = 0; //(LUTFreq[0] & 0xff);
volatile byte LUTDex = 0;
/****************************BH141* instruction*******************************/
//volatile byte adcFlag = 0;
//volatile byte adcVal[2];
volatile word bdata txState;
sbit stereo = txState^3;
sbit phaseMode0 = txState^4;
sbit phaseMode1 = txState^5;
sbit test0 = txState^6;
sbit test1 = txState^7;
/***********************************8MAIN????????????????????????*****************/
void main() {
/**************LOCALS****************************/
unsigned long tempoCnt = TEMPO_CNT;
word station = FREQ_MIN;
byte tempoFlag = 1;
byte atom = 10;
byte width = 1;
byte offTime = 255;
byte cnt = 0;
byte i = 0;
byte state = 0;
byte enableLED = 1;
/**************SETUP++***************************************/
setup();
setFreq(station);
TR1 = 1;
TR0 = 1;
/****************LOOP*****************************************/
for(;;) {
//delay(UINT_MAX);
//periodL1--;
// if (tempoCnt-- == 0) {
// tempoCnt = TEMPO_CNT;
// if(tempoFlag++ > 4) {
// tempoFlag = 1;
// }
// }
// delay(1000);
// //delay(tempoFlag*(TUNE_IT/SPEED_DIV));
// if (station++ >= MAX_FREQ) {
// station = MIN_FREQ;
// }
// setFreq(station);
// delay(tempoFlag*(TUNE_IT/SPEED_DIV));
// setFreq(912);
//#ifdef JUST_BUTT
// delay(UINT_MAX);
// if (midButt == 0) {
// LED ^= 1;
// txVcc ^= 1;
// //LEDout ^= 1;
// }
// delay(UINT_MAX);
// if (LED) {
// if (hiButt == 0) {
// LED = 0;
// delay(UINT_MAX);
// station++;
// setFreq(station);
// LED = 1;
// delay(UINT_MAX);
// }
// else if (loButt == 0) {
// LED = 0;
// delay(UINT_MAX);
// --station;
// setFreq(station);
// LED = 1;
// delay(UINT_MAX);
// }
//
// if (station < MIN_FREQ) {
// station = 700;
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// }
// if (station > MAX_FREQ) {
// station = 1080;
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// LED = 0;
// delay(UINT_MAX);
// LED = 1;
// delay(UINT_MAX);
// }
// }
//#else
//// adc_startadc1conversion(ADC_IMMEDIATE, ADC_FIXEDSINGLE, ADC1_CHANNEL2);
//// cnt = atom;
//// while(cnt--) {
//// delay(atom);
//// }
//// adc_startadc1conversion(ADC_IMMEDIATE, ADC_FIXEDSINGLE, ADC1_CHANNEL2);
//// cnt = atom;
//// if (adcFlag == 1) {
////// for (width = 0; (width < adcVal[1]); width++) {
////// LEDout = 0;
////// cnt = (255 - width);
////// while (cnt--) {
////// delay(atom);
////// }
////// LEDout = 1;
////// cnt = width;
////// while (cnt--) {
////// delay(atom);
////// }
////// width += 3;
////// }
////// offTime = 0;
//// for (width = adcVal[1]; width > 0; width--) {
//// LEDout = 0;
//// cnt = offTime++;
//// while (cnt--) {
//// delay(atom);
//// }
//// LEDout = 1;
//// cnt = width;
//// while (cnt--) {
//// delay(atom);
//// }
//// }
//// adcFlag = 0;
//// LEDout = 0;
//// }
// if (hiButt == 0) {
// state++;
// delay(UINT_MAX);
//#ifndef BUT_DEL
// } else if (midButt == 0) {
// txVcc = 1;
// enableLED ^= 1;
// if (LED) LED = 0;
// delay(UINT_MAX);
//#endif
// } else if (loButt == 0) {
// state--;
// delay(UINT_MAX);
// }
// if (state > MAX_STATE) {
// state = MIN_STATE;
// }
// switch (state) {
// case UP_SWEEP :
// if (enableLED == 1) {
// delay(UINT_MAX/SPEED_DIV);
// setFreq(station++);
// if (enableLED == 1) LED ^= 1;
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
//
// case UP_SLOW_POLY:
// if (enableLED == 1) {
// for (i = 0; i < SPEED_DIV; i++) {
// delay(UINT_MAX/2 + (UINT_MAX/NUM_TRANS * SPEED_DIV/2));
// }
// LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
//
// case UP_SLOW_EVEN:
// if (enableLED == 1) {
// for (i = 0; i < SPEED_DIV; i++) {
// delay(UINT_MAX);
// }
// if (enableLED == 1) LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
//
// case UP_OFF_BEAT_DELAY:
// if (enableLED == 1) {
// delay(UINT_MAX);
// LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// delay(UINT_MAX);
// delay((UINT_MAX/2/NUM_TRANS) * SPEED_DIV/2);
// LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// delay(UINT_MAX - ((UINT_MAX/2/NUM_TRANS) * SPEED_DIV/2));
// LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
//
// case UP_DOWN:
// if (enableLED == 1) {
// delay(UINT_MAX);
// LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// delay(UINT_MAX);
// LED ^= 1;
// setFreq(station--);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
// case UP_ALL_TOGETHER:
// if (enableLED == 1) {
// for (i = 0; i < SPEED_DIV; i++) {
// delay(UINT_MAX);
// }
// if (enableLED == 1) LED ^= 1;
// setFreq(station++);
// if (station > FREQ_MAX)
// station = FREQ_MIN;
// }
// break;
// case TONES_TWO_STEP:
// if (enableLED == 1) {
// delay(TUNE_IT/SPEED_DIV);
// if (enableLED == 1) LED ^= 1;
// setFreq(station++);
// if (station > (FREQ_MIN+1))
// station = FREQ_MIN;
// }
// break;
// case TONES_THREE_STEP:
// if (enableLED == 1) {
// delay(TUNE_IT/SPEED_DIV);
// if (enableLED == 1) LED ^= 1;
// setFreq(station++);
// if (station > (FREQ_MIN+1))
// station = FREQ_MIN-1;
// }
// break;
// case TONES_WIDE:
// if (enableLED == 1) {
// delay(TUNE_IT/SPEED_DIV);
// if (enableLED == 1) LED ^= 1;
// setFreq(station++);
// if (station > (FREQ_MAX - NUM_TRANS/2))
// station = FREQ_MIN-NUM_TRANS/2;
// }
// break;
// }
//#endif
}
}
/*******************SETUP FUNCTION*********************/
void setup() {
P0M1 = 0x13; //input for buttons and audioN, push pull for audioL
P0M2 = 0x08;
P1M1 = 0; //quasi-bidirectional pins or inputs
P2M1 = 0;
P3M1 = 0;
midButt = 1; //pull up resistors on the button inputs
hiButt = 1;
loButt = 1;
LED = 1; //LED on
txVcc = 1; //transmitter off
CE = 0; //serial input inable for transmitter
stereo = 0;
audioL = 0;
test0 = 1; //always
test1 = 0; //always
phaseMode0 = 0; //?
phaseMode1 = 0; //?
// configure timers
TMOD &= 0x00; //clear conf for timers
TAMOD &= 0xEE; //clear conf for timers
TMOD |= 0x11; //16bit mode for both
//TAMOD |= 0x10;
periodH1 = (0xff & (LUTFreq[0] >> 8));
periodL1 = (LUTFreq[0] & 0xff);
// timer values
TH0 = periodH0;
TL0 = periodL0;
TH1 = periodH1;
TL1 = periodL1;
//timer 0 interrupt is higher than timer 1 thus timer 0 is tempo and t1 is pitch
// set timer 1 isr priority to 2
IP0 &= 0xF7;
IP0H &= 0xFF;
// // enable timer 1 interrupt
ET1 = 1;
ET0 = 1;
// start timers
//TR1 = 1;
//TR0 = 1;
// LEDout = 0;
//adc_init();
}
/*********************TIMER interrupts****************************/
void timers_isr1 (void) interrupt 3 using 2
{
TH1 = periodH1;
TL1 = periodL1;
audioL ^= 1;
//LED ^= 1;
}
void timers_isr0 (void) interrupt 1 using 3
{
TH0 = 0x80;//periodH0;
TL0 = 0;//periodL0;
if(count0-- == 0) {
count0 = 3;//FOUR_SECS;
if (LUTDex++ >= LUT_LEN) {
LUTDex = 0;
}
periodH1 = (0xff & (LUTFreq[LUTDex] >> 8));
periodL1 = (0xff & LUTFreq[LUTDex]);
//TR1 ^= 1;
LED ^= 1;
// if (LED == 0) {
// setFreq(912);
// } else setFreq(911);
//audioL ^= 1;
}
}
/*****************TEST SETUP***************************************/
/********************SETTERS****************************/
void setFreq (word freq) { //takes
if (freq > MAX_FREQ || freq < MIN_FREQ) return; //out of bounds, do-over
else {
word temp = freq;
EA = 0; //Disable interrupts for tuning
temp += (txState & 0xF800); //keep phase cntrl, channels, and test bits
txState = temp; //return or sorts
txProg();
EA = 1; //resume interrupt service
}
}
/*********************8CEREAL***************************/
void txProg() { //shift out txState to the transmitter
word i = 0x01;
EA = 0;
txVcc = 0; // TX on
txClk = 0;
CE = 0;
CE = 1;
for(i = 0x01; i != 0; i <<= 1) {
txData = txState & i;
txClk = 1;
txClk = 0;
}
CE = 0;
EA = 1;
}
void delay (word cnt) { //2.17 us * cnt
while (--cnt);
#ifdef BUT_DEL
if(midButt == 0) {}
#endif
}