manipulating bits on PORTx

General discussion on mikroElektronika website & forums.
Post Reply
Author
Message
dvfer
Posts: 2
Joined: 27 Mar 2012 10:54

manipulating bits on PORTx

#1 Post by dvfer » 27 Mar 2012 11:01

Is there a way to manipulate bits on any port as a vector??

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: manipulating bits on PORTx

#2 Post by filip » 28 Mar 2012 09:47

Hi,

Please, can you tell me what exactly did you have in mind ?

Regards,
Filip.

dvfer
Posts: 2
Joined: 27 Mar 2012 10:54

Re: manipulating bits on PORTx

#3 Post by dvfer » 28 Mar 2012 16:56

Well, I would like to do somthing like this:

I'm using a pic16F887..


for (i=0;i<8;i++) {
PORTB = 1;
delay_ms(1000);
}


This code will generate an Error when compiled, but, is there a way to manipulate a register's bits like an array?? Do I have to write my own library??

And also I know that it is not possible to declare a bit type array :'(..




Thanks for fast respond...

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: manipulating bits on PORTx

#4 Post by filip » 29 Mar 2012 10:19

Hi,

Well, you could do this in this way :

Code: Select all

char i;
char array[] = {1,2,4,8,16,32,64,128,255};

void main() {
  for (i=0;i<8;i++) {
    PORTB = array[i];
  }
}
Basically, you assign to the PORTB predefined values from the declared vector (array).

Regards,
Filip.

Post Reply

Return to “Website & Forums General Discussion”