#include <pic.h> // using 16F877
// configuration
//==========================================================================
__CONFIG ( 0x3F32 );
#define servo RB1
#define MHZ *1000L /* number of kHz in a MHz */
#define KHZ *1 /* number of kHz in a kHz */
#define Delay_us(x) { unsigned char _dcnt; \
_dcnt = (((x)*(20MHZ))/(24MHZ))|1; \
while(--_dcnt != 0) \
continue; \
_dcnt = (((x)* (20MHZ))/(24MHZ))|1; \
while(--_dcnt != 0) \
continue; }
void _Delay_ms(unsigned char y);
// delay ms
void main(void)
{
unsigned int i,a;
TRISB = 0b00000001; // PORTB as Ouput Port(servo motor is RB1)
PORTB = 0b00000000; //clear portb
while(1)
{
//for(i=0;i<50;i++)
//{
servo=1; //set servo pin low
Delay_us(150);
Delay_us(150);
Delay_us(150);
servo=0; //set servo pin high
_Delay_ms(19);
Delay_us(50);
_Delay_ms(20); }
}
void _Delay_ms(unsigned char y)
{
unsigned char i;
do {
i = 4;
do {
Delay_us(250);
} while(--i);
} while(--y);
}