Hello I have this code
This is MikroC for programing of a PIC microcontroller.The goal is to control a stepper motor by 2 push buttons.The push buttons are connected to pins PD0 and PD1 and the 4 pins of the stepper motor are connected to pins PB4,PB5,PB6 and PB7.Can anyone test if this is a bug because the stepper motor doesnt rotate at all , and the buttons are not working and I dont understand where I am wrong.I am using PicsimLab so if any of you has spare time and wants to answer reply!Thanks!
C:
void turn(int direction,int speed)
{
int i;
if(direction==0)
{
for(i==0;i<50;i++)
{
PORTB = 0b10010000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b11000000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b01100000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b00110000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
}
}
else if(direction==1)
{
for(i==0;i<50;i++)
{
PORTB = 0b00110000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b01100000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b11000000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
PORTB = 0b10010000;
for(i==0;i<speed;i++)
{
delay_ms(1);
}
}
}
}
void main() {
TRISB = 0b00001111;
TRISD = 0b00000011;
while(1)
{
if(PORTB.F0)
{
turn(1,10);
}
if(PORTB.F1)
{
turn(0,20);
}
delay_ms(1000);
}
}