so I've been trying to create a circuit with a PIC16F917, a button, and three LED's, where upon a button press the LED output changes, like the button press cycles through different modes. I've been trying to do this utilising pointers, in a way like a multiplexer, where the value of an integer depicts the certain output mode (interpreted by outputconfig()
), and the push of a button increments that integer by 1; but don't really know what's going wrong.
Also, why does XC8 say upon the build, that the use of "delay()" and "outputconfig()" within main() is a "function declared an implicit int"? And why does it still work?
Any help and/or guidance would be much appreciated. Below is the code I am working with. Thankyou!
#include <xc.h>
#include <pic16f917.h>
#include "configbits.h"
#include "definitions.h"
int value;
int *output;
int result;
int main()
{
TRISEbits.TRISE0=1;
TRISDbits.TRISD5=0;
TRISDbits.TRISD6=0;
TRISDbits.TRISD7=0;
while(1)
{
if(1==IN1)
{
delay();
if(1==IN1)
{
output=&value+1;
result=*output;
outputconfig();
}
}
}
}
int delay()
{
int i;
for(i=0;i<1000;i++){}
}
int outputconfig()
{
if(0==value)
{
OUT1=1;
OUT2=0;
OUT3=0;
}
if(1==value)
{
OUT1=0;
OUT2=1;
OUT3=0;
}
if(2==value)
{
OUT1=0;
OUT2=0;
OUT3=1;
}
else
{
NOP();
}
}
int
even if it does not. In this case he's lucky that the compiler's assumption is correct. But if one of the functions returnfloat
or a pointer or anything that's notint
then it's a bug waiting to happen. Either use the function after the function definition or declare the function prototype before using. C allows programs that don't do either to compile but it may or may not result in a correct program. \$\endgroup\$