The example below should print it. The function goes through the inputs one by one until it finds it (or not).
Your program is all messed up regarding the Carousel function. It is defined to take 2 parameters, but you call it with one parameter, and then it doesn't use any parameters but just sets a bit. I would remove all that and just set the bit.
This statement is incorrect. ClearBit doesn't return anything to be tested by an 'if' statement. ClearBit and SetBit are assumed to never fail and unlike ReadBit which returns the state of the input.
if (ClearBit(DC_Carousel_Motor)) //return 1;
After the function is working just turn the carousel on, use a while loop to wait until the CarouselPostion returns the tool you want, then turn off the carousel.
Code: Select all
#include "KMotionDef.h"
//// THIS ARE THE INPUT BITS READING EACH TOOL
#define TOOL_1 1161
#define TOOL_2 1162
#define TOOL_3 1163
#define TOOL_4 1164
#define TOOL_5 1165
#define TOOL_6 1166
#define TOOL_7 1167
#define TOOL_8 1168
int CarouselPosition(void); // define the function with no parameters and returns an integer
void main()
{
int Pos;
for (;;) // loop forever
{
Pos = CarouselPosition(); // call the function
printf("Carousel Position = %d\n",Pos); // print what the function returned
Delay_sec(1); // don't print too fast
} // end of loop
}
// returns current carousel position based on switches
int CarouselPosition(void)
{
int i;
for (i=0; i<8; i++) // check all 8 inputs
{
if (ReadBit(TOOL_1 + i) == 1) // found it?
return i+1; // yes, return it (add 1 to make first 1 not 0)
} // end of for loop
return -1; // not found return -1
}