Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Basically I have to run a MERCVRY MOTOR SM-42BYG01125 with 2 H-bridges and a mic

ID: 3547653 • Letter: B

Question

Basically I have to run a MERCVRY MOTOR SM-42BYG01125 with 2 H-bridges and a microcontroller. I want the first FOR loop that runs it forward 40 steps to run first then once its finished run the 2nd for loop when i=40 for another 40 steps then start over and continue but I just have no experience with this. Been in the lab for 13.5 hour straight and I can only get the motor to go back and forth in one step not 40


here is the code, please post explanations so I know how to manipulate it thanks


CODE;


#include <18f1320.h>  /*tell compiler we are using a 18f1320.h microcontroller */

#fuses INTRC_IO,NOLVP,NOWDT,PUT

#use delay (clock=4000000)

//LED lights

#define GREEN_LED PIN_A3

#define YELLOW_LED PIN_B0

#define RED_LED PIN_B1

#define FOUR PIN_A6

#define THREE PIN_A7

#define TWO PIN_B2

#define ONE PIN_B3

#define STEPS (80)

//methods


int main(){

int i;

i==1;

while (true){

for (i>0; i<40;){


Output_low(PIN_A3); //led green initiate forward rotation

Output_high(THREE);

Output_high(ONE);

Output_low(TWO);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_A3);

//turn off led


Output_low(PIN_A3); //led green

Output_high(THREE);

Output_low(FOUR);

Output_low(ONE);

Output_high(TWO);

Delay_ms(50);

Output_high(PIN_A3);



Output_low(PIN_A3); //led green

Output_high(FOUR);

Output_high(TWO);

Output_low(ONE);

Output_low(THREE);

Delay_ms(50);

Output_high(PIN_A3);




Output_low(PIN_A3); //led green

Output_high(FOUR);

Output_low(TWO);

Output_low(THREE);

Output_high(ONE);

Delay_ms(50);

Output_high(PIN_A3);


i=i+1

}




for (i>40;){

Delay_ms(350);

Output_low(PIN_B1); //led red initiate reverse rotation

Output_high(FOUR);

Output_low(ONE);

Output_low(THREE);

Output_high(TWO);

Delay_ms(50);

Output_high(PIN_B1);

//turn off led


Output_low(PIN_B1); //led red

Output_high(THREE);

Output_low(FOUR);

Output_low(ONE);

Output_high(TWO);

Delay_ms(50);

Output_high(PIN_B1);



Output_low(PIN_B1); //led red

Output_high(ONE);

Output_high(THREE);

Output_low(FOUR);

Output_low(TWO);

Delay_ms(50);

Output_high(PIN_B1);




Output_low(PIN_B1); //led red

Output_high(FOUR);

Output_high(ONE);

Output_low(TWO);

Output_low(THREE);

Delay_ms(50);

Output_high(PIN_B1);


}}}

Explanation / Answer

#include <18f1320.h> /*tell compiler we are using a 18f1320.h microcontroller */

#fuses INTRC_IO, NOLVP, NOWDT, PUT

#use delay(clock = 4000000)

//LED lights

#define GREEN_LED PIN_A3

#define YELLOW_LED PIN_B0

#define RED_LED PIN_B1

#define FOUR PIN_A6

#define THREE PIN_A7

#define TWO PIN_B2

#define ONE PIN_B3

#define STEPS (80)

//methods


int main(){

int i;

i == 1;

while (true){

for (i>0; i<40;){


Output_low(PIN_A3); //led green initiate forward rotation

Output_high(ONE);

Output_low(TWO);

Output_low(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_A3);

//turn off led


Output_low(PIN_A3); //led green

Output_low(ONE);

Output_high(TWO);

Output_low(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_A3);



Output_low(PIN_A3); //led green

Output_low(ONE);

Output_low(TWO);

Output_high(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_A3);




Output_low(PIN_A3); //led green

Output_low(ONE);

Output_low(TWO);

Output_low(THREE);

Output_high(FOUR);

Delay_ms(50);

Output_high(PIN_A3);


i = i + 1

}




for (i>40;){

Delay_ms(350);

Output_low(PIN_B1); //led red initiate reverse rotation

Output_low(ONE);

Output_low(TWO);

Output_low(THREE);

Output_high(FOUR);

Delay_ms(50);

Output_high(PIN_B1);

//turn off led


Output_low(PIN_B1); //led red

Output_low(ONE);

Output_low(TWO);

Output_high(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_B1);



Output_low(PIN_B1); //led red

Output_low(ONE);

Output_high(TWO);

Output_low(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_B1);




Output_low(PIN_B1); //led red

Output_high(ONE);

Output_low(TWO);

Output_low(THREE);

Output_low(FOUR);

Delay_ms(50);

Output_high(PIN_B1);


}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote