M
markcalaway
Guest
# include <p18f252.h>
# include <delays.h>
main (void)
(
int i, j, x, y;
x = 16;
y = 128;
j = 1; / / første servo = throttle
while (x <= 20)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x-4); / / gass min til maks
PORTBbits.RB (j) = 0;
Delay100TCYx (y 4);
i ;
)
x 1;
y-1;
)
x = 16;
y = 128;
while (x> = 12)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x 4); / / gass maks til min
PORTBbits.RB (j) = 0;
Delay100TCYx (y-4);
i ;
)
x-1;
Y 1;
)
j ; / servo endre gang
while (j <5) / / servo endre 4 ganger
(
x = 16;
y = 128;
while (x <= 20)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x); / / annen servos nøytral til maks
PORTBbits.RB (j) = 0;
Delay100TCYx
;
i ;
)
x 1;
y-1;
)
x = 16;
y = 128;
while (x> = 12)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x 4); / / annen servos maks til min
PORTBbits.RB (j) = 0;
Delay100TCYx (y-4);
i ;
)
x-1;
Y 1;
)
x = 16;
y = 128;
while (x <= 16)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x); / / annen servos min til nøytral
PORTBbits.RB (j) = 0;
Delay100TCYx
;
i ;
)
x 1;
y-1;
)
j ; / / endre servo
)
)Vi vil bruke dette programmet til å kontrollere de 5 servoer av en Rc helikopter.Port B vil bli dedikert til dette.(Eg. Port B pin 1 styrer gass, pin 2 styrer roret og så videre.
Problemet vi har ligger i 'TRISBbits.TRISB (j)', slik at den ikke gjenkjenner 'j'.Med denne linjen im prøver å endre biter av havnen som utgang.Jeg hadde allerede prøvd skiftet register, men til slutt jeg fortsatt tror problemet ligger i innstillingen tilsvarende bit som produksjon og ikke skiftende.Så er det noen kommando jeg kan bruke for å sette utgang bruke mitt gamle formatet eller noe lignende uten å gjøre noen store endringer i programmet.Noen råd ville være verdsatt.Takk.
# include <delays.h>
main (void)
(
int i, j, x, y;
x = 16;
y = 128;
j = 1; / / første servo = throttle
while (x <= 20)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x-4); / / gass min til maks
PORTBbits.RB (j) = 0;
Delay100TCYx (y 4);
i ;
)
x 1;
y-1;
)
x = 16;
y = 128;
while (x> = 12)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x 4); / / gass maks til min
PORTBbits.RB (j) = 0;
Delay100TCYx (y-4);
i ;
)
x-1;
Y 1;
)
j ; / servo endre gang
while (j <5) / / servo endre 4 ganger
(
x = 16;
y = 128;
while (x <= 20)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x); / / annen servos nøytral til maks
PORTBbits.RB (j) = 0;
Delay100TCYx
i ;
)
x 1;
y-1;
)
x = 16;
y = 128;
while (x> = 12)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x 4); / / annen servos maks til min
PORTBbits.RB (j) = 0;
Delay100TCYx (y-4);
i ;
)
x-1;
Y 1;
)
x = 16;
y = 128;
while (x <= 16)
(
i = 0;
while (i <2)
(
TRISBbits.TRISB (j) = 0;
PORTBbits.RB (j) = 1;
Delay100TCYx (x); / / annen servos min til nøytral
PORTBbits.RB (j) = 0;
Delay100TCYx
i ;
)
x 1;
y-1;
)
j ; / / endre servo
)
)Vi vil bruke dette programmet til å kontrollere de 5 servoer av en Rc helikopter.Port B vil bli dedikert til dette.(Eg. Port B pin 1 styrer gass, pin 2 styrer roret og så videre.
Problemet vi har ligger i 'TRISBbits.TRISB (j)', slik at den ikke gjenkjenner 'j'.Med denne linjen im prøver å endre biter av havnen som utgang.Jeg hadde allerede prøvd skiftet register, men til slutt jeg fortsatt tror problemet ligger i innstillingen tilsvarende bit som produksjon og ikke skiftende.Så er det noen kommando jeg kan bruke for å sette utgang bruke mitt gamle formatet eller noe lignende uten å gjøre noen store endringer i programmet.Noen råd ville være verdsatt.Takk.