Computer Science Canada does this program loop forever? |
Author: | cwlvc [ Sat Dec 13, 2008 6:22 pm ] |
Post subject: | does this program loop forever? |
#include <pic.h> /* cRandom.c Hardware Notes: Outputs: RA0 - Connected to D0 Input for Motor 1 (left wheel) RA1 - Connected to D1 Input for Motor 1 RC0 - Connected to D2 Input for Motor 2 (right wheel) RC1 - Connected to D3 Input for Motor 2 Inputs: NONE Anson Mo, Harnish December 16, 2008 */ // ---------------------------------------------------------- //setup //config statement __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BORDIS & IESODIS & FCMDIS); //declare variables int i, j; char counter; // ---------------------------------------------------------- // mainline of cRandom.c main() { CMCON0 = 7; //Turn off all Comparators ANSEL = 0; //Teach all ports to be digital TRISA = 0b001000; // Teach all PORTA to be outputs except RA3(input) TRISC = 0b000000; // Teach all PORTC to be outputs. while (1==1) { // move robot forward by making the left motor and right motor move in direct A PORTA = 0b000001; // Teach RA0 to be on consequently making D0 of the left motor on and thus // making it turn in Direction A (forward). PORTC = 0b000001; // Teach RC0 to be on consequently making D0 of the right motor on and thus // making it turn in Direction A (forward) for(counter = 0; counter<10; counter++)// repeat the code 10 times to loop 500 milliseconds 10 times { for (i = 0; i < 255; i++) for (j = 0; j < 129; j++);//initiate a delay of 5 seconds } // spin robot left by making left motor spin backwards(D1 on) and right motor spin forwards(D0 on) PORTA = 0b000010; // Teach RA0 to be oFF and RA1 to be on consequently // making D1 of the left motor on and turning in direction B (backwards) PORTC = 0b000001; // Teach RC0 to be on consequently making D0 of the right motor on // and making it turn in Direction A (Forward) for(counter = 0; counter<9; counter++)// repeat the code 9 times to loop 250 milliseconds 9 times { for (i = 0; i < 255; i++) for (j = 0; j < 64; j++);//initiate a delay of 2.25 seconds } // move robot backwards by making left motor and right motor move in direction B PORTA = 0b000010; // Teach RA0 to be oFF and RA1 to be on consequently // making D1 of the left motor on and turning in direction B (backwards) PORTC = 0b000010; // Teach RC0 to be oFF and RC1 to be on consequently // making D1 of the right motor on and turning in direction B (backwards) for(counter = 0; counter<9; counter++)// repeat the code 9 times to loop 500 milliseconds 9 times { for (i = 0; i < 255; i++) for (j = 0; j < 129; j++);//initiate a delay of 4.5 seconds } // spin robot right by making left motor spin forwards(D0 on) and right motor spin backwards(D1 on) PORTA = 0b000001; // Teach RA0 to be on consequently making D0 of the left MOTOR // motor on and making it turn in Direction A (Forward) PORTC = 0b000010; // Teach RC0 to be oFF and RC1 to be on consequently // making D1 of the right motor on and turning in direction B (backwards) for(counter = 0; counter<15; counter++)// repeat the code 15 times to loop 250 milliseconds 15 times { for (i = 0; i < 255; i++) for (j = 0; j < 64; j++);//initiate a delay of 3.75 seconds } // spin robot right by making left motor spin forwards(D0 on) and right motor spin backwards(D1 on) PORTA = 0b000000; // Teach all RA ports to be be off consequently setting the D0 and D1 of the left motor to off. // This will make the motor stop PORTC = 0b000000; // Teach all RC ports to be be off consequently setting the D0 and D1 of the right motor to off. // This will make the right motor stop for(counter = 0; counter<4; counter++)// repeat the code 4 times to loop 500 milliseconds 4 times { for (i = 0; i < 255; i++) for (j = 0; j < 129; j++);//initiate a delay of 2 seconds } }//elihw } // End cRandom.c |