Sie sind auf Seite 1von 68

CODE LISTING

MAIN SM
/ *********************************************************************** ***** Module MainSM.c Description The only state machine used for the implementation. *********************************************************************** *****/ /*----------------------------- Include Files -----------------------------*/ /* include header files for this state machine as well as any machines at the next lower level in the hierarchy that are sub-machines to this machine */ #include <stdio.h> #include <ME218_C32.h> #include "misc.h" #include "EF_General.h" #include "EF_Queue.h" #include "EF_Events.h" #include "MainSM.h" #include "EF_Timers.h" #include "EF_PostList.h" // Action Function header files //HERE??? #include "MotorActions.h" #include "LEDActions.h" #include "WaitFor.h" /*----------------------------- Module Defines ----------------------------*/ #define QUEUE_SIZE 3 /*---------------------------- Module Functions ---------------------------*/ // prototypes for private functions for this machine.They should be functions // relevant to the behavior of this state machine int CheckHolsterStatus(void);

/*---------------------------- Module Variables ---------------------------*/

// everybody needs a state variable, you may need others as well. // type of state variable should match htat of enum in header file static MainState_t CurrentState; static MainState_t NextState; // NEED THESE? static unsigned int MotorPulseWaitTime; static short Difficulty = 0; static short LowDiffThresh = 333; static short HighDiffThresh = 667; static unsigned int LeftScore = 0; static unsigned int RightScore = 0; static unsigned int MediumScoreThresh = 20; // *********** CALIBRATE THIS *************** static unsigned int PostGameTime = 5000; static char FirstEvent = 0; //static unsigned int MasterTime = 45000; static unsigned int CountDownWaitTime = 750; static unsigned int ClockWaitTime = 100; static unsigned int PulseClockTime = 1000; static char RYGcounter = 0; static unsigned int RYGWaitTime = 125; unsigned int LongerWait; // everybody needs a queue too! EF_Event MainSMQueue[QUEUE_SIZE+1]; /*------------------------------ Module Code ------------------------------*/ / *********************************************************************** ***** Function InitTemplateSM Parameters None Returns boolean, False if error in initialization, True otherwise Description Sets up the event queue and does any rother equired initialization for this state machine Notes Author

