I am trying to control the servo motor with PIC 16F877A and mplabX.Below is my coding for servo motor turn 90 degree,and reversed 90 degree. Unfortunately, i can not move the servo motor. Can i know which pin and register are related to control the servo motor. I am glad to see somebody reply.Thanx:)
#include "delay.h"
#include<htc.h>
#include"adc.h"
#define _XTAL_FREQ 8000000
__CONFIG( HS & // External Crystal at High Speed
WDTDIS & // Disable Watchdog Timer.
PWRTEN & // Enable Power Up Timer.
BORDIS & // Disable Brown Out Reset.
//MCLREN & // MCLR function is enabled
LVPDIS);
void main(void)
{
//int x = 125;
PORTA=0;
PORTC=0;
TRISA=0;
TRISC = 0b11111111 ; // configure RC3 as input (1 for input and 0 for output)
PR2 = 0xFA; //oxFA for 250 (used to set time period)
CCPR2L = 125; // (used to set duty cycle)
CCP2CON = 0b00001100; // select for PWM mode
T2CON = 0b00000110; // enabling timer 2, prescalar 16
adc_initialize();
while(1)
{
RA1=1;
if(RC3==1) // forward
{
// x=x+1
CCPR2L = 250+125; // (used to set duty cycle)
T2CON = 0b00000110; // enabling timer 2, prescalar 16
RC1=1;
}
if(RC4==1) // back ward
{
// x=x-1
CCPR2L = 250-245; // (used to set duty cycle)
T2CON = 0b00000110; // enabling timer 2, prescalar 16
}
DelayMs(2);
}
}