SASSI Sam
Newbie level 6
- Joined
- Nov 18, 2013
- Messages
- 11
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,356
Hi every body, this code with MikroC to drive a DC Motor in 2 directions
void main() {
short duty = 0; //initial value for duty
TRISC = 0x00; //PORTC as output
TRISB = 0x00; //PORTB as output
portb = 0x00; // init
PWM1_Init(5000); //Initialize PWM1
PWM1_Start(); //start PWM1
PWM1_Set_Duty(duty); //Set current duty for PWM1
while (1) // endless loop
{
PORTB = 0x01; // 1st direction given through RB0
Delay_ms(10);
duty = 255; //max duty
PWM1_Set_Duty(duty);
delay_ms(5000);
PWM1_STOP();
portb=0;
delay_ms(5000); //wait until Motor stop before changing direction..
PORTB = 0x02; // 2nd direction given through RB1
Delay_ms(10);
duty = 255; //max duty
PWM1_Set_Duty(duty);
delay_ms(5000);
PWM1_STOP();
}
}
void main() {
short duty = 0; //initial value for duty
TRISC = 0x00; //PORTC as output
TRISB = 0x00; //PORTB as output
portb = 0x00; // init
PWM1_Init(5000); //Initialize PWM1
PWM1_Start(); //start PWM1
PWM1_Set_Duty(duty); //Set current duty for PWM1
while (1) // endless loop
{
PORTB = 0x01; // 1st direction given through RB0
Delay_ms(10);
duty = 255; //max duty
PWM1_Set_Duty(duty);
delay_ms(5000);
PWM1_STOP();
portb=0;
delay_ms(5000); //wait until Motor stop before changing direction..
PORTB = 0x02; // 2nd direction given through RB1
Delay_ms(10);
duty = 255; //max duty
PWM1_Set_Duty(duty);
delay_ms(5000);
PWM1_STOP();
}
}