Home:ALL Converter>Implicit declaration of function and conflicting type - AVR

Implicit declaration of function and conflicting type - AVR

Ask Time:2015-06-02T14:41:50         Author:Yash

Json Formatter

This is my first program for AVR. While building, the code is showing error: conflicting types for 'Encode' implicit declaration of 'Encode'

I have written the following code:

#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>

#define SegDataPort PORTC
#define SegDataPin PINC
#define SegDataDDR DDRC

#define SegCntrlPort PORTD
#define SegCntrlPin PIND
#define SegCntrlDDR DDRD

int main(void)
{
   SegDataDDR = 0xFF;
   SegCntrlDDR = 0xF3;
   SegCntrlPort = 0xF3;
   SegDataPort = 0x00;
   unsigned char adc_value;
   float volt = adc_value/1023;
   int temp = floor(volt*10 + 0.5);

   SegDataPort = Encode(temp1%10);

   //^^^^ implicit declaration of 'Encode' 

   SegCntrlPort = ~0x01;
   SegDataPort = Encode((temp1/10)%10);
   SegCntrlPort = ~0x02;
   SegDataPort = Encode(temp1/100);
   SegCntrlPort = ~0x04;
}

unsigned char Encode(int digit)
{
   unsigned char val;
   switch(digit)
   {
      case 0 : Val = 0b00111111;
      case 1 : val = 0b00000110;

      /// so on till case 9
   }
   return val;
}

I am using ATmega16 as microcontroller. I have also added much more libraries such as math for floor function and others. I have tried changing int to unsigned int, unsigned char and others but it is still not working and showing same error. Please help me.

Author:Yash,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30589109/implicit-declaration-of-function-and-conflicting-type-avr
Sourav Ghosh :

\n implicit declaration of 'Encode'\n\n\nIn C a function needs to be either declared or defined before it has been used (called).\n\nEither\n\n\nMove the definition of Encode() function before main()\nAdd a forward declaration to Encode() before main().\n\n\nThat said, floor() is a function, defined in math.h and defined in the math library. To use that, you need to #include <math.h> and link with -lm at compilation time.\n\n\n\nAbout the programmic logic used here,\n\nunsigned char adc_value;\nfloat volt = adc_value/1023;\nint temp = floor(volt*10 + 0.5);\n\n\nare pretty problematic, because\n\n\nadc_value is used uninitialized, which leads to undefined behaviour.\nadc_value is of type char. Dividing it by a value of 1023 will always give a result of 0 as the division will take place as an integer division and won't produce a float result itself, as you migh have expected.\n\n\nMy suggestions, change that code block to\n\nint adc_value = <some value to initialize>; //or some input function\nfloat volt = (float)adc_value/1023; //enforce floating point division\nint temp = floor(volt*10 + 0.5);\n",
2015-06-02T06:45:03
yy