this is my final project in a class. this program is used to analog a transportation schedule systems

Dependencies:   C12832_lcd mbed

Fork of app-board-Joystick-with-LCD by Kim Sehee

Committer:
yantao
Date:
Thu Jun 05 21:34:40 2014 +0000
Revision:
1:7af7e8d3a37f
Parent:
0:3cb0e69f1806
this programm is my final project in a ucsc-extension's course: embedded IO programming.; the programm is used to analog 4 roads schedule.each time only one road is opened for transportation.; road1,road 2,and road3 are polled scheduled periodically

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ssery 0:3cb0e69f1806 1 #include "mbed.h"
ssery 0:3cb0e69f1806 2 #include "C12832_lcd.h"
ssery 0:3cb0e69f1806 3
yantao 1:7af7e8d3a37f 4 //program description
yantao 1:7af7e8d3a37f 5 //author: TAO YAN
yantao 1:7af7e8d3a37f 6 //date:June 5 2014
yantao 1:7af7e8d3a37f 7 //this program is used to analog 4 roads usage
yantao 1:7af7e8d3a37f 8 //there are 4 roads: road1, road2, road3 and vip_road
yantao 1:7af7e8d3a37f 9 // each time only one road is opened for transportation
yantao 1:7af7e8d3a37f 10 //road1,road 2,and road3 are polled scheduled periodically: road1->road2->road3->road1->road2->road3
yantao 1:7af7e8d3a37f 11 //however, if programm detected vip road's request open signal:by push center button
yantao 1:7af7e8d3a37f 12 // program will act as an preemptive OS, hang current road, and schedule vip road
yantao 1:7af7e8d3a37f 13 // when vip road's transportation finished, system will resume the previous road that was interrupted by the vip road: such as below
yantao 1:7af7e8d3a37f 14 // road1 run--->system detects vip road signal->vip road run->road1 run->road2 run->road3 run->road1 run->
yantao 1:7af7e8d3a37f 15 //road2 run->ystem detects vip road signal->vip road run->road2 run->road3 run->road1 run
yantao 1:7af7e8d3a37f 16
ssery 0:3cb0e69f1806 17 // LCD and Joystick Setting
ssery 0:3cb0e69f1806 18 C12832_LCD lcd;
ssery 0:3cb0e69f1806 19
ssery 0:3cb0e69f1806 20 BusIn Up(p15);
ssery 0:3cb0e69f1806 21 BusIn Down(p12);
ssery 0:3cb0e69f1806 22 BusIn Left(p13);
ssery 0:3cb0e69f1806 23 BusIn Right(p16);
yantao 1:7af7e8d3a37f 24 BusIn Center(p14);
yantao 1:7af7e8d3a37f 25
yantao 1:7af7e8d3a37f 26
yantao 1:7af7e8d3a37f 27
yantao 1:7af7e8d3a37f 28 BusOut leds(LED1,LED2,LED3,LED4);
ssery 0:3cb0e69f1806 29
ssery 0:3cb0e69f1806 30 // Custom Function
ssery 0:3cb0e69f1806 31 void initialize();
ssery 0:3cb0e69f1806 32
yantao 1:7af7e8d3a37f 33
yantao 1:7af7e8d3a37f 34
yantao 1:7af7e8d3a37f 35 typedef enum
yantao 1:7af7e8d3a37f 36 {
yantao 1:7af7e8d3a37f 37 Road1_can_Pass=0,
yantao 1:7af7e8d3a37f 38 Road2_can_Pass,
yantao 1:7af7e8d3a37f 39 Road3_can_Pass,
yantao 1:7af7e8d3a37f 40 vip_Road4_mustPass_now,
yantao 1:7af7e8d3a37f 41
yantao 1:7af7e8d3a37f 42 }STATE;
yantao 1:7af7e8d3a37f 43
yantao 1:7af7e8d3a37f 44 #define switch_to_vip_road 1
yantao 1:7af7e8d3a37f 45 #define road1 1
yantao 1:7af7e8d3a37f 46 #define road2 2
yantao 1:7af7e8d3a37f 47 #define road3 3
yantao 1:7af7e8d3a37f 48
ssery 0:3cb0e69f1806 49 int main()
ssery 0:3cb0e69f1806 50 {
yantao 1:7af7e8d3a37f 51 int index=0,is_now_swith_vip_road=0,return_from_vip_road=0;
yantao 1:7af7e8d3a37f 52 int current_state = Road1_can_Pass;
ssery 0:3cb0e69f1806 53 initialize();
yantao 1:7af7e8d3a37f 54 while(1)
yantao 1:7af7e8d3a37f 55 {
yantao 1:7af7e8d3a37f 56 lcd.locate(0,15);
yantao 1:7af7e8d3a37f 57 switch(current_state)
yantao 1:7af7e8d3a37f 58 {
yantao 1:7af7e8d3a37f 59
yantao 1:7af7e8d3a37f 60 case Road1_can_Pass:
yantao 1:7af7e8d3a37f 61 is_now_swith_vip_road=0;
yantao 1:7af7e8d3a37f 62 return_from_vip_road=0;
yantao 1:7af7e8d3a37f 63 leds=1;
yantao 1:7af7e8d3a37f 64 initialize();
yantao 1:7af7e8d3a37f 65 lcd.printf("now road1 open\n");
yantao 1:7af7e8d3a37f 66 for(index=0;index<660000;index++)
yantao 1:7af7e8d3a37f 67 {
yantao 1:7af7e8d3a37f 68 if(Center)
yantao 1:7af7e8d3a37f 69 {
yantao 1:7af7e8d3a37f 70 leds=0;
yantao 1:7af7e8d3a37f 71 is_now_swith_vip_road=switch_to_vip_road;
yantao 1:7af7e8d3a37f 72 return_from_vip_road=road1;
yantao 1:7af7e8d3a37f 73 break;
yantao 1:7af7e8d3a37f 74 }
yantao 1:7af7e8d3a37f 75 leds!=leds;
yantao 1:7af7e8d3a37f 76 }
yantao 1:7af7e8d3a37f 77 if(is_now_swith_vip_road==switch_to_vip_road) //if button center entered, means intrruptedbyviproad,return to road1 when vip road transoirtation finished
yantao 1:7af7e8d3a37f 78 {
yantao 1:7af7e8d3a37f 79 current_state=vip_Road4_mustPass_now;
yantao 1:7af7e8d3a37f 80 initialize();
yantao 1:7af7e8d3a37f 81 lcd.printf("confirm vip road request open signal, switch to vip road transportation\n");
yantao 1:7af7e8d3a37f 82 wait(1);
yantao 1:7af7e8d3a37f 83 initialize();
yantao 1:7af7e8d3a37f 84 lcd.printf("when vip road transportation finished, switched return to road1\n");
yantao 1:7af7e8d3a37f 85 wait(1);
yantao 1:7af7e8d3a37f 86 }
yantao 1:7af7e8d3a37f 87 else
yantao 1:7af7e8d3a37f 88 {
yantao 1:7af7e8d3a37f 89 current_state = Road2_can_Pass;
yantao 1:7af7e8d3a37f 90 initialize();
yantao 1:7af7e8d3a37f 91 lcd.printf("road1 tranportation will finished,now will switch to road 2\n");//sequence:road1, road2 ,road3 periodically
yantao 1:7af7e8d3a37f 92 wait(1);
yantao 1:7af7e8d3a37f 93 }
yantao 1:7af7e8d3a37f 94 break;
yantao 1:7af7e8d3a37f 95
yantao 1:7af7e8d3a37f 96
yantao 1:7af7e8d3a37f 97
yantao 1:7af7e8d3a37f 98
yantao 1:7af7e8d3a37f 99 case Road2_can_Pass:
yantao 1:7af7e8d3a37f 100 is_now_swith_vip_road=0;
yantao 1:7af7e8d3a37f 101 return_from_vip_road=0;
yantao 1:7af7e8d3a37f 102 leds=2;
yantao 1:7af7e8d3a37f 103 initialize();
yantao 1:7af7e8d3a37f 104 lcd.printf("now road2 open\n");
yantao 1:7af7e8d3a37f 105 for(index=0;index<660000;index++)
yantao 1:7af7e8d3a37f 106 {
yantao 1:7af7e8d3a37f 107 if(Center)
yantao 1:7af7e8d3a37f 108 {
yantao 1:7af7e8d3a37f 109 leds=0;
yantao 1:7af7e8d3a37f 110 is_now_swith_vip_road=switch_to_vip_road;
yantao 1:7af7e8d3a37f 111 return_from_vip_road=road2;
yantao 1:7af7e8d3a37f 112 break;
yantao 1:7af7e8d3a37f 113 }
yantao 1:7af7e8d3a37f 114 leds!=leds;
yantao 1:7af7e8d3a37f 115 }
yantao 1:7af7e8d3a37f 116 if(is_now_swith_vip_road==switch_to_vip_road)
yantao 1:7af7e8d3a37f 117 {
yantao 1:7af7e8d3a37f 118 current_state=vip_Road4_mustPass_now;
yantao 1:7af7e8d3a37f 119 initialize();
yantao 1:7af7e8d3a37f 120 lcd.printf("confirm vip road request open signal, switch to vip road transportation\n");
yantao 1:7af7e8d3a37f 121 wait(1);
yantao 1:7af7e8d3a37f 122 initialize();
yantao 1:7af7e8d3a37f 123 lcd.printf("when vip road transportation finished, switched return to road2\n");
yantao 1:7af7e8d3a37f 124 wait(1);
yantao 1:7af7e8d3a37f 125 }
yantao 1:7af7e8d3a37f 126 else
yantao 1:7af7e8d3a37f 127 {
yantao 1:7af7e8d3a37f 128 current_state = Road3_can_Pass;
yantao 1:7af7e8d3a37f 129 initialize();
yantao 1:7af7e8d3a37f 130 lcd.printf("road2 tranportation will finished,now will switch to road 3 transportation\n");//sequence:road1, road2 ,road3 periodically
yantao 1:7af7e8d3a37f 131 wait(1);
yantao 1:7af7e8d3a37f 132 }
yantao 1:7af7e8d3a37f 133 break;
yantao 1:7af7e8d3a37f 134
yantao 1:7af7e8d3a37f 135
yantao 1:7af7e8d3a37f 136 case Road3_can_Pass:
yantao 1:7af7e8d3a37f 137 is_now_swith_vip_road=0;
yantao 1:7af7e8d3a37f 138 return_from_vip_road=0;
yantao 1:7af7e8d3a37f 139 leds=4;
yantao 1:7af7e8d3a37f 140 initialize();
yantao 1:7af7e8d3a37f 141 lcd.printf("now road3 open\n");
yantao 1:7af7e8d3a37f 142 for(index=0;index<660000;index++)
yantao 1:7af7e8d3a37f 143 {
yantao 1:7af7e8d3a37f 144 if(Center)
yantao 1:7af7e8d3a37f 145 {
yantao 1:7af7e8d3a37f 146 leds=0;
yantao 1:7af7e8d3a37f 147 is_now_swith_vip_road=switch_to_vip_road;
yantao 1:7af7e8d3a37f 148 return_from_vip_road=road3;
yantao 1:7af7e8d3a37f 149 break;
yantao 1:7af7e8d3a37f 150 }
yantao 1:7af7e8d3a37f 151 leds!=leds;
yantao 1:7af7e8d3a37f 152 }
yantao 1:7af7e8d3a37f 153 if(is_now_swith_vip_road==switch_to_vip_road)
yantao 1:7af7e8d3a37f 154 {
yantao 1:7af7e8d3a37f 155 current_state=vip_Road4_mustPass_now;
yantao 1:7af7e8d3a37f 156 initialize();
yantao 1:7af7e8d3a37f 157 lcd.printf("confirm vip road request open signal, switch to vip road transportation\n");
yantao 1:7af7e8d3a37f 158 wait(1);
yantao 1:7af7e8d3a37f 159 initialize();
yantao 1:7af7e8d3a37f 160 lcd.printf("when vip road transportation finished, switched return to road3\n");
yantao 1:7af7e8d3a37f 161 wait(1);
yantao 1:7af7e8d3a37f 162 }
yantao 1:7af7e8d3a37f 163 else
yantao 1:7af7e8d3a37f 164 {
yantao 1:7af7e8d3a37f 165 current_state = Road1_can_Pass;
yantao 1:7af7e8d3a37f 166 initialize();
yantao 1:7af7e8d3a37f 167 lcd.printf("road3 tranportation will finished,now will periodically switch to road 1 transportation\n");//sequence:road1, road2 ,road3 periodically
yantao 1:7af7e8d3a37f 168 wait(1);
yantao 1:7af7e8d3a37f 169 }
yantao 1:7af7e8d3a37f 170 break;
yantao 1:7af7e8d3a37f 171 case vip_Road4_mustPass_now:
yantao 1:7af7e8d3a37f 172 leds=8;
yantao 1:7af7e8d3a37f 173 initialize();
yantao 1:7af7e8d3a37f 174 lcd.printf("now vip road open\n");
yantao 1:7af7e8d3a37f 175 for(index=0;index<660000;index++)
yantao 1:7af7e8d3a37f 176 {
yantao 1:7af7e8d3a37f 177 leds!=leds;
yantao 1:7af7e8d3a37f 178 }
yantao 1:7af7e8d3a37f 179 if(return_from_vip_road==road1)
yantao 1:7af7e8d3a37f 180 {
yantao 1:7af7e8d3a37f 181 current_state = Road1_can_Pass;
yantao 1:7af7e8d3a37f 182 initialize();
yantao 1:7af7e8d3a37f 183 lcd.printf("now vip road transportation finished, switched return to road1\n");
yantao 1:7af7e8d3a37f 184 wait(1);
yantao 1:7af7e8d3a37f 185 }
yantao 1:7af7e8d3a37f 186 else if(return_from_vip_road==road2)
yantao 1:7af7e8d3a37f 187 {
yantao 1:7af7e8d3a37f 188 current_state = Road2_can_Pass;
yantao 1:7af7e8d3a37f 189 initialize();
yantao 1:7af7e8d3a37f 190 lcd.printf("now vip road transportation finished, switched return to road2\n");
yantao 1:7af7e8d3a37f 191 wait(1);
yantao 1:7af7e8d3a37f 192 }
yantao 1:7af7e8d3a37f 193 else if(return_from_vip_road==road3)
yantao 1:7af7e8d3a37f 194 {
yantao 1:7af7e8d3a37f 195 current_state = Road3_can_Pass;
yantao 1:7af7e8d3a37f 196 initialize();
yantao 1:7af7e8d3a37f 197 lcd.printf("now vip road transportation finished, switched return to road3\n");
yantao 1:7af7e8d3a37f 198 wait(1);
yantao 1:7af7e8d3a37f 199 }
yantao 1:7af7e8d3a37f 200 break;
yantao 1:7af7e8d3a37f 201
yantao 1:7af7e8d3a37f 202 default:
yantao 1:7af7e8d3a37f 203 break;
yantao 1:7af7e8d3a37f 204 }
yantao 1:7af7e8d3a37f 205 }
yantao 1:7af7e8d3a37f 206 return 0;
ssery 0:3cb0e69f1806 207 }
ssery 0:3cb0e69f1806 208 void initialize()
ssery 0:3cb0e69f1806 209 {
ssery 0:3cb0e69f1806 210 lcd.cls();
yantao 1:7af7e8d3a37f 211 lcd.locate(0,0);
yantao 1:7af7e8d3a37f 212 }