1 //#define HARNESS
  2 //#define SPITESTHARNESS
  3 //#define TESTTAPE
  4 
  5 #include <hidef.h>      /* common defines and macros */
  6 #include <mc9s12e128.h>     /* derivative information */
  7 #include <stdio.h>
  8 #include <ADS12.h>
  9 #include <stdlib.h>
 10 #include <S12E128bits.h> /* E128 bit definitions  */
 11 #include <bitdefs.h> /* BIT0HI, BIT0LO....definitions */
 12 #include <stdlib.h>
 13 
 14 #include "Movement.h"
 15 #include "Sensors.h"
 16 #include "InitPorts.h"
 17 #include "PWM.h"
 18 
 19 
 20 
 21 #pragma LINK_INFO DERIVATIVE "SampleS12"
 22 
 23 
 24 //Checks Tape sensors
 25 int CheckTape(char Sensor)
 26 {
 27 
 28   //The Tape Sensor Numbers correspond to positions on a keypad, however we changed bot orientation,
 29   // so 1,2,3 are now in front
 30 
 31 
 32   //           Front
 33   //           3 2 1
 34   //     Left  6 5 4  Right
 35   //           9 8 7
 36   //           Back
 37 
 38   switch (Sensor)
 39   {
 40 
 41     case 3: //Back Right Sensor
 42       //printf("3 is called\r\n");
 43       if((PTS & BIT2HI) == 0)
 44         return 0;
 45       else
 46         return 1;
 47       break;
 48 
 49     case 2: //Back Middle Sensor
 50       //printf("2 is called\r\n");
 51       if((PTP & BIT0HI) == 0)
 52         return 0;
 53       else
 54         return 1;
 55       break;
 56 
 57     case 1: //Back Left Sensor
 58       //printf("1 is called\r\n");
 59       if((PTP & BIT5HI) == 0)
 60         return 0;
 61       else
 62         return 1;
 63       break;
 64 
 65     case 5: //Center - Center Sensor
 66       //printf("5 is called\r\n");
 67       if((PTS & BIT3HI) == 0)
 68         return 0;
 69       else
 70         return 1;
 71       break;
 72 
 73     case 9: //Front Right
 74       //printf("9 is called\r\n");
 75       if((PTIAD & BIT1HI) ==0)
 76         return 0;
 77       else
 78         return 1;
 79       break;
 80 
 81     case 8: //Front Middle Sensor
 82       //printf("8 is called\r\n");
 83       if((PTIAD & BIT2HI) ==0)
 84         return 0;
 85       else
 86         return 1;
 87       break;
 88 
 89     case 7: //Front Left Sensor
 90       //printf("7 is called\r\n");
 91       if((PTIAD & BIT3HI) ==0)
 92         return 0;
 93       else
 94         return 1;
 95       break;
 96 
 97 
 98   }
 99 
100 
101 }
102 
103 
104 char CheckIR(void)
105 {
106   //printf("3 is called\r\n");
107   if(ADS12_ReadADPin(0x07) > 200)
108   if((PTIAD & BIT5HI) == 1)  // see IR
109     return 1;
110   else
111     return 0;
112 }
113 
114 
115 
116 /////////////////////Test Harness///////////////////////////
117 
118 #ifdef TESTTAPE
119 void main(void)
120 {
121   InitPorts();
122   InitPWM();
123   (void)printf("Sensor:  1  2  3  5  7  8  9\n\r");
124   while(1)
125   {
126     (void)printf(" Value:  %i  %i  %i  %i  %i  %i  %i\r", CheckTape(1), CheckTape(2), CheckTape(3), CheckTape(5), CheckTape(7), CheckTape(8), CheckTape(9));
127   }
128 
129 }
130 #endif