Why it showing type redeclared error? - Page 1
Forum section: electronics / general

author: radhika
author_rank: Regular Contributor
timestamp: October 18, 2018, 05:52:35 pm
content: Hello,Can anybody help me in simulating this code. It's showing tyoe redeclared error.Please once simulate this code in your MPLAB X IDE.Code:#include <stdio.h>#include <stdlib.h>#include <xc.h>#include <p18f4520.h>#include <LCD.h>#define ldata PORTD //PORTD = LCD data pins#define rs PORTEbits.RE0 //rs = PORTE.0#define rw PORTEbits.RE1 //rw = PORTE.1#define en PORTEbits.RE2 //en = PORTE.2#define Up PORTAbits.RA0#define Down PORTAbits.RA1#define Select PORTAbits.RA2#define Clock PORTBbits.RB5#define Data PORTBbits.RB6// End specification for pins/* function prototype */void MSDelay(unsigned int);void lcdinit(void);void lcdWrite(unsigned char);void lcdout(char c);void lcdchr (char x);void SendPotValue (unsigned short num);void SelectArrow();//POT values;unsigned short aa, count1;int t, i, Flag, Mask;const char MESSAGE[] = "VOL:";void main() {TRISAbits.TRISA0 = 1;TRISAbits.TRISA1 = 1;TRISAbits.TRISA2 = 1;TRISBbits.TRISB6 = 0; //SCLTRISBbits.TRISB5 = 0; //SDACMCON = 0x07; // Disable comparatorsADCON1 = 0x0F; // Disable Analog functionslcdinit(); // Initialize LCDlcdcmd(0x00); // CLEAR displaylcdcmd(0x0C); // Cursor offlcdout(1,1,MESSAGE); // Write message1 in 1st rowaa = 50;count1 = 2;SendPotValue(aa);do {if (!Up) {Debounce_Key();if (aa < 250) {aa = aa + 25;count1 = aa/25;}SendPotValue(aa);}if (!Down) {Debounce_Key();if (aa > 0) {aa = aa - 25;count1 = aa/25;}SendPotValue(aa);}if (!Select) {Debounce_Key();SelectArrow();}} while (1);}void SendPotValue(unsigned short num1){unsigned int // Mask;Mask = 0x80;Data = 1;Clock = 1;MSDelay(5);Clock = 0;// Shift in 8-bit wiper position for POTAfor (t=0; t<8; t++){Flag = num1 & Mask;if(Flag==0)Data = 0;elseData = 1;Clock = 1;MSDelay(1);Clock = 0;Mask = Mask >> 1;}lcdcmd(0x00);lcdout(1,3,MESSAGE); // Write message1 in 1st rowSelectArrow();}void SelectArrow(){for (i=0; i<count1; i++) {lcdchr(1, 6+i, 255); //char row, char column, char out}}void Debounce_Key(){MSDelay(200);}void lcdcmd(unsigned char value){ldata = value;rs = 0;rw = 0;en = 1;MSDelay(1);en = 0;}void MSDelay(unsigned int itime){unsigned int i, j;for (i=0; i<itime; i++)for (j=0; j<255; j++);}void lcdinit(){lcdcmd(0x38);lcdcmd(0x0C);lcdcmd(0x01);lcdcmd(80);}void lcdOut(char c){rs = 1;lcdWrite( c );}void lcdchar(char dat){ldata= dat; /*Send data to LCD*/rs = 1; /*Data Register is selected*/en=1; /*High-to-Low pulse on Enable pin to latch data*/NOP();en=0;MSDelay(1);}Thanks.

author: taydin
author_rank: Frequent Contributor
timestamp: October 18, 2018, 05:58:18 pm
content: It's probably a mismatch between how the functions are declared and how they are defined.In order to make life easier, always try to place function definitions at the top of the source code, so that functions below don't need function "declarations". If you use both function declaration and definition, then you are putting on yourself the responsibility to keep them exactly in sync. But if you just define a function and let functions below just "see" it, then you don't need declarations.Always try to avoid duplication!

author: helius
author_rank: Super Contributor
timestamp: October 18, 2018, 06:15:28 pm
content: Quote from: radhikaYou probably meantlcdcharto match the definition.You want to be consistent with forward declarations, and use(void)for declaring zero arguments. The reason is that the Pre-ANSI, K&R C style uses no argument prototypes in function declarations, and having just an empty parameter list is ambiguous with that style.

author: JPortici
author_rank: Super Contributor
timestamp: October 18, 2018, 10:16:39 pm
content: don't include p18f4520.hxc.h takes care of that.ALWAYS state which mcu, compiler, compiler version, ide and ide version. The less we have to guess the better.Copy and paste the actual error output from the compiler.if that's the only file of course you're going to have the redeclared error somewhere. You need to write all the local functions prototypes before the main or the compiler doesn't know how to make the call

author: ejeffrey
author_rank: Super Contributor
timestamp: October 19, 2018, 05:19:29 am
content: There are several problem with this code.You don't have a prototype for lcdcmd.If you don't have a prototype the compiler will essentially automatically generate a declaration with default argument and return types. Then it gets to the definition which doesn't match, and that causes a type mismatch.You also declare lcdout(char c) but call it as lcdout(1,1,MESSAGE) and define it as lcdOut(char c).lcdchr / lcdchar ambiguity.In lcdinit(), the call to lcdcmd(80); is probably supposed to be lcdcmd(0x80).

