Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Is this program possible ?

Status
Not open for further replies.

markcalaway

Newbie level 4
Newbie level 4
Joined
Nov 28, 2005
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
#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(y);
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(y);
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.
 

First of all you should specify which compiler you are using.

I do not think that it is possible to write the program like you want to do you should consider to use a mask value to clear / set individual bits of a port.

const unsigned char mask[]={0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

// set individual bit
PORTB|=mask[x];

// clear individual bit
PORTB&=(mask[x] ^ 0xFF);

hope this helps and best regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top