J. Edward Carryer, 10/23/11, 18:55 *********************************************************************** *****/ boolean InitMainSM ( void ) { unsigned char ucResult1; EF_Event ThisEvent; ucResult1 = EF_InitQueue( MainSMQueue, ARRAY_SIZE(MainSMQueue) ); if ( ucResult1 == QUEUE_SIZE ) // successful queue init { // put us into the Initial PseudoState CurrentState = InitMain; // Default Fan to OFF TurnOffFan(); // post the initial transition event ThisEvent.EventType = EF_INIT; if (PostMainSM( ThisEvent ) == True) { return True; }else { return False; } }else { return False; } } / *********************************************************************** ***** Function PostTemplateSM Parameters EF_Event ThisEvent , the event to post to the queue Returns boolean False if the Enqueue operation failed, True otherwise Description Posts an event to the state machine's queue

Notes Author J. Edward Carryer, 10/23/11, 19:25 *********************************************************************** *****/ boolean PostMainSM( EF_Event ThisEvent ) { boolean bResult3; bResult3 = EF_EnQueueFIFO( MainSMQueue, ThisEvent ); return bResult3; } / *********************************************************************** ***** Function RunTemplateSM Parameters void Returns boolean, Flase if an error encountered, True otherwise Description add your description here Notes uses nested switch/case to implement the machine. Author J. Edward Carryer, 10/23/11, 18:38 *********************************************************************** *****/ boolean RunMainSM( void ) { EF_Event ThisEvent; // pull an event from the queue ThisEvent = EF_DeQueue( MainSMQueue ); NextState = CurrentState; // we should only call the Run function if we know that there is something in // the queue, so if we found EF_NO_EVENT something is wrong if (ThisEvent.EventType == EF_NO_EVENT )

{ return False; }else { switch ( CurrentState ) { case InitMain : if ( ThisEvent.EventType == EF_INIT ) { puts("INIT EVENT \n\r"); NextState = BothIn; // Call LED Function here, turn on LR and RR AllOffLED(); BothInLED(); } break; case BothIn : // If current state is BothIn switch ( ThisEvent.EventType ) { case LeftRemoved : //If event is LeftRemoved { NextState = LeftOut; // Call LED Function here, turn on LG and RR AllOffLED(); LeftOutLED(); } break; case RightRemoved : //If event is RightRemoved { NextState = RightOut; // Call LED Function here, turn on LR and RG AllOffLED(); RightOutLED(); } break; case StartSelected : //If event is StartSelected { NextState = BothIn; FlashBothRed(); } break; } break;

case LeftOut : // If current state is LeftOut switch ( ThisEvent.EventType ) { case LeftReturned : //If event is LeftReturned { NextState = BothIn; // Call LED Function here, turn on LR and RR AllOffLED(); BothInLED(); } break; case RightRemoved : //If event is RightRemoved { NextState = BothOut; // Call LED Function here, turn on LG and RG AllOffLED(); BothOutLED(); } break; case StartSelected : //If event is StartSelected { NextState = LeftOut; FlashRightRed(); } break; } break; case RightOut : // If current state is RightOut switch ( ThisEvent.EventType ) { case LeftRemoved : //If event is LeftRemoved { NextState = BothOut; // Call LED Function here, turn on LG and RG AllOffLED(); BothOutLED(); } break; case RightReturned : //If event is RightReturned { NextState = BothIn;

// Call LED Function here, turn on LR and RR AllOffLED(); BothInLED(); } break; case StartSelected : //If event is StartSelected { NextState = RightOut; FlashLeftRed(); } break; } break; case BothOut : // If current state is BothOut switch ( ThisEvent.EventType ) { case LeftReturned : //If event is LeftReturned { NextState = RightOut; // Call LED Function here, turn on LR and RG AllOffLED(); RightOutLED(); } break; case RightReturned : //If event is RightReturned { NextState = LeftOut; // Call LED Function here, turn on LG and RR AllOffLED(); LeftOutLED(); } break; case StartSelected : //If event is StartSelected { NextState = GameStarted; // Call LED Function here, turn off all LEDs AllOffLED(); // LED Countdown Red, Yellow Green BadOutcomeLED();

WaitFor(CountDownWaitTime); MediumOutcomeLED(); WaitFor(CountDownWaitTime); GoodOutcomeLED(); WaitFor(CountDownWaitTime); AllOffLED(); // Set Difficulty Difficulty = ReadDifficulty(); if (Difficulty <= LowDiffThresh) { MotorPulseWaitTime = 80; puts("Easy Difficulty \n\r"); } else if (Difficulty >= HighDiffThresh) { MotorPulseWaitTime = 40; puts("Hard Difficulty \n\r"); } else { MotorPulseWaitTime = 60; puts("Medium Difficulty \n\r"); } printf("Difficulty: %d \n\r", Difficulty); LongerWait = RYGWaitTime*4; WaitFor(CountDownWaitTime); TurnOnRYG(); EF_Timer_InitTimer(0,LongerWait); RYGcounter = 0; } break; } break; case GameStarted : // If current state is GameStarted

switch ( ThisEvent.EventType ) { case EF_TIMEOUT : {

// Flash the green (first 5 sec), yellow (second 5 sec) and red (third 5 sec) LEDs to indicate the remaining time. // The frequency of flashing increases when moving from green to yellow to red if (RYGcounter < 40) { if ( ((RYGcounter % 8) == 0) || ((RYGcounter % 8) == 1) || ((RYGcounter % 8) == 2) || ((RYGcounter % 8) == 3) ) { NextState = GameStarted; TurnOnRY(); EF_Timer_InitTimer(0, RYGWaitTime); } else { NextState = GameStarted; TurnOnRYG(); EF_Timer_InitTimer(0, RYGWaitTime); } } else if (RYGcounter < 80) { if ( ((RYGcounter % 4) == 0) || ((RYGcounter % 4) == 1) ) { NextState = GameStarted; BadOutcomeLED(); EF_Timer_InitTimer(0, RYGWaitTime); } else { NextState = GameStarted; TurnOnRY(); EF_Timer_InitTimer(0, RYGWaitTime); } } else if (RYGcounter < 120) { if ( (RYGcounter % 2) == 0) { NextState = GameStarted; AllOffLED(); EF_Timer_InitTimer(0, RYGWaitTime); } else { NextState = GameStarted; BadOutcomeLED(); EF_Timer_InitTimer(0, RYGWaitTime); } } else if (RYGcounter == 120) // GAME OVER {

NextState = GameOver; TurnOffFan(); AllOffLED(); EF_Timer_InitTimer(0, PostGameTime); puts(" GAME OVER \n\r"); // Check the scores to determine which outcome to present to the user if (RightScore >= LeftScore) { puts("Right Player Wins \n\r"); if (RightScore >= MediumScoreThresh) { RightMediumOutcomeLED(); puts("Medium Outcome \n\r"); } else { RightBadOutcomeLED(); puts("Bad Outcome \n\r"); } } else { puts("Left Player Wins \n\r"); if (LeftScore >= MediumScoreThresh) { LeftMediumOutcomeLED(); puts("Medium Outcome \n\r"); } else { LeftBadOutcomeLED(); puts("Bad Outcome \n\r"); } } } RYGcounter++; } break;

case LeftShakeDetected : //If event is LeftShakeDetected { NextState = GameStarted; // Pulse Left Motor StartLeftScore(); WaitFor(MotorPulseWaitTime); StopLeftScore(); //Increment Left Score LeftScore++; printf("Left Score: %d \n\r \n\r", LeftScore); // Turn on Fan TurnOnFan(); } break; case RightShakeDetected : //If event is RightShakeDetected { NextState = GameStarted; // Pulse Right Motor StartRightScore(); //puts("Right Motor Started \n\r"); WaitFor(MotorPulseWaitTime); StopRightScore(); //puts("Right Motor Stopped \n\r"); // Increment Right Score RightScore++; printf("Right Score: %d \n\r \n\r", RightScore); //Turn on Fan TurnOnFan(); } break; case LeftUpperLimitHit : //If event is LeftUpperLimitHit { if (LeftScore > 4) { NextState = GameOver; puts("Left Limit Hit, Game Over \n\r"); // Stop Timer Motor

StopGameClock(); // Turn Off Fan TurnOffFan(); // Turn on Winning and Left Green LEDs LeftGoodOutcomeLED(); // Start Timer EF_Timer_InitTimer(0, PostGameTime); } } break; case RightUpperLimitHit : //If event is RightUpperLimitHit { if (RightScore > 4) { NextState = GameOver; puts("Right Limit Hit, Game Over \n\r"); // Stop Timer Motor StopGameClock(); // Turn Off Fan TurnOffFan(); // Turn on Winning and Right Green LEDs RightGoodOutcomeLED(); // Start Timer EF_Timer_InitTimer(0, PostGameTime); } } break; } break; case GameOver : // If current state is Game Over puts("IN GAME OVER STATE \n\r"); switch ( ThisEvent.EventType ) { case EF_TIMEOUT : //If event is LeftReturned {

NextState = Resetting; puts("Timer Expired, Resetting \n\r"); //Turn off LEDs AllOffLED(); //Reverse Left Score Motor ResetLeftScore(); //Reverse Right Score Motor ResetRightScore(); } break; } break; case Resetting : // If current state is Resetting switch ( ThisEvent.EventType ) { case LeftLowerLimitHit : //If event is AllReset { NextState = LeftReset; StopLeftScore(); puts(" Left Reset \n\r"); } break; case RightLowerLimitHit : //If event is AllReset { NextState = RightReset; StopRightScore(); puts(" Right Reset \n\r"); } break; } break; case LeftReset : // If current state is Resetting switch ( ThisEvent.EventType ) { case RightLowerLimitHit : //If event is AllReset { int HolsterState = CheckHolsterStatus();

//NextState = BothReset; StopRightScore(); puts(" Right Reset. Both Reset. \n\r"); //StopGameClock(); RightScore = 0; LeftScore = 0; puts("Everything Reset \n\r"); // Both Out if (HolsterState == 1) { puts("Resetting to Both Holsters Out \n\r"); NextState = BothOut; // Turn on Both Out LEDS BothOutLED(); } // Left Out else if (HolsterState == 2) { puts("Resetting to Left Holster Out \n\r"); NextState = LeftOut; // Turn on Left Out LEDS LeftOutLED(); } // Right Out else if (HolsterState == 3) { puts("Resetting to Right Holster Out \n\r"); NextState = RightOut; // Turn on Right Out LEDS RightOutLED(); } // Both In else if (HolsterState == 4) { puts("Resetting to Both Holsters In \n\r"); NextState = BothIn; // Turn on Both In LEDS BothInLED(); }

} break; } break; case RightReset : // If current state is Resetting switch ( ThisEvent.EventType ) { case LeftLowerLimitHit : //If event is AllReset { int HolsterState = CheckHolsterStatus(); //NextState = BothReset; StopLeftScore(); puts(" Left Reset. Both Reset. \n\r"); //StopGameClock(); RightScore = 0; LeftScore = 0; puts("Everything Reset \n\r"); // Both Out if (HolsterState == 1) { puts("Resetting to Both Holsters Out \n\r"); NextState = BothOut; // Turn on Both Out LEDS BothOutLED(); } // Left Out else if (HolsterState == 2) { puts("Resetting to Left Holster Out \n\r"); NextState = LeftOut; // Turn on Left Out LEDS LeftOutLED(); } // Right Out else if (HolsterState == 3) { puts("Resetting to Right Holster Out \n\r"); NextState = RightOut;

// Turn on Right Out LEDS RightOutLED(); } // Both In else if (HolsterState == 4) { puts("Resetting to Both Holsters In \n\r"); NextState = BothIn; // Turn on Both In LEDS BothInLED(); } } break; } break; } CurrentState = NextState; return True; } } /********************************************************************** ****** Function IsTemplateSMQEmpty Parameters void Returns boolean True if the Queue is empty, False if the queue has something in it Description tests if this state machine's queue is empty Notes Author J. Edward Carryer, 10/23/11, 19:28 *********************************************************************** *****/

boolean IsMainSMQEmpty( void ){ return EF_IsQueueEmpty( MainSMQueue ); } / *********************************************************************** ***** Function QueryTemplateSM Parameters None Returns TemplateState_t The current state of the Template state machine Description returns the current state of the Template state machine Notes Author J. Edward Carryer, 10/23/11, 19:21 *********************************************************************** *****/ MainState_t QueryMainSM ( void ) { return(CurrentState); } / *********************************************************************** **** private functions *********************************************************************** ****/ int CheckHolsterStatus(void) { unsigned char LeftHolsterStatus; unsigned char RightHolsterStatus; LeftHolsterStatus = PTT & BIT0HI; RightHolsterStatus = PTT & BIT1HI;

//Both Out if ( (LeftHolsterStatus == 0) && (RightHolsterStatus == 0) ) return 1; // Left Out if ( (LeftHolsterStatus == 0) && (RightHolsterStatus == 2) ) return 2; // Right Out if ( (LeftHolsterStatus == 1) && (RightHolsterStatus == 0) ) return 3; // Both In if ( (LeftHolsterStatus == 1) && (RightHolsterStatus == 2) ) return 4; }

EVENT CHECKERS
EVENTCHECKERS.C // Event Checking functions for use in testing the CheckUserEvents // functionality #include "EF_General.h" #include "EF_Events.h" #include "EF_PostList.h" #include "EventCheckers.h" #include <ME218_C32.h> #include "EF_Timers.h" #include <stdio.h> #include "MainSM.h" #include "ADS12.h" // Needed for A/D pins // For Now: Include files for event actions #include "MotorActions.h" #include "LEDActions.h" #include "WaitFor.h" // Variable Definitions static unsigned char DebounceWaitTime = 30; static unsigned char PinWaitTime = 10; //************************************************************** EVENT FUNCTIONS ******************************************************************** //************************ START BUTTON HIT ********************************// boolean StartButtonHit(void) { static unsigned char LastInputStart = 0; unsigned char CurrentInputStart; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime;

CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if (DebounceTime >= DebounceWaitTime) { CurrentInputStart = PTIAD & BIT7HI; WaitFor(PinWaitTime); if ( (CurrentInputStart != 0) && (CurrentInputStart != LastInputStart) ) { EF_Event ThisEvent; ThisEvent.EventType = StartSelected; EF_PostList01(ThisEvent); ReturnVal = True; puts("Start Button Hit \n\r"); TimeOfLastSample = EF_Timer_GetTime(); } LastInputStart = CurrentInputStart; } return ReturnVal; } // ******************** LEFT HOLSTER REMOVED ********************// boolean LeftHolsterRemoved(void) { static unsigned char LastInput1 = 0; unsigned char CurrentInput1; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput1 = PTT & BIT0HI; WaitFor(PinWaitTime);

if ( (CurrentInput1 == 0) && (CurrentInput1 != LastInput1) ) { EF_Event ThisEvent; puts("Left Holster Removed \n\r"); ThisEvent.EventType = LeftRemoved; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput1 = CurrentInput1; } return ReturnVal; } // ******************** LEFT HOLSTER REPLACED ********************// boolean LeftHolsterReplaced(void) { static unsigned char LastInput1 = 0; unsigned char CurrentInput1; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput1 = PTT & BIT0HI; WaitFor(PinWaitTime); if ( (CurrentInput1 == 1) && (CurrentInput1 != LastInput1) ) { EF_Event ThisEvent; puts("Left Holster Replaced \n\r");

ThisEvent.EventType = LeftReturned; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput1 = CurrentInput1; } return ReturnVal; } // ******************** RIGHT HOLSTER REMOVED ********************// boolean RightHolsterRemoved(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT1HI; WaitFor(PinWaitTime); if ( (CurrentInput == 0) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Right Holster Removed \n\r"); ThisEvent.EventType = RightRemoved; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; }

LastInput = CurrentInput; } return ReturnVal; } // ******************** RIGHT HOLSTER REPLACED ********************// boolean RightHolsterReplaced(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT1HI; WaitFor(PinWaitTime); if ( (CurrentInput == 2) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Right Holster Replaced \n\r"); ThisEvent.EventType = RightReturned; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput = CurrentInput; } return ReturnVal; } /********** LEFT SHAKE INPUT EVENT **********/ boolean LeftShakeInput(void) {