author: radhika
author_rank: Regular Contributor
timestamp: October 19, 2018, 07:17:03 am
content: I have done some changes according to all the suggestions:Please check:Code:#include <stdio.h>#include <stdlib.h>#include <xc.h>#include <LCD.h>#define ldata PORTD //PORTD = LCD data pins#define rs PORTEbits.RE0 //rs = PORTE.0#define rw PORTEbits.RE1 //rw = PORTE.1#define en PORTEbits.RE2 //en = PORTE.2#define Up PORTAbits.RA0#define Down PORTAbits.RA1#define Select PORTAbits.RA2#define Clock PORTBbits.RB5#define Data PORTBbits.RB6// End specification for pins/* function prototype */void MSDelay(unsigned int);void lcdinit(void);void lcdWrite(unsigned char);void lcdout(char row, char column, char text);void lcdchar (char x);void SendPotValue (unsigned short num);void SelectArrow();//POT values;unsigned short aa, count1, i;int t, Flag, Mask;const char MESSAGE[] = "VOL:";void SendPotValue(unsigned short num1){unsigned int // Mask;Mask = 0x80;Data = 1;Clock = 1;MSDelay(5);Clock = 0;// Shift in 8-bit wiper position for POTAfor (t=0; t<8; t++){Flag = num1 & Mask;if(Flag==0)Data = 0;elseData = 1;Clock = 1;MSDelay(1);Clock = 0;Mask = Mask >> 1;}lcdcmd(0x01);lcdout(1,3,MESSAGE); // Write message1 in 1st rowSelectArrow();}void SelectArrow(){for (i=0; i<count1; i++) {lcdchar(1, 6+i, 255); //char row, char column, char out}}void Debounce_Key(){MSDelay(200);}void lcdcmd(unsigned char value){ldata = value;rs = 0;rw = 0;en = 1;MSDelay(1);en = 0;}void MSDelay(unsigned int itime){unsigned int i, j;for (i=0; i<itime; i++)for (j=0; j<255; j++);}void lcdinit(){lcdcmd(0x38);lcdcmd(0x0C);lcdcmd(0x01);lcdcmd(0x80);}void lcdout(char rows, char columns, char texts){rs = 1;lcdWrite( texts );}void lcdchar(char dat){ldata= dat; /*Send data to LCD*/rs = 1; /*Data Register is selected*/en=1; /*High-to-Low pulse on Enable pin to latch data*/NOP();en=0;MSDelay(1);}void main() {TRISAbits.TRISA0 = 1;TRISAbits.TRISA1 = 1;TRISAbits.TRISA2 = 1;TRISBbits.TRISB6 = 0; //SCLTRISBbits.TRISB5 = 0; //SDACMCON = 0x07; // Disable comparatorsADCON1 = 0x0F; // Disable Analog functionslcdinit(); // Initialize LCDlcdout(1,1,MESSAGE); // Write message1 in 1st rowaa = 50;count1 = 2;SendPotValue(aa);do {if (!Up) {Debounce_Key();if (aa < 250) {aa = aa + 25;count1 = aa/25;}SendPotValue(aa);}if (!Down) {Debounce_Key();if (aa > 0) {aa = aa - 25;count1 = aa/25;}SendPotValue(aa);}if (!Select) {Debounce_Key();SelectArrow();}} while (1);}But I am still getting an error, i.e :Speaker_Check.c:34: warning: (346) declaration of "Mask" hides outer declaration ------- Mask = 0x80;Speaker_Check.c:52: warning: (361) function declared implicit int ------- lcdcmd(0x01);Speaker_Check.c:53: warning: (358) illegal conversion of pointer to integer ------- lcdout(1,3,MESSAGE);Speaker_Check.c:60: error: (186) too many function arguments ------- lcdchar(1, 6+i, 255);Speaker_Check.c:69: error: (984) type redeclared ------- {Speaker_Check.c:69: error: (1098) conflicting declarations for variable "lcdcmd" (Speaker_Check.c:68) --------- {(908) exit status = 1nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/Speaker_Check.p1' failedmake: Leaving directory 'C:/Users/Soni/MPLABXProjects/Speaker_Check.X'nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failedmake: Leaving directory 'C:/Users/Soni/MPLABXProjects/Speaker_Check.X'nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failedmake: *** [build/default/production/Speaker_Check.p1] Error 1make: *** [.build-conf] Error 2make: *** [.build-impl] Error 2BUILD FAILED (exit value 2, total time: 1s)

author: JPortici
author_rank: Super Contributor
timestamp: October 19, 2018, 07:26:35 am
content: have you tried reading the messages? start with the first error.too many arguments at line 60. you called lcdchar with three arguments. lcdchar has only one argument. maybe you meant to use lcdout?

author: sokoloff
author_rank: Super Contributor
timestamp: October 19, 2018, 07:32:27 am
content: Put an explicit declaration for lcdcmd above.Fix the explicit declaration for lcdchar. You are calling it with three parameters when you declared it took only one.lcdout must take “texts” as a (const) char * (a string or a char pointer) not as a char.You probably also need to add an additional MSDelay in the bit-banging loop, assuming you want a square wave clock signal. As the code is now, the clock pin will spend most of its time high and be periodically (and quickly) strobed low. Maybe that’s right, but it’s a little unusual.I’d also seek to write an MSDelay not based on arbitrary looping, but based on an actual timer on the chip. As it is now, an optimizing compiler is allowed to make that function arbitrarily fast.

author: JPortici
author_rank: Super Contributor
timestamp: October 19, 2018, 07:52:53 am
content: there are builtin functions for delays in ms and us. Unfortunately, they require you read the compiler manual to understand how to use them