//----------------------------------------------------------------- // Program: PBot_BOB-A_VC6.osc // Function: Lesson A. LED Test // Designer: Phil Malone, phil@philbot.com www.philbot.com // Details: http://www.philbot.com // // Device: Bot On a Board (BOB) V1.1 // Compiler: OOPic 6.x // Motor Drive: SN75410 With Tamiya Gearbox // Quad encoder:OPB610 // // // Version Date Comment // ------- --------- ------- // 1.00 8/8/2005 Original //----------------------------------------------------------------- //------------------------------------------------------- // BOB I/O Port definitions //------------------------------------------------------- Const IO_LINE_LEFT = 3; // Left Fairchild Analog Reflective sensor Const IO_LINE_MID = 2; // Middle Fairchild Analog Reflective sensor Const IO_LINE_RIGHT = 1; // Right Fairchild Analog Reflective sensor Const IO_PROXIMITY_LEFT = 8; // Left Sharp Digital Prox sensor Const IO_PROXIMITY_RIGHT = 9; // Right Sharp Digital Prox sensor Const IO_PROXIMITY_REAR = 10; // Rear Sharp Digital Prox sensor Const IO_LED1 = 12; // General Purpose LED 1 Const IO_LED2 = 13; // General Purpose LED 2 Const IO_LED3 = 14; // General Purpose LED 3 Const IO_LED4 = 15; // General Purpose LED 4 Const IO_LED_GROUP = 1; // LED I/O Group 1 (Lines 8-15) Const IO_LED_NIBBLE = 1; // LED I/O High Nible (Lines 12-15) Const IO_MOTOR_LEFT_FWD = 24; // Left Motor H-Bridge High Const IO_MOTOR_LEFT_REV = 25; // Left Motor H-Bridge Low Const IO_MOTOR_LEFT_PWM = 18; // Left Motor PWM control Const IO_MOTOR_RIGHT_FWD = 26; // Right Motor H-Bridge High Const IO_MOTOR_RIGHT_REV = 27; // Right Motor H-Bridge Low Const IO_MOTOR_RIGHT_PWM = 17; // Right Motor PWM control Const IO_ENCODER_LEFT_FRONT = 31; // Left A I/R optical interruptor Const IO_ENCODER_LEFT_BACK = 30; // Left B I/R optical interruptor Const IO_ENCODER_RIGHT_FRONT = 29; // Right A I/R optical interruptor Const IO_ENCODER_RIGHT_BACK = 28; // Right B I/R optical interruptor //----------------------------------------------------------------- // Constants, used for default values //----------------------------------------------------------------- Const CLOCK_PRESCALE = 5; // Divide Clock by 6 Const FIVE_SECONDS = 50; // 50 tenths Const SLOW_PWM = 2; // Maximum PWM divide for 312KHz Const PWM_PERIOD = 100; // Maximum PWM +/- range Const OBSTACLE = cvLow; // Eye Sees Obstacle Const CLEAR = cvHigh; // Eye Does Not see Obstacle //----------------------------------------------------------------- // User Objects. Use these to access BOB hardware. //----------------------------------------------------------------- oCountDownO ActionTimer = New oCountDownO; // User Timer // LED Object (accessed as group of 4 bits) oDIO4 LEDs = New oDIO4; // Driver for LEDs //----------------------------------------------------------------- // General Variables //----------------------------------------------------------------- //----------------------------------------------------------------- // BOB Main Program //----------------------------------------------------------------- Void Main(Void) { // Always set up the required IO first. SetupIO(); // Wait for 5 second "Start Up" to elapse While(ActionTimer.NonZero); // Cycle the 4 LEDs through all 16 states While(cvTrue) { LEDs.Value += 1 ; // Increment LED value WaitTenths(3); // Wait 3/10th of a second before continuing. } } //################################################################# // These are the standard functions that All lessons have //################################################################# //----------------------------------------------------------------- // SetupIO() // Configure all the IO Objects here //----------------------------------------------------------------- Void SetupIO( Void ) { // -------------------------------- // setup the ActionTimer Timer for 1/10th Second ticks // Preload counter with 5 second delay // -------------------------------- ActionTimer.PreScale = CLOCK_PRESCALE; ActionTimer.ClockIn.Link(ooPIC.Hz60); ActionTimer = FIVE_SECONDS; ActionTimer.Operate = cvTrue; // -------------------------------- // setup the LED Drivers // -------------------------------- LEDs.IOGroup = IO_LED_GROUP ; LEDs.Nibble = IO_LED_NIBBLE ; LEDs.Direction = cvOutput ; // Turn All LEDs on. LEDs.Value = 15 ; } //----------------------------------------------------------------- // WaitTenths(Byte Tenths) // This function uses the Action timer to wait for a number // of "tenths" of a second. // This method is more accurate than the OOPic.Delay function //----------------------------------------------------------------- Void WaitTenths(Byte Tenths) { // Set timer ActionTimer = Tenths; While(ActionTimer.NonZero); } //################################################################# // Lesson specific functions //#################################################################