static char LastInput; char CurrentInput; boolean ReturnVal = False; char ShakeState; short accelinput; accelinput = ADS12_ReadADPin(1); if (accelinput <= ACCEL_THRESH_LOW) { ShakeState = -1; } if (accelinput >= ACCEL_THRESH_HIGH) { ShakeState = 1; } CurrentInput = ShakeState; if ((CurrentInput == 1) && (CurrentInput != LastInput)) { EF_Event ThisEvent; ThisEvent.EventType = LeftShakeDetected; EF_PostList01(ThisEvent); ReturnVal = True; } LastInput = CurrentInput; return ReturnVal; } /********** RIGHT SHAKE INPUT EVENT **********/ boolean RightShakeInput(void) { static char LastInput; char CurrentInput; boolean ReturnVal = False; char ShakeState; short accelinput; accelinput = ADS12_ReadADPin(2); if (accelinput <= ACCEL_THRESH_LOW) {

ShakeState = -1; } if (accelinput >= ACCEL_THRESH_HIGH) { ShakeState = 1; } CurrentInput = ShakeState; if ((CurrentInput == 1) && (CurrentInput != LastInput)) { EF_Event ThisEvent; ThisEvent.EventType = RightShakeDetected; EF_PostList01(ThisEvent); ReturnVal = True; } LastInput = CurrentInput; return ReturnVal; } // ******************** LEFT LOWER LIMIT HIT ********************// boolean LeftScoreLowerLimit(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT4HI; WaitFor(PinWaitTime); if ( (CurrentInput == 16) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Left Lower Limit Hit \n\r");

