Hi, everyone i am doing my servo control using pic16f877a. I need some help because my code is not working. it only move alittle and just stop. could anyone help me so that i control my servo by press botton on port A bit0 it go right and press port A bit1 it go left. here is my code:
Please help me debug this sucker.
thank you
#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;
PORTB = 0x00;
PCFG2 = 1;
PCFG1 = 1;
TRISA = 0xff;
TRISB = 0;
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 help me debug this sucker.
thank you
#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;
PORTB = 0x00;
PCFG2 = 1;
PCFG1 = 1;
TRISA = 0xff;
TRISB = 0;
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
}
}
}
}