How to use ports in a loop

Status
Not open for further replies.

osmanandac

New Member
I want to make like a following code
// the port definitons
RA3=my_ports(0)
RB2=my_ports(1)
RA1=my_ports(2)
RB7=my_ports(3)
RB0=my_ports(4)
Rxx=my_ports(x)
...

//then use in loop
....
for(i=0;i<10;i++)
{
my_ports(i)=1;
.....
my_ports(i)=0;
.....
}
 
I don't understand what you are trying to do. If you post a reply please include which chip and compiler you are using.

Mike.
 
If that is what he is asking then, in BoostC, you can do,
Code:
volatile int Ports @PORTA;
int PortBits[16]={
    0x8000,0x4000,0x2000,0x1000,
    0x0800,0x0400,0x0200,0x0100,
    0x0080,0x0040,0x0020,0x0010,
    0x0008,0x0004,0x0002,0x0001
};

void SetPort(char index){
    Ports=PortBits[index];
}

With the above, SetPort(0) will set bit 7 of PortB. Swapping the values in the table will change the order.

Mike.
 
Yes this is my solution


Thank you Mike for reply, i am using 16F877 and 16F628.
You replied solution for only one port. Can i define PORTA, PORTB, PORTC ports are together in ports structure?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…