ThisEvent.EventType = LeftLowerLimitHit; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput = CurrentInput; } return ReturnVal; } // ******************** LEFT UPPER LIMIT HIT ********************// boolean LeftScoreUpperLimit(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT5HI; WaitFor(PinWaitTime); if ( (CurrentInput == 32) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Left Upper Limit Hit \n\r"); ThisEvent.EventType = LeftUpperLimitHit; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; }

LastInput = CurrentInput; } return ReturnVal; }

// ******************** RIGHT LOWER LIMIT HIT ********************// boolean RightScoreLowerLimit(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT6HI; WaitFor(PinWaitTime); if ( (CurrentInput == 64) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Right Lower Limit Hit \n\r"); ThisEvent.EventType = RightLowerLimitHit; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput = CurrentInput; } return ReturnVal; }

// ******************** RIGHT UPPER LIMIT HIT ********************// boolean RightScoreUpperLimit(void) { static unsigned char LastInput = 0; unsigned char CurrentInput; boolean ReturnVal = False; static unsigned int TimeOfLastSample = 0; unsigned int CurTime; unsigned int DebounceTime; CurTime = EF_Timer_GetTime(); DebounceTime = CurTime - TimeOfLastSample; if(DebounceTime >= DebounceWaitTime) { CurrentInput = PTT & BIT7HI; WaitFor(PinWaitTime); if ( (CurrentInput == 128) && (CurrentInput != LastInput) ) { EF_Event ThisEvent; puts("Right Upper Limit Hit \n\r"); ThisEvent.EventType = RightUpperLimitHit; EF_PostList01(ThisEvent); ReturnVal = True; TimeOfLastSample = CurTime; } LastInput = CurrentInput; } return ReturnVal; }

