E215     11 1116   

Lab KK16-30 Two Motor s, Part 1
xx points


ELT 215

Back to Main Page


Write a program that will create the following sequence, using a function named TwoMotor s:
  1. Motor A goes on for a length of time determined by switches 5, 4, and 3.
  2. Motor A goes off.
  3. Motor B goes on for a length of time determined by switches 2, 1, and 0.
  4. Motor B goes off.
  5. Both motors stay off for a length of time determined by switches 7 and 6.
  6. The above sequence then repeats indefinitely.
Motor A (a miniature DC motor) will be connected to LED 1 and Motor B will be connected to LED 0.

The TwoMotors function should operate as follows:
  1. Two numbers, a and b are received from the main program. They are both unsigned characters.  a is the time that Motor A stays on, and b is the time that Motor B stays on.
  2. The TwoMotors function won't be returning any number.
  3. a and b are both multiplied by 30, so as to obtain sufficiently long delays.
  4. Motor A is turned on for the amount of time specified by a.
  5. Motor A is turned off.
  6. Motor B is turned on for the amount of time specified by b.
  7. Motor B is turned off.
  8. The function returns to the main program.
Directions
  1. If necessary, download a copy of the template file by clicking here.
  2. Right after #pragma code, put a function protytype for TwoMotors
    • void TwoMotors(unsigned char a, unsigned char b);
  3. Immediately after this, put two define statements as follows:
    • #define MOTORA LED1
    • #define MOTORB LED0
  4. At the top of the main program (just before InitPorts( ) ), declare the following variables as unsigned char:
    • mtra      Motor A run time.
    • mtrb      Motor B run time.
    • rest        Amount of time the motors rest before the cycle repeats.
  5. At the beginning of the primary loop, convert switches 7 and 6 to a number between 0 and 3 and put this number into rest.
  6. Convert switches 5, 4, and 3 to a number between 0 and 7, and put it into mtra.
  7. Convert switches 2, 1, and 0 to a number between 0 and 7, and put it into mtrb.
  8. Send mtra and mtrb to the TwoMotors function.
  9. Multiply rest by 80.
  10. Delay for rest * 10 ms.
  11. Right after the END OF MAIN PROGRAM comment line, put the TwoMotors function.


 
Back to Main Page