English 中文(简体)
Pic programming: what is the variable type of a port bit in MikroC?
原标题:

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

问题回答

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.

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;




相关问题
passing form variables into a url with php

I have the following form which allows a user to select dates/rooms for a hotel reservation. <form action="booking-form.php" method="post"> <fieldset> <div class="select-date">...

Error: "Cannot modify the return value" c#

I m using auto-implemented properties. I guess the fastest way to fix following is to declare my own backing variable? public Point Origin { get; set; } Origin.X = 10; // fails with CS1612 Error ...

C-style Variable initialization in PHP

Is there such a thing as local, private, static and public variables in PHP? If so, can you give samples of each and how their scope is demonstrated inside and outside the class and inside functions?

C#/.NET app doesn t recognize Environment Var Change (PATH)

In my C# app, I am programmatically installing an Oracle client if one is not present, which requires adding a dir to the PATH system environment variable. This all works fine, but it doesn t take ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

How to dynamically generate variables in Action Script 2.0

I have a for loop in action script which I m trying to use to dynamically create variable. Example for( i = 0 ; i &lt 3 ; i++) { var MyVar+i = i; } after this for loop runs, i would like to ...

热门标签