EVENTCHECKERS.H // prototypes for test event checkers // Function Prototypes boolean StartButtonHit(void); boolean LeftHolsterRemoved(void); boolean LeftHolsterReplaced(void); boolean RightHolsterRemoved(void); boolean RightHolsterReplaced(void); boolean LeftShakeInput(void); boolean RightShakeInput(void); boolean LeftScoreLowerLimit(void); boolean LeftScoreUpperLimit(void); boolean RightScoreLowerLimit(void); boolean RightScoreUpperLimit(void); boolean TimerLowerLimit(void); boolean TimerUpperLimit(void); boolean AllReset(void); // #Includes #include <bitdefs.h> // #Defines // Port T #define TIMERUPPERLIMIT BIT2HI #define TIMERLOWERLIMIT BIT3HI #define LEFTSCORELIMITPIN BIT4HI #define LEFTSCORECYCLEPIN BIT5HI #define RIGHTSCORELIMITPIN BIT6HI #define RIGHTSCORECYCLEPIN BIT7HI // Port M // Port AD// digital inputs use PTIAD, outputs use PTAD #define LEFT_ACCEL_PIN 4 #define RIGHTHOLSTERPIN BIT6HI #define LEFTHOLSTERPIN BIT7HI // Port E

#define ACCEL_THRESH_HIGH 300 #define ACCEL_THRESH_LOW 100

