Main.c
#include <hidef.h> /* common defines and macros */
#include <mc9s12e128.h> /* derivative information */
#include <stdio.h>
#include <stdlib.h>
#include <S12E128bits.h> /*E128 bit definitions */
#include <bitdefs.h> /* BIT0HI, BIT0LO definitions */
#include <TIMERS12.h>
#include "MotorControl.h"
#include "LineFollow.h"
#include "IRbeacon.h"
#include "BallDrop.h"
#include "Startup.h"
#include "GoingPlaces.h"
#pragma LINK_INFO DERIVATIVE "SampleS12"
void main(void)
{
char Side;
TMRS12_Init(TMRS12_RATE_2MS); //initiates timer
PWMinit(); //initiates PWM
PortInit(); //initiates ports
BeaconInit(); //initiates beacon
BallDropInit(); //initiates ball drop
while(PTT & BIT5HI); //wait for flash
delay(10); //delay for flash to end
TimerInit(); //start 2 min timer
FindBeacon(50, RIGHT); //finds 50 beacon
Side = AorB(50); //when hits line, decides if on side A or B
FirstDispenser(Side); //goes towards the dispenser first time
DispTo3(Side,0); //goes to goal 3
G3ToDisp(Side); //goes back to dispenser
DispTo3(Side,1); //goes to goal 3, backing up when hits line
G3ToDisp(Side); //goes back to dispenser
DispTo1(Side); //goes to goal 1
G1ToDisp(Side); //goes back to dispenser
DispTo1(Side); //goes to goal 1
return; //game ends unless 2 minute timer activates first
}