Write
a program that will create the following sequence, using a function
named TwoMotor s:
- Motor A goes on for a length of time determined by
switches 5, 4, and 3.
- Motor A goes off.
- Motor B goes on for a length of time determined by
switches 2, 1, and 0.
- Motor B goes off.
- Both motors stay off for a length of time determined by
switches 7 and 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:
- 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.
- The TwoMotors
function won't be returning any number.
- a and b are both multiplied by 30, so as
to obtain sufficiently long delays.
- Motor A is turned on for the amount of time specified
by a.
- Motor A is turned off.
- Motor B is turned on for the amount of time specified
by b.
- Motor B is turned off.
- The function returns to the main program.
Directions
- If necessary, download a copy of the template file by
clicking here.
- Right after #pragma code,
put a function protytype for TwoMotors
- void TwoMotors(unsigned
char a, unsigned char b);
- Immediately after
this, put two define statements as follows:
- #define MOTORA LED1
- #define MOTORB LED0
- 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.
- 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.
- Convert switches 5, 4, and 3 to a number between 0 and 7,
and put it into mtra.
- Convert switches 2, 1, and 0 to a number between 0 and 7,
and put it into mtrb.
- Send mtra and mtrb to the TwoMotors function.
- Multiply rest by
80.
- Delay for rest *
10 ms.
- Right after the END OF MAIN PROGRAM comment line, put the TwoMotors function.
|