-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalProject_226.c
1425 lines (1184 loc) · 42.9 KB
/
finalProject_226.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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Control of the intersection model **/
#include "driverlib.h" //Libraries used in program
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h> //Used for debugging
#include <stdlib.h> //Used for debugging
#include <string.h> //Used for debugging
#include "msp.h"
//INITIALIZATION FUNCTIONS
void initializeAll(); // Function used to initialize all components
void timer32_init(); // Initializes instance 1 and instance two of timer32
void trafficLightPin_Init(); // Initialize the traffic light and cross walk pins
void timerA_init(); // Initialize timerA0.1 (Servo) and timerA0.2 (Sounder)
void lcdDisplay_init(); // Initializes the LCD
void SysTick_Init(); // Initializes the systick timer used for basic delays
void lcdPin_Init(); // Initializes the LCD pins
void servoPin_init(); // Initializes the Servo pin 6.7 TimerA0.1 for PWM
void stepperPin_Init(); // Initializes the stepper motor pins GPIO
void buzzer_init(); // Initializes P2.5 to use for the sounder
void gpioHandler_Init(); // Initializes port 1, used for the cross walk GPIO interupts
//LCD CURSOR / SCREEN MANIPULATION FUNCTIONS
void nextLine(); // Pass 0xC0 as an instruction to go to next line
void cursorToHome(); // Pass 0x01 instruction send cursor home position
void clearScreen(); // Will clear the screen of the LCD
//LCD DATA PASSING FUNCTIONS
void instructionWrite(uint8_t command); // Assigns the RS to 0
void dataWrite(uint8_t data); // Assigns the RS value to 1
void PulseEnablePin(); // Used to initiate the transaction of bits to LCD
void pushNibble(uint8_t nibble); // Passes four bits at a time to the LCD
void pushByte(uint8_t byte); // Masks appropriate bits and sends to pushNibble()
//TRAFFIC LIGHT FUNCTIONS
void ns_toggleYellowLED(); // Toggle the yellow LED for NS traffic
void ew_toggleYellowLED(); // Toggle the yellow LED for EW traffic
void checkNS_crossWalk(); // Checks the cross walk flags
void checkEW_crossWalk(); // Checks the cross walk flags
void NS_crosswalkFlash(); // Does the toggle act (manipulates the pin output
void EW_crosswalkFlash(); // Does the toggle act (manipulates the pin output
//BUZER FUNCTIONS
void buzzerTone1(); // Sets a low tone for sounder (cross walk is green)
void buzzerTone2(); // Sets a medium tone for the sounder
void buzzerTone3(); // Sets a high tone for the sounder
void buzzOff(); // Sets the sounder to off (cross walk is off)
void fridgeTone(); // Fun tone sounds when the program starts
//SYSTIC TIMER FUNCTIONS
void delay_ms(unsigned ms); // Uses the clock cycle period to determine milli
void delay_micro(unsigned microsec); // Uses the clock cycle period to determine micros
//HANDLERS
void T32_INT1_IRQHandler(void); // Instance 1 of timer32 interupt handler used to track the durration of each light which is then set to the LCD to update
void T32_INT2_IRQHandler(void); // Instance 2 of timer32 interrupt handler increments the flags which control the change of states
void TA0_N_IRQHandler (void); // Timer A0 Used to capture the incomming IR signal
void PORT1_IRQHandler(void);
void PORT2_IRQHandler(void);//Handler used to control the angle of the LCD; button presses
void PORT4_IRQHandler(void);
void PORT5_IRQHandler(void);
//STEPPER FUNCTIONS
void directionUp(); // Stepper motor
void directionDown(); // Stepper motor
//STATE FUNCTIONS
void state1(); // Sets NS Straight lights to green / NS left flashing yellow
void state2(); // Sets NS Straight lights to yellow / NS left flashing yellow
void state3(); // Sets NS Straight lights to red / Continues to flash NS left yellows
void state4(); // Sets NS Left green
void state5(); // Sets NS Left lights to yellow
void state6(); // Sets NS Left lights to red / ALL LIGHTS RED
void state7(); // Sets EW Straight lights to green / EW left flashing yellow
void state8(); // Sets EW Straight to green / EW left flashing yellow
void state9(); // Sets EW Straight to red / EW left green
void state10(); // Sets EW Left to yellow
void state11(); // Sets EW Left to red
void state12(); // Sets All lights red for 2 seconds
//LCD DISPLAY FUNCTIONS
void displayTopLine(char* topLine); // Used to pass strings to display on the top line of the LCD
void displayBottomLine(char* bottomLine); // Used to pass strings to the bottom line of the LCD
void tocks_displayTopLine(char* topLine); // Used to pass the counter variable tocks to display the current length the light has been in state
void tocks_displayBottomLine(char* bottomLine); // Used to pass the counter vairable tocks to the bottom position of the LCD display
//LCD DISPLAY LINES
char ns[] = "N/S ";
char ew[] = "E/W ";
char s1[] = "S. green ";
char s2[] = "S. yellow";
char s3[] = "S. red ";
char s4[] = "L. green ";
char s5[] = "L. yellow";
char s6[] = "L. red ";
char s7[] = "S. green ";
char s8[] = "S. yellow";
char s9[] = "S. red ";
char s10[] = "L. green ";
char s11[] = "L. yellow";
char s12[] = "L. red ";
uint8_t nsBuzzerFlag = 0;
uint8_t ewBuzzerFlag =0;
uint8_t buzzFlag = 0;
uint8_t dFlag = 0, checkFlagy = 0; // Ensures the dislpay is only updated once per state to save time
uint8_t nsTocks = 0; //Used to control the count of the NS
uint8_t ewTocks = 0; //Used to control the count of EW lights
uint32_t flagRavel = 1175;
uint8_t safetyFlag = 0;
void checkPole();
uint32_t toggle = 0;
uint32_t NS_toggleDurringGreen = 20;
uint32_t EW_toggleDurringGreen = 40;
float toggleDurringYellow = 10;
float toggleDurringRed = 2.5;
uint8_t state = 1;
uint32_t i = 0;
uint8_t NS_crosswalk = 0;
uint8_t EW_crosswalk = 0;
uint32_t servoPos = 1900;
uint32_t period = 60000;
uint32_t dCycle = 1900;
uint8_t stepperSpeed = 3;
uint8_t ticks = 0;
uint32_t on_off = 200; // 200 * 2 is a single cycle of ms for the flashing yellow
static uint16_t capturedCyclesCurrent;
static uint16_t capturedCyclesPast = 0;
uint16_t capturedPeriod;
int main(void){
initializeAll();
delay_micro(100);
displayTopLine(ns);
delay_micro(100);
nextLine();
delay_micro(100);
displayBottomLine(ew);
fridgeTone();
directionUp();
//directionDown();
while (1){
switch(state){
case 1:
state1(); // Straight N.S. green
break;
case 2:
state2(); // Straight N.S. yellow
break;
case 3:
state3(); // Straight N.S. red
break; // Smooth transition from straght red to left green
case 4:
state4(); // N.S. left green
break;
case 5:
state5(); // N.S. left yellow
break;
case 6:
state6(); // N.S. left red / ALL LIGHTS RED
break;
case 7:
state7(); // E.W. straight green
break;
case 8:
state8(); // E.W. straight yellow
break;
case 9:
state9(); // E.W. straight red
break;
case 10:
state10(); // E.W. left green
break;
case 11:
state11(); // E.W. left yellow
break;
case 12:
state12(); // E.W. left red // ALL LIGHTS RED
break;
}
}
}
void checkPole(){
if(safetyFlag == 1){
safetyFlag = 0;
P3->OUT |= 0X88; // E.W. Red
P6->OUT |= 0X90; // N.S. Left has red // ALL LIGHTS ARE RED
directionDown();
P3->OUT &=~ 0X88; // E.W. Red
P6->OUT &=~ 0X90; // N.S. Left has red // ALL LIGHTS ARE RED
state = 1;
}
if(safetyFlag == 2){
safetyFlag = 0;
P3->OUT |= 0X88; // E.W. Red
P6->OUT |= 0X90; // N.S. Left has red // ALL LIGHTS ARE RED
directionUp();
P3->OUT &=~ 0X88; // E.W. Red
P6->OUT &=~ 0X90; // N.S. Left has red // ALL LIGHTS ARE RED
state = 1;
}
}
void TA0_N_IRQHandler( void ) {
MAP_Timer_A_clearCaptureCompareInterrupt (TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_3);
capturedCyclesCurrent = MAP_Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_3);
if (capturedCyclesCurrent > capturedCyclesPast){
capturedPeriod = (capturedCyclesCurrent - capturedCyclesPast);
}
else{
capturedPeriod = 65535 - (capturedCyclesPast + capturedCyclesCurrent);
}
if ((35635 < capturedPeriod) && (capturedPeriod < 39375) ){ // within 5% of 10Hz period detect10Hz=1;
P2->OUT |= BIT5;
}
if ((25446 < capturedPeriod ) && (capturedPeriod < 28055) ){ // within 5% of 14Hz period detect14Hz=1;
state = 1;
}
capturedCyclesPast = capturedCyclesCurrent ; // save for next interrupt
}
//STATES
void state1(){
checkPole();
if(dFlag == 0){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s1);
delay_micro(37);
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s9);
delay_micro(37);
dFlag = 1; // Used to toggle the specific display for the state of the lights
}
nsTocks = 0;
ewTocks = 0;
P7->OUT |= BIT4; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT5; // Crosswalk off for safety
P7->OUT |= BIT6; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT7; // Crosswalk off for safety
P6->OUT &=~ 0X90; // Turn NS red off from state 12
P6->OUT |= 0X41; // N.S. Straight has green
P3->OUT |= 0X88; // E.W. Red
toggle = NS_toggleDurringGreen; // Set the durration of the flashing yellow
ns_toggleYellowLED();
state++; // Increment the state
}
void state2(){
//checkPole();
if(dFlag == 1){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s2);
dFlag = 0;
}
nsTocks = 0;
P6->OUT &=~ 0X41; // N.S. green off
P6->OUT |= 0X42; // N.S. Straight has yellow
if(NS_crosswalk == 2){
NS_crosswalk = 3;
}
toggle = toggleDurringYellow; // Set the durration of the flashing yellow lights
ns_toggleYellowLED();
state++; // Increment the state
ticks = 0;
}
void state3(){
//checkPole();
if(dFlag == 0){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s3);
dFlag = 1;
}
nsTocks = 0;
P6->OUT &=~ 0X42; // N.S. straight yellow off
P6->OUT |= 0X50; // N.S. Straight has red
if(NS_crosswalk == 3){
P7->OUT |= BIT6;
NS_crosswalk = 0;
}
if(nsBuzzerFlag > 10){
buzzerTone3();
nsBuzzerFlag = 0;
}
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
void state4(){
//checkPole();
if(dFlag == 1){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s4);
dFlag = 0;
}
nsTocks = 0;
P6->OUT &=~ 0X50; // N.S. Straight has red
P6->OUT |= 0X30; // N.S. Left has green
if(ticks == 5){ // Hold N.S. left green
state++;
ticks = 0; // Reset the counter ticks
}
}
void state5(){
//checkPole();
if(dFlag == 0){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s5);
dFlag = 1;
}
nsTocks = 0;
P6->OUT &=~ 0X30; // Turn off
P6->OUT |= 0X50; // N.S. Left has yellow
if(NS_crosswalk == 3){
NS_crosswalk = 0;
}
if(ticks == 3){ // Hold N.S. left yellow for 3 seconds
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
}
void state6(){
if(dFlag == 1){
instructionWrite(0x84);
delay_micro(37);
displayTopLine(s6);
dFlag = 0;
}
nsTocks = 0;
P7->OUT |= BIT4; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT5; // Crosswalk off for safety
P7->OUT |= BIT6; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT7; // Crosswalk off for safety
buzzOff(); // Turn off crosswalk buzzer
//nsBuzzerFlag = 0;
checkPole();
P6->OUT &=~ 0X50;
P6->OUT |= 0X90; // N.S. Left has red // ALL LIGHTS ARE RED
if(ticks == 2){ // Hold all lights red for 2 seconds
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
}
void state7(){
//checkPole();
if(dFlag == 0){
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s7);
dFlag = 1;
}
ewTocks = 0;
P3->OUT &=~ 0X88; // E.W. Red off
P3->OUT |= 0x41; // E.W. Straight has green
P5->OUT &=~ BIT1; // Turns off cross walk for safety
toggle = EW_toggleDurringGreen; // Set the durration of the flashing yellow lights
ew_toggleYellowLED(); // Flash the yellow lights
ticks = 0; // Reset the counter ticks
state++; //
}
void state8(){
// checkPole();
if(dFlag == 1){
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s8);
dFlag = 0;
}
ewTocks = 0;
P3->OUT &=~ 0X41; // E.W. straight green off
P3->OUT |= 0X44; // E.W. Straight has yellow
if(EW_crosswalk == 2){
EW_crosswalk = 3;
}
toggle = toggleDurringYellow; // Set the durration of the flashing yellow lights
ew_toggleYellowLED();
state++; // Increment the state
ticks = 0; // Reset the counter ticks
}
void state9(){
//checkPole();
if(dFlag == 0){
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s9);
dFlag = 1;
}
ewTocks = 0;
P3->OUT &=~ 0X44; // E.W. Straight yellow off
P3->OUT |= 0X48; // E.W. Straight has red
if(EW_crosswalk == 3){
P7->OUT |= BIT4;
EW_crosswalk = 0;
}
if(ewBuzzerFlag > 10){
buzzerTone3();
ewBuzzerFlag = 0;
}
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
void state10(){
//checkPole();
if(dFlag == 1){
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s10);
dFlag = 0;
}
ewTocks = 0;
P3->OUT &=~ 0X48; // E.W. Straight red off
P3->OUT |= 0X28; // E.W. Left has green
if(ticks == 5){ // Hold E.W. left green
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
}
void state11(){
//checkPole();
if(dFlag == 0){
instructionWrite(0xC4);
delay_micro(37);
displayBottomLine(s11);
dFlag = 1;
}
ewTocks = 0;
P3->OUT &=~ 0X28; // E.W. Left green off
P3->OUT |= 0X48; // E.W. Left has yellow
if(EW_crosswalk == 3){
EW_crosswalk = 0;
}
if(ticks == 3){ // Hold E.W. left green for 3 seconds
state++; // Increment state
ticks = 0; // Reset the counter ticks
}
}
void state12(){
checkPole();
if(dFlag == 1){
instructionWrite(0xC5);
delay_micro(37);
displayBottomLine(s12);
dFlag = 0;
}
ewTocks = 0;
P7->OUT |= BIT4; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT5; // Crosswalk off for safety
P7->OUT |= BIT6; // EW GREEN Crosswalk off for safety
P7->OUT &=~ BIT7; // Crosswalk off for safety
buzzOff(); // Turn off crosswalk buzzer
// ewBuzzerFlag = 0;
checkPole();
P3->OUT &=~ 0X48; // E.W. Left yellow off
P3->OUT |= 0X88; // E.W. Red // ALL RED
if(ticks == 2){ // Hold all lights red for 2 seconds
state = 1; // Increment state
ticks = 0; // Reset the counter ticks
}
}
void directionUp(){
for(i = 0; i< flagRavel; i++){
P5OUT |= BIT4; // Assigns pin 0001 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &=~ BIT4; // Turn pin low
P5OUT |= BIT5; // Assigns pin 0010 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~BIT5; // Turn pin low
P5OUT |= BIT6; // Assigns pin 0100 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~BIT6; // Turn pin low
P5OUT |= BIT7; // Assigns pin 1000 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~BIT7; // Turn pin low
}
}
void directionDown(){
for(i = 0; i< flagRavel; i++){
P5OUT |= 0x80; //Assigns pin 1000 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~0x80; // Turn pin low
P5OUT |= 0x40; // Assigns pin 0100 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~0x40; // Turn pin low
P5OUT |= 0x20; // Assigns pin 0010 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~0x20; // Turn pin low
P5OUT |= 0x10; // Assigns pin 0001 0000 high
delay_ms(stepperSpeed); // stepper speed determined by user
P5OUT &= ~0x10; // Turn pin low
}
}
void T32_INT1_IRQHandler(void){ //Interrupt Handler for Timer 2
TIMER32_1->INTCLR = 1; //Clear interrupt flag so it does not interrupt again immediately.
TIMER32_1->LOAD = 3000000 - 1; //Set to a count down of 1 second on 3 MHz clock
nsTocks++;
ewTocks++;
instructionWrite(0x8E); //15th post
delay_micro(37);
switch(nsTocks){
case 1:
dataWrite(0x30);
dataWrite(0x31); // Send each character to the function datawrite()
break;
case 2:
dataWrite(0x30);
dataWrite(0x32); // Send each character to the function datawrite()
break;
case 3:
dataWrite(0x30);
dataWrite(0x33); // Send each character to the function datawrite()
break;
case 4:
dataWrite(0x30);
dataWrite(0x34); // Send each character to the function datawrite()
break;
case 5:
dataWrite(0x30);
dataWrite(0x35); // Send each character to the function datawrite()
break;
case 6:
dataWrite(0x30);
dataWrite(0x36); // Send each character to the function datawrite()
break;
case 7:
dataWrite(0x30);
dataWrite(0x37); // Send each character to the function datawrite()
break;
case 8:
dataWrite(0x30);
dataWrite(0x38); // Send each character to the function datawrite()
break;
case 9:
dataWrite(0x30);
dataWrite(0x39); // Send each character to the function datawrite()
break;
case 10:
dataWrite(0x30); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 11:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 12:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 13:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x34);
break;
case 14:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x35);
break;
case 15:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x36);
break;
case 16:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x37);
break;
case 17:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x38);
break;
case 18:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x39);
break;
case 19:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x30);
break;
case 20:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 21:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 22:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 23:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x4);
break;
case 24:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x35);
break;
case 25:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x36);
break;
case 26:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x37);
break;
case 27:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x38);
break;
case 28:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x39);
break;
case 29:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x30);
break;
case 30:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 31:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 32:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 33:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x34);
break;
case 34:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x35);
break;
}
instructionWrite(0xCE);
delay_micro(37);
switch(ewTocks){
case 1:
dataWrite(0x30);
dataWrite(0x31); // Send each character to the function datawrite()
break;
case 2:
dataWrite(0x30);
dataWrite(0x32); // Send each character to the function datawrite()
break;
case 3:
dataWrite(0x30);
dataWrite(0x33); // Send each character to the function datawrite()
break;
case 4:
dataWrite(0x30);
dataWrite(0x34); // Send each character to the function datawrite()
break;
case 5:
dataWrite(0x30);
dataWrite(0x35); // Send each character to the function datawrite()
break;
case 6:
dataWrite(0x30);
dataWrite(0x36); // Send each character to the function datawrite()
break;
case 7:
dataWrite(0x30);
dataWrite(0x37); // Send each character to the function datawrite()
break;
case 8:
dataWrite(0x30);
dataWrite(0x38); // Send each character to the function datawrite()
break;
case 9:
dataWrite(0x30);
dataWrite(0x39); // Send each character to the function datawrite()
break;
case 10:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 11:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 12:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 13:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x34);
break;
case 14:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x35);
break;
case 15:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x36);
break;
case 16:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x37);
break;
case 17:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x38);
break;
case 18:
dataWrite(0x31); // Send each character to the function datawrite()
dataWrite(0x39);
break;
case 19:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x30);
break;
case 20:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 21:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 22:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 23:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x4);
break;
case 24:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x35);
break;
case 25:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x36);
break;
case 26:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x37);
break;
case 27:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x38);
break;
case 28:
dataWrite(0x32); // Send each character to the function datawrite()
dataWrite(0x39);
break;
case 29:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x30);
break;
case 30:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x31);
break;
case 31:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x32);
break;
case 32:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x33);
break;
case 33:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x34);
break;
case 34:
dataWrite(0x33); // Send each character to the function datawrite()
dataWrite(0x35);
break;
}
}
void displayTopLine(char* topLine){
for (i = 0; topLine[i] != '\0'; i++){ // While i doesn't equal the null character increment through the top array
dataWrite(topLine[i]); // Send each character to the function datawrite();
}
}
void displayBottomLine(char* bottomLine){
for (i = 0; bottomLine[i] != '\0'; i++){ // While i doesn't equal the null character increment through the bottom array
dataWrite(bottomLine[i]); // Send each character to the function datawrite();
}
}
void buzzerTone1(){
TIMER_A0->CCR[0] = 4000;
TIMER_A0->CCR[2] = 2000;
}
void buzzerTone2(){
TIMER_A0->CCR[0] = 5000;;
TIMER_A0->CCR[2] = 2500;
}
void buzzerTone3(){
TIMER_A0->CCR[0] = 6000;
TIMER_A0->CCR[2] = 3000;
}
void buzzOff(){
TIMER_A0->CCR[0] = 0;
TIMER_A0->CCR[2] = 0;
}
//TRAFFIC LIGHT / CROSSWALK FUNCTIONS
void ns_toggleYellowLED(){
for(i = 0; i < toggle; i++){
checkNS_crossWalk();
//checkPole();
P6->OUT |= 0x40;
if(NS_crosswalk == 3){
NS_crosswalkFlash();
}
delay_ms(on_off);
P6->OUT &=~ 0x40;
if(NS_crosswalk == 3){
NS_crosswalkFlash();
}
delay_ms(on_off);
}
}
void checkNS_crossWalk(){
if(state == 1 && NS_crosswalk == 1){
P7->OUT &=~ BIT6; // EW GREEN Crosswalk off for safety
toggle = toggle + 15;
P7->OUT |= BIT7; // Turn on Green Cross walk
NS_crosswalk = 2; // Increment so it will not continue to increment the toggle time
}
if(NS_crosswalk == 3){
P7->OUT &=~ BIT7; // Turn off green cross
}
if(EW_crosswalk == 1){
EW_crosswalk = 2; // Will monitor the state and hold until light changes
toggle = 15; // Decreases the current light toggle time
}
if(!(P1->IN & BIT5)){
nsBuzzerFlag++;
}
if(nsBuzzerFlag > 10){
buzzerTone1();
}
if(NS_crosswalk == 3 & nsBuzzerFlag > 10){
buzzerTone2();
}