MOTOR AND FAN ACTIONS


MOTORACTIONS.C // These functions determine the actuation of the motors and the fan #include "MotorActions.h" #include <ME218_C32.h> #include "ADS12.h" // ****************** LEFT SCORE ******************// /* START LEFT SCORE */ void StartLeftScore(void) { PTM |= LEFTDIRBITHI; //Set Direction to Raise Score PTM |= LEFTENBITHI; //Turn on Motor } /* STOP LEFT SCORE */ void StopLeftScore(void) { PTM &= LEFTENBITLO; //Turn off Motor } /* REVERSE LEFT SCORE */ void ResetLeftScore(void) { PTM &= LEFTDIRBITLO; // Set Direction to Lower Score PTM |= LEFTENBITHI; // Turn on Motor } // ****************** RIGHT SCORE ******************// /* START RIGHT SCORE */ void StartRightScore(void) { PTM |= RIGHTDIRBITHI; //Set Direction to Raise Score PTM |= RIGHTENBITHI; //Turn on Motor } /* STOP RIGHT SCORE */ void StopRightScore(void) {

PTM &= RIGHTENBITLO; //Turn off Motor } /* REVERSE RIGHT SCORE */ void ResetRightScore(void) { PTM &= RIGHTDIRBITLO; // Set Direction to Lower Score PTM |= RIGHTENBITHI; // Turn on Motor } //***************** FAN ACTIONS ************************ void TurnOnFan(void) { PTAD |= BIT6HI; } void TurnOffFan(void) { PTAD &= BIT6LO; } MOTORACTIONS.H // ****************** LEFT SCORE ******************// void StartLeftScore(void); void StopLeftScore(void); void ResetLeftScore(void); // ****************** RIGHT SCORE ******************// void StartRightScore(void); void StopRightScore(void); void ResetRightScore(void); // ****************** FAN ACTIONS ******************// void TurnOnFan(void); void TurnOffFan(void); // ****************** FAN ACTIONS ******************//

