this is my final project in a class. this program is used to analog a transportation schedule systems
Fork of app-board-Joystick-with-LCD by
Revision 1:7af7e8d3a37f, committed 2014-06-05
- Comitter:
- yantao
- Date:
- Thu Jun 05 21:34:40 2014 +0000
- Parent:
- 0:3cb0e69f1806
- Commit message:
- 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
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 08 11:13:01 2013 +0000 +++ b/main.cpp Thu Jun 05 21:34:40 2014 +0000 @@ -1,6 +1,19 @@ #include "mbed.h" #include "C12832_lcd.h" +//program description +//author: TAO YAN +//date:June 5 2014 +//this program is used to analog 4 roads usage +//there are 4 roads: road1, road2, road3 and vip_road +// each time only one road is opened for transportation +//road1,road 2,and road3 are polled scheduled periodically: road1->road2->road3->road1->road2->road3 +//however, if programm detected vip road's request open signal:by push center button +// program will act as an preemptive OS, hang current road, and schedule vip road +// when vip road's transportation finished, system will resume the previous road that was interrupted by the vip road: such as below +// road1 run--->system detects vip road signal->vip road run->road1 run->road2 run->road3 run->road1 run-> +//road2 run->ystem detects vip road signal->vip road run->road2 run->road3 run->road1 run + // LCD and Joystick Setting C12832_LCD lcd; @@ -8,34 +21,192 @@ BusIn Down(p12); BusIn Left(p13); BusIn Right(p16); -BusOut Reset(p14); +BusIn Center(p14); + + + +BusOut leds(LED1,LED2,LED3,LED4); // Custom Function void initialize(); -// Main + + +typedef enum +{ + Road1_can_Pass=0, + Road2_can_Pass, + Road3_can_Pass, + vip_Road4_mustPass_now, + +}STATE; + +#define switch_to_vip_road 1 +#define road1 1 +#define road2 2 +#define road3 3 + int main() { + int index=0,is_now_swith_vip_road=0,return_from_vip_road=0; + int current_state = Road1_can_Pass; initialize(); - while(1) - { - lcd.locate(0,15); // Set Location print a text - // Operations by Joystic - if (Up) - lcd.printf("UP"); - if (Down) - lcd.printf("Down"); - if (Left) - lcd.printf("Left"); - if (Right) - lcd.printf("Right"); - if (Reset) - initialize(); - } + while(1) + { + lcd.locate(0,15); + switch(current_state) + { + + case Road1_can_Pass: + is_now_swith_vip_road=0; + return_from_vip_road=0; + leds=1; + initialize(); + lcd.printf("now road1 open\n"); + for(index=0;index<660000;index++) + { + if(Center) + { + leds=0; + is_now_swith_vip_road=switch_to_vip_road; + return_from_vip_road=road1; + break; + } + leds!=leds; + } + if(is_now_swith_vip_road==switch_to_vip_road) //if button center entered, means intrruptedbyviproad,return to road1 when vip road transoirtation finished + { + current_state=vip_Road4_mustPass_now; + initialize(); + lcd.printf("confirm vip road request open signal, switch to vip road transportation\n"); + wait(1); + initialize(); + lcd.printf("when vip road transportation finished, switched return to road1\n"); + wait(1); + } + else + { + current_state = Road2_can_Pass; + initialize(); + lcd.printf("road1 tranportation will finished,now will switch to road 2\n");//sequence:road1, road2 ,road3 periodically + wait(1); + } + break; + + + + + case Road2_can_Pass: + is_now_swith_vip_road=0; + return_from_vip_road=0; + leds=2; + initialize(); + lcd.printf("now road2 open\n"); + for(index=0;index<660000;index++) + { + if(Center) + { + leds=0; + is_now_swith_vip_road=switch_to_vip_road; + return_from_vip_road=road2; + break; + } + leds!=leds; + } + if(is_now_swith_vip_road==switch_to_vip_road) + { + current_state=vip_Road4_mustPass_now; + initialize(); + lcd.printf("confirm vip road request open signal, switch to vip road transportation\n"); + wait(1); + initialize(); + lcd.printf("when vip road transportation finished, switched return to road2\n"); + wait(1); + } + else + { + current_state = Road3_can_Pass; + initialize(); + lcd.printf("road2 tranportation will finished,now will switch to road 3 transportation\n");//sequence:road1, road2 ,road3 periodically + wait(1); + } + break; + + + case Road3_can_Pass: + is_now_swith_vip_road=0; + return_from_vip_road=0; + leds=4; + initialize(); + lcd.printf("now road3 open\n"); + for(index=0;index<660000;index++) + { + if(Center) + { + leds=0; + is_now_swith_vip_road=switch_to_vip_road; + return_from_vip_road=road3; + break; + } + leds!=leds; + } + if(is_now_swith_vip_road==switch_to_vip_road) + { + current_state=vip_Road4_mustPass_now; + initialize(); + lcd.printf("confirm vip road request open signal, switch to vip road transportation\n"); + wait(1); + initialize(); + lcd.printf("when vip road transportation finished, switched return to road3\n"); + wait(1); + } + else + { + current_state = Road1_can_Pass; + initialize(); + lcd.printf("road3 tranportation will finished,now will periodically switch to road 1 transportation\n");//sequence:road1, road2 ,road3 periodically + wait(1); + } + break; + case vip_Road4_mustPass_now: + leds=8; + initialize(); + lcd.printf("now vip road open\n"); + for(index=0;index<660000;index++) + { + leds!=leds; + } + if(return_from_vip_road==road1) + { + current_state = Road1_can_Pass; + initialize(); + lcd.printf("now vip road transportation finished, switched return to road1\n"); + wait(1); + } + else if(return_from_vip_road==road2) + { + current_state = Road2_can_Pass; + initialize(); + lcd.printf("now vip road transportation finished, switched return to road2\n"); + wait(1); + } + else if(return_from_vip_road==road3) + { + current_state = Road3_can_Pass; + initialize(); + lcd.printf("now vip road transportation finished, switched return to road3\n"); + wait(1); + } + break; + + default: + break; + } + } + return 0; } void initialize() { lcd.cls(); - lcd.locate(0,0); - lcd.printf("Joystic and LCD Controller!"); -} \ No newline at end of file + lcd.locate(0,0); +}