Help : Changing PWM to 50Hz to Control Servo-Converting Code

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Holyares
Posts: 3
Joined: 20 Aug 2012 20:53

Help : Changing PWM to 50Hz to Control Servo-Converting Code

#1 Post by Holyares » 17 Aug 2013 08:08

Hey guys , I need to convert this code from C to MicroC Pro.
This code is used to change the PWM frequency into 50Hz to control a servo motor.
Notice that this code is used for PIC16f1509 while I want to use it with PIC16F877 , hope this changes nothing.

here is the code :

#include <stdio.h>

//*********binary representation of a number (recursive)*******/////
void printBin_r(int n,int cont){
if (cont<7)
printBin_r(n>>1,cont+1);

printf("%d ",n&1);
}
void printBin(int n){
printBin_r(n,0);
}
///////*******************************************/////////////////

int main(){

unsigned char a=0b10000111; //just an example of a number to divide
unsigned char f=0,s=0; //simulating 2 8-bit registers

printBin(a);
printf("\n");

//******* divide a byte -> 6 bit in f and 2 bit in s ******////
f=a>>2;
s=a&0b11;
/////////************************************/////////////

printBin(f);
printf("\n");

printBin(s);
printf("\n");

return 0;
}

it's from this page :
http://ferretrobotics.blogspot.com/2013 ... -50hz.html

Post Reply

Return to “mikroC PRO for PIC Beta Testing”