short ReadDifficulty(void); // BIT DEFINITIONS // Port M #define LEFTDIRBITHI BIT2HI #define LEFTDIRBITLO BIT2LO #define LEFTENBITHI BIT3HI #define LEFTENBITLO BIT3LO #define RIGHTDIRBITHI BIT4HI #define RIGHTDIRBITLO BIT4LO #define RIGHTENBITHI BIT5HI #define RIGHTENBITLO BIT5LO

READ DIFFICULTY
//***************** READ DIFFICULTY ************************ short ReadDifficulty(void) { short difficulty; difficulty = ADS12_ReadADPin(0); return difficulty; }

LED ACTIONS
LEDACTIONS.C // Include necessary header files #include "LEDActions.h" #include <ME218_C32.h> #include <stdio.h> #include "ADS12.h" #include "EF_Timers.h" #include "WaitFor.h" // ******************************************* START OF INDIVIDUAL SHIFT REGISTER FUNCTIONS ***********************************************// unsigned int WaitTime = 0; unsigned int FlashWaitTime = 200; int NumberOfFlashes = 7; // BOTH SW IN HOLSTERS void BothInLED(void) { // This will turn on the Left and Right red LEDs // To do this outputs 0 and 2 are pulled high // 0 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 2 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime);

PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // LEFT SW OUT void LeftOutLED(void) { // This will turn on the Left green and Right red LEDs // To do this outputs 1 and 2 are pulled high // 0 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI;

WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // RIGHT SW OUT void RightOutLED(void) { // This will turn on the Left red and Right green LEDs // To do this outputs 0 and 3 are pulled high

// 0 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO;; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime);

PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // BOTH SW OUT void BothOutLED(void) { // This will turn on the Left green and Right green LEDs // To do this outputs 1 and 3 are pulled high // 7 is also high to turn on the Start LED // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime);

PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 HI PTAD |= DATABITHI;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // ALL OFF void AllOffLED(void) { // This will turn on all of the LEDs off // To do this all pins are low // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO;

WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // LEFT GREEN void LeftGreenLED(void) {

// This will turn all LEDS off, except Left Green // To do this all pins are low // 0 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // RIGHT GREEN void RightGreenLED(void) { // This will turn all LEDs off, except right green // To do this all pins are low // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO;

WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // Left Player GOOD OUTCOME void LeftGoodOutcomeLED(void) { // This will turn all LEDs off, the good outcome LED // To do this all pins are low, except pins 1 and 5 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // Right Player GOOD OUTCOME void RightGoodOutcomeLED(void)

{ // This will turn all LEDs off, the good outcome LED // To do this all pins are low, except pins 3 and 5 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 HI PTAD |= DATABITHI;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // Left MEDIUM OUTCOME void LeftMediumOutcomeLED(void) { // This will turn all LEDs off, except the medium outcome LED (5) and Left Holster (1) // To do this all pins are low, except pins 1 and 4 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW

PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // Right MEDIUM OUTCOME void RightMediumOutcomeLED(void) { // This will turn all LEDs off, the medium outcome LED // To do this all pins are low, except pins 3 and 4 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // LeftBADOUTCOME

void LeftBadOutcomeLED(void) { // This will turn all LEDs off, the bad outcome LED // To do this all pins are low, except pins 1 and 6 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW

PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // RightBADOUTCOME void RightBadOutcomeLED(void) { // This will turn all LEDs off, the bad outcome LED // To do this all pins are low, except pins 3 and 6 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO;

PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // GOODOUTCOME void GoodOutcomeLED(void) { // This will turn all LEDs off, except the good outcome LED // To do this all pins are low, except pin 5 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW

PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); }

// MEDIUMOUTCOME void MediumOutcomeLED(void) { // This will turn all LEDs off, except the medium outcome LED // To do this all pins are low, except pin 4 // 0 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 5 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // BADOUTCOME void BadOutcomeLED(void) { // This will turn all LEDs off, except the bad outcome LED // To do this all pins are low, except pin 6 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW

PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // TURNONRYG void TurnOnRYG(void) { // This will turn all LEDs off, except the bad outcome LED // To do this all pins are low, except pin 6 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 5 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); }

