1

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

HHK
  • 4,852
  • 1
  • 23
  • 40
Shubham
  • 949
  • 6
  • 21
  • 29

2 Answers2

0

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.

user1013341
  • 336
  • 1
  • 9
  • If Shubham uses the "char" type just as "enough space for 8 bytes" then the meaning of a NULL will not matter (as long he does not use printf or similar functions on the array). I find it cleaner to define a proper type similar to this "typedef unsigned char UInt8". – 0x6d64 Jun 06 '12 at 11:56
0

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;
Ted Tedson
  • 316
  • 1
  • 6
  • 15