các bác giúp em với em viết code như là bác motu mà sao cái servo rc của em nó ko chạy như ý !!hic,nó chỉ quay qua 1 bên mà ko quay về lại!!
các bác xem giùm em chương trình,em dùng HT pic ạ!!!
Code:
#include <htc.h>
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT
& UNPROTECT & BORDIS & IESODIS & FCMDIS);
#define FOSC 8000000L
#define MAX_VALUE 200
#define right MAX_VALUE - 20
#define left MAX_VALUE - 10
#define center MAX_VALUE -15
#define THRESHOLD_VALUE 50
unsigned char pulse_max=0;
unsigned char pulse_top=0;
unsigned char top_value = 0;
void delay_ms(int x)
{
for(char i=0;i<x;i++)
_delay(1000);
}
void interrupt isr(void)
{
if(T0IF) {
pulse_max++;
pulse_top++;
/* MAX_VALUE=200 turn off the pulse */
if (pulse_max >= MAX_VALUE) {
pulse_max=0;
pulse_top=0;
RB1=0;
}
if (pulse_top == top_value) {
RB1=1;
}
TMR0=56;
T0IF = 0;
}
}
void main(void)
{
OSCCON=0x70;
ANSEL=ANSELH=0x00;
TRISB=0x00;
PORTB=0x00;
pulse_max=0;
pulse_top=0;
OPTION = 0b00000000;
TMR0=56;
T0IE = 1;
GIE = 1;
while(1)
{
top_value=left;
delay_ms(1000);
top_value=right;
delay_ms(1000);
}
}
đây là cái servo rc của em,dem dùng loại tower pro 9g