#include <htc.h>
#include <pic.h>
__CONFIG(RC & WDTDIS & PWRTEN & BOREN & LVPEN & WRTEN & DEBUGEN & UNPROTECT);
int x, y;
delay(int xvalue,int yvalue)
{
for(x = 0; x < xvalue; x++)
for(y = 0; y < yvalue; y++);
return;
}
main()
{
PORTA = 0x00; //Clear port A
PORTB = 0x00; //Clear port B
PCFG2 = 1;
PCFG1 = 1;
TRISA = 0xff; //Set port A as input
TRISB = 0; //set port B as output
while(1) // Loop forever
{
if(RA0 == 1)
{
while(RA0 == 1) // If push button 0 is pressed
{
RB0 = 1; // Pulse high
delay(2,279); // 2 ms
RB0 = 0; // Low
delay(19,243); // 18 ms
}
}
else if (RA1 == 1)
{
while(RA1 == 1)
{
RB0 = 1; // Pulse high
delay(2,127); // 1 ms
RB0 = 0; // Low
delay(19,271); // 18 ms
}
}
}
}
Please someone could help me debug this code, i would like to be able to control my servo motor (TowrPro MG995) Using pic16f877a. As you can see i am using port A as input and port B as output. when i press RA0 i want it to go left and RA1 i want it to go right. thank you
#include <pic.h>
__CONFIG(RC & WDTDIS & PWRTEN & BOREN & LVPEN & WRTEN & DEBUGEN & UNPROTECT);
int x, y;
delay(int xvalue,int yvalue)
{
for(x = 0; x < xvalue; x++)
for(y = 0; y < yvalue; y++);
return;
}
main()
{
PORTA = 0x00; //Clear port A
PORTB = 0x00; //Clear port B
PCFG2 = 1;
PCFG1 = 1;
TRISA = 0xff; //Set port A as input
TRISB = 0; //set port B as output
while(1) // Loop forever
{
if(RA0 == 1)
{
while(RA0 == 1) // If push button 0 is pressed
{
RB0 = 1; // Pulse high
delay(2,279); // 2 ms
RB0 = 0; // Low
delay(19,243); // 18 ms
}
}
else if (RA1 == 1)
{
while(RA1 == 1)
{
RB0 = 1; // Pulse high
delay(2,127); // 1 ms
RB0 = 0; // Low
delay(19,271); // 18 ms
}
}
}
}
Please someone could help me debug this code, i would like to be able to control my servo motor (TowrPro MG995) Using pic16f877a. As you can see i am using port A as input and port B as output. when i press RA0 i want it to go left and RA1 i want it to go right. thank you