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

4

2 回答 2

0

您可以定义您的引脚并改用预定义的名称。这要容易得多。例如:

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

或者

unsigned char sensor = PORTE.F0;
于 2014-07-02T07:18:59.100 回答
0

我假设您正在尝试使用一组输入引脚来执行此操作。数字输入引脚应读取为 int,特别是 0 或 1。您的char数组可能无法作为输入为 0 的引脚工作,将被读取为 NULL 字符,这将表示字符串的结尾任何期望正常的 c 字符串的东西。但是,应该没有什么可以阻止您使用int数组。

于 2012-05-19T09:30:01.317 回答