Program 6-4 Write a structured C program that allows the motor to run clockwise
ID: 3590929 • Letter: P
Question
Program 6-4 Write a structured C program that allows the motor to run clockwise for a certain period time. Stop for some time, then rotate counter clockwise for a certain period of time, stops and after some time continue to repeat the cycle. Each of the action should be a function and your main program will simply call the functions See Figure 6-4 for changing the direction of rotation of DC motor using D2n V23105 DPDT Relay PA1 PAO Motor Operation 0 0Stops or breaks 0 1Stops or breaks Clockwise 1 1Counter-Clockwise NOTE: If the lab kit does not have D2n V23105 DPDT Relay, please use two LEDs to indicate the output status of PA1 and PA0, as simulation. + SV S2 51 nRD 16 131 4 PAS 0 turn motor On OfF 20PAD to change direction PAO Fiqure 6-4. Changing the direction of rotation of DC motorExplanation / Answer
save the file in motor.c, compile and run. Modify the code as per your register variable PA0,PA1.
You can change for loop iteration count as per your requirement.
Test in Lab and if you find any issue put a comment.
Note: Please like the answer
/*****************************/
/*
* motor.c
*
* Created on: 13-Oct-2017
* Author:
*/
#include <stdio.h>
struct Rotate{
unsigned int PA0:1; //assigning 1 bit value
unsigned int PA1:1; //assigning 1 bit value
}rot; //global structure variable used in clockwise() & counterclockwise
void delay(); //function prototype
void clockwise(); //function prototype
void counterclockwise(); //function prototype
int main()
{
rot.PA0=0;
rot.PA1=0; //setting rotation variable to stop mode
int i;
while(1) // continuous loop to repeat process
{
for(i=0;i<100;i++) //change the increment count as per your requirement
{
clockwise(); //motor clockwise rotation for 100 cycle
}
for(i=0;i<50;i++)
{
delay(); //delay for 50 cycle
}
for(i=0;i<100;i++)
{
counterclockwise(); //motor counter clockwise rotation for 100 cycle
}
for(i=0;i<50;i++)
{
delay(); //delay for 50 cycle
}
}
return 0;
}
void delay()
{
rot.PA0=1;
rot.PA1=0;
}
void clockwise()
{
rot.PA0=0;
rot.PA1=1;
}
void counterclockwise()
{
rot.PA0=1;
rot.PA1=1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.