// TURNONRY void TurnOnRY(void) { // This will turn all LEDs off, except the bad outcome LED // To do this all pins are low, except pin 6 // 0 LO PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 1 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 2 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 3 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 4 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime);

// 5 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 6 HI PTAD |= DATABITHI; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // 7 LOW PTAD &= DATABITLO; PTAD &= SHIFTCLOCKBITLO; WaitFor(WaitTime); PTAD |= SHIFTCLOCKBITHI; WaitFor(WaitTime); // REG CLOCK PTAD &= OUTPUTLATCHBITLO; WaitFor(WaitTime); PTAD |= OUTPUTLATCHBITHI; WaitFor(WaitTime); } // FLASH LEFT RED void FlashLeftRed(void) { // Init State before this is Left Red and Right Green // Need to cycle between // 1. Only Right Green On // 2. Left Red Right Green int i; for (i=0; i<3; i++) { RightGreenLED(); WaitFor(FlashWaitTime);

RightOutLED(); WaitFor(FlashWaitTime); } } // FLASH RIGHT RED void FlashRightRed(void) { // Init State before this is Left Green and Right Red // Need to cycle between // 1. Only Left Green On // 2. Left Green Right Red int i; for (i=0; i<3; i++) { LeftGreenLED(); WaitFor(FlashWaitTime); LeftOutLED(); WaitFor(FlashWaitTime); } } // FLASH BOTH RED void FlashBothRed(void) { // Init State before this is Left Red and Right Red // Need to cycle between // 1. All Off // 2. Left Red Right Red int i; for (i=0; i<3; i++) { AllOffLED(); WaitFor(FlashWaitTime); BothInLED(); WaitFor(FlashWaitTime); } } // FLASH LEFT GOOD OUTCOME void FlashLeftGoodOutcome(void) {

// Need to cycle between // 1. LeftGoodOutcome // 2. GoodOutcome int i; for (i=0; i<NumberOfFlashes; i++) { LeftGoodOutcomeLED(); WaitFor(FlashWaitTime); GoodOutcomeLED(); WaitFor(FlashWaitTime); } } // FLASH LEFT MEDIUM OUTCOME void FlashLeftMediumOutcome(void) { // Need to cycle between // 1. LeftMediumOutcome // 2. MediumOutcome int i; for (i=0; i<NumberOfFlashes; i++) { LeftMediumOutcomeLED(); WaitFor(FlashWaitTime); MediumOutcomeLED(); WaitFor(FlashWaitTime); } } // FLASH LEFT BAD OUTCOME void FlashLeftBadOutcome(void) { // Need to cycle between // 1. LeftBaddOutcome // 2. BadOutcome int i; for (i=0; i<NumberOfFlashes; i++) { LeftBadOutcomeLED(); WaitFor(FlashWaitTime); BadOutcomeLED(); WaitFor(FlashWaitTime); }

LEDACTIONS.H // Includes #include <ME218_C32.h> // Definitions #define OUTPUTLATCHBITHI BIT3HI #define OUTPUTLATCHBITLO BIT3LO #define SHIFTCLOCKBITHI BIT4HI #define SHIFTCLOCKBITLO BIT4LO #define DATABITHI BIT5HI #define DATABITLO BIT5LO // Function Prototypes void BothInLED(void); void LeftOutLED(void); void RightOutLED(void); void BothOutLED(void); void AllOffLED(void); void LeftGreenLED(void); void RightGreenLED(void); void LeftGoodOutcomeLED(void); void LeftMediumOutcomeLED(void); void LeftBadOutcomeLED(void); void RightGoodOutcomeLED(void); void RightMediumOutcomeLED(void); void RightBadOutcomeLED(void); void GoodOutcomeLED(void); void MediumOutcomeLED(void); void BadOutcomeLED(void); void FlashLeftRed(void); void FlashRightRed(void); void FlashBothRed(void); void FlashLeftGoodOutcome(void); void FlashLeftMediumOutcome(void);

void FlashLeftBadOutcome(void); void FlashRightGoodOutcome(void); void FlashRightMediumOutcome(void); void FlashRightBadOutcome(void); void TurnOnRYG(void); void TurnOnRY(void);

Das könnte Ihnen auch gefallen