Pic programming: what is the variable type of a port bit in MikroC?

3.6k views Asked by At

I'm programming in C in the MikroC IDE for a pic16f887 and I want more versatility with pins such as being able to put them into an array, passing them as arguments to functions...etc.

So I was wondering what the "type" of a pin such as PORTB.F1 is? How would I store bits into an array?

Would this work?

const char pinArr[3] = {PORTB.F1, PORTC.F1, PORTD.F1};

Thanks

2

There are 2 answers

1
user1013341 On

I'm assuming you are trying to do this with a set of inputs pins. A digital input pin should be read as an int, specifically it will be 0 or 1. Your char array probably wouldn't work as a pin with an input of 0 would be read as a NULL character, which would signal the end of the string to anything expecting a normal c string. However there should be nothing stopping you using an int array.

0
Ted Tedson On

You can define your pins and use the predefined names instead. It's a lot more easier. For example:

#define front_sensor                PORTE.F0
#define left_sensor                 PORTE.F1
#define right_sensor                PORTE.F2

or

unsigned char sensor = PORTE.F0;