markcalaway
Newbie level 4
#include<p18f252.h>
#include<delays.h>
main(void)
{
int i, j, x, y;
x = 16;
y = 128;
j = 1; //first servo = throttle
while(x<=20)
{
i = 0;
while(i < 2)
{
TRISBbits.TRISB(j)=0;
PORTBbits.RB(j)=1;
Delay100TCYx(x-4); //throttle min to max
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); //throttle max to min
PORTBbits.RB(j)=0;
Delay100TCYx(y-4);
i++;
}
x-1;
y+1;
}
j++; //servo change once
while(j<5) //servo change 4 times
{
x = 16;
y = 128;
while(x<=20)
{
i = 0;
while(i < 2)
{
TRISBbits.TRISB(j)=0;
PORTBbits.RB(j)=1;
Delay100TCYx(x); //other servos neutral to max
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); //other servos max to 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); //other servos min to neutral
PORTBbits.RB(j)=0;
Delay100TCYx;
i++;
}
x+1;
y-1;
}
j++; //change servo
}
}
We will be using this program to control the 5 servos of an Rc Helicopter. Port B will be dedicated for this. (Eg. Port B pin 1 controls the throttle, pin 2 controls the rudder and so on.
The problem we have lies in 'TRISBbits.TRISB(j)', such that it doesn't recognise the 'j'. With this line im trying to change the bits of the port as output. I had already tried the shift register, but eventually I still think the problem lies in setting the corresponding bit as output and not the shifting. So is there any command i could use to set the output using my old format or something similar without making any major changes to the program. Any advice would be appreciated. Thank You.
#include<delays.h>
main(void)
{
int i, j, x, y;
x = 16;
y = 128;
j = 1; //first servo = throttle
while(x<=20)
{
i = 0;
while(i < 2)
{
TRISBbits.TRISB(j)=0;
PORTBbits.RB(j)=1;
Delay100TCYx(x-4); //throttle min to max
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); //throttle max to min
PORTBbits.RB(j)=0;
Delay100TCYx(y-4);
i++;
}
x-1;
y+1;
}
j++; //servo change once
while(j<5) //servo change 4 times
{
x = 16;
y = 128;
while(x<=20)
{
i = 0;
while(i < 2)
{
TRISBbits.TRISB(j)=0;
PORTBbits.RB(j)=1;
Delay100TCYx(x); //other servos neutral to max
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); //other servos max to 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); //other servos min to neutral
PORTBbits.RB(j)=0;
Delay100TCYx;
i++;
}
x+1;
y-1;
}
j++; //change servo
}
}
We will be using this program to control the 5 servos of an Rc Helicopter. Port B will be dedicated for this. (Eg. Port B pin 1 controls the throttle, pin 2 controls the rudder and so on.
The problem we have lies in 'TRISBbits.TRISB(j)', such that it doesn't recognise the 'j'. With this line im trying to change the bits of the port as output. I had already tried the shift register, but eventually I still think the problem lies in setting the corresponding bit as output and not the shifting. So is there any command i could use to set the output using my old format or something similar without making any major changes to the program. Any advice would be appreciated. Thank You.