HI-TECH C "can't generate code for this expression" Error.

Microcontroller Topics
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

HI-TECH C "can't generate code for this expression" Error.

Post by Nandika » Sun Aug 11, 2013 11:56 pm

Hello Friends,
I'm using HI-TECH C PIC10/12/16 MCUs version 9.81 in MPLAB IDE.
I'm using PIC16F84A.

In my coding has interrupt service routine like this.

Code: Select all

void interrupt ISR(){
	if(T0IF==1){
		tmrofc++;
	}
	if(INTF==1){
		float s=0;//distance in m
		float ticks=0;
		float time=0;
		
		ticks=(float)((tmrofc*256)+TMR0);
		time=ticks*1.6;
		s=time*0.00346;
		Display(s);
		
	}
}

Code: Select all

Display(s);
is another function for writing 7-Segment display.

Code: Select all

void Display(s){
	unsigned char d0=0;
	unsigned char d1=0;
	d0=s%10;
	d1=(s*10)%10;
	RA0=1;
	RA1=1;
	getDigit(d0);
	getDigit(d1);
	
}
Now my problem while build...
Build C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\101216HTC\range for device 16F84A
Using driver C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe

Make: The target "C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\101216HTC\delay.p1" is up to date.
Make: The target "C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\101216HTC\main.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\101216HTC\main.c -q --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.81\bin\picc.exe" -orange.cof -mrange.map --summary=default --output=default delay.p1 main.p1 --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.81
Copyright (C) 2010 Microchip Technology Inc.
Serial number: HCPICP-654321 (PRO)
Error [712] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\101216HTC\main.c; 62. can't generate code for this expression


********** Build failed! **********


What is this error?
What is reason for this error?


I searched in some forums like Microchip,HI-TECH C forum...Some said it's a RAM problem(Not enough memory).I change PIC.
Some said HI-TECH C Lite mode not alowe for that.I change to Pro mode.
Finaly,Some said cant use Delay routine in ISR.. :idea:
After commenting Display();,build successful.

Cant use another function in ISR?

I don't know really ISR.But,I have imagine :) [It's a another problem]

Please give me solutions for my questions.

Thank in advanced
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: HI-TECH C "can't generate code for this expression" Error.

Post by SemiconductorCat » Mon Aug 12, 2013 1:01 am

Read your code twice when you wrote it first.
see carefully,

Code: Select all

void Display(s){
what is 's' ? int float char or what?

you could define it on the second line however like bellow,

Code: Select all

void Display(c)
int c;
{

}
This could vary on Hi-Tech C however. First make that correction and try to compile, but I don't think
it will solve error 712.Try it and feedback.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: HI-TECH C "can't generate code for this expression" Error.

Post by Neo » Mon Aug 12, 2013 5:23 am

I do agree with Semi, the function parameters must be well defined. So it should be something like follows.

void Display(int s){
}

Also, it is not a good practice to call heavy functions from the interrupt routine in embedded programming. You should service the interrupt as soon as you can and return the control back to the system. Until a hardware interrupt is services, all other functions of the CPU is blocked.

So you could do something like this within the interrupt,

Code: Select all

interrupt_routine (){
       is_int_triggered = TRUE;
}
Main function,

Code: Select all

void main(void){

      if (is_int_triggered == TRUE){
            call display function here
      }
}
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: HI-TECH C "can't generate code for this expression" Error.

Post by Nandika » Mon Aug 12, 2013 7:57 am

Can't give argument type.
I tried like this ,

Code: Select all

void Display(float s){
	unsigned char d0=0;
	unsigned char d1=0;
	d0=(int)s%10;
	d1=(int)(s*10)%10;
	RA0=1;
	RA1=1;
	getDigit(d0);
	getDigit(d1);
	
}
I relived,
Error [987] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.22 arguments redeclared
Error [1098] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.22 conflicting declarations for variable "Display" (C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c:8)


********** Build failed! **********
After change like this,

Code: Select all

void Display(int d0,int d1){
	RA0=1;
	RA1=1;
	getDigit(d0);
	getDigit(d1);
	
}
and called like this,

Code: Select all

void interrupt ISR(){
	if(T0IF==1){
		tmrofc++;
	}
	if(INTF==1){
		float s=0;//distance in m
		float ticks=0;
		float time=0;
		unsigned char d0=0;
		unsigned char d1=0;
		ticks=(float)((tmrofc*256)+TMR0);
		time=ticks*1.6;
		s=time*0.00346;
		d0=(int)s%10;
		d1=(int)(s*10)%10;
		Display(d0,d1);
		
	}
}
But,
Error [987] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.28 arguments redeclared
Error [1098] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.28 conflicting declarations for variable "Display" (C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c:8)

********** Build failed! **********
Finally,
I removed int from Display function declaration line,like this,

Code: Select all

void Display(d0,d1){
	RA0=1;
	RA1=1;
	getDigit(d0);
	getDigit(d1);
	
}
Build Successful!!!
HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.81
Copyright (C) 2010 Microchip Technology Inc.
Serial number: HCPICP-654321 (PRO)

Memory Summary:
Program space used 22Fh ( 559) of 400h words ( 54.6%)
Data space used 3Ch ( 60) of 44h bytes ( 88.2%)
EEPROM space used 0h ( 0) of 40h bytes ( 0.0%)
Configuration bits used 0h ( 0) of 1h word ( 0.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)


Loaded C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\HC-SR04_Distance.cof.

********** Build successful! **********
Cant give int,float...types for argument.

Thanks
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: HI-TECH C "can't generate code for this expression" Error.

Post by SemiconductorCat » Mon Aug 12, 2013 5:18 pm

>> Error [1098] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.22 conflicting declarations for variable "Display" (C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c:8)

Hm, if so this sounds like , your build chain try to compile with C compiler instead of C++ compiler.
So it didn't allow it to overload , where Display is defined somewhere already. (probably on header files).
Try Display_() as the function name and feedback.

Or save your file as main.cpp instead main.c and try again with the Display(int,int) version.
That would solve the redeclaration problem but error 712 goes beyond that, so feedback.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: HI-TECH C "can't generate code for this expression" Error.

Post by Neo » Mon Aug 12, 2013 5:22 pm

Nandika, if you are not using a header file, you need to define the function prototype before the calling point as below.

Code: Select all

void dispaly(int, int);

void main(void){

     call display function.....
}

void display(int a, int b){
     your code here
}
Or else, you can write the display function on top of the calling point as below.

Code: Select all

void display(int a, int b){
     your code here
}

void main(void){

     call display function.....
}
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: HI-TECH C "can't generate code for this expression" Error.

Post by Nandika » Mon Aug 12, 2013 8:44 pm

Friends,

As Semiconductor said,I change Display() function and problem is solved.
Thanks :)
Now I can use data type int for arguments.
This is modified code.

Code: Select all

void Display_Segments(int d0,int d1){
   RA0=1;
   RA1=1;
   getDigit(d0);
   getDigit(d1);
   
}

void interrupt ISR(){
   if(T0IF==1){
      tmrofc++;
   }
   if(INTF==1){
      float s=0;//distance in m
      float ticks=0;
      float time=0;
      unsigned char d0=0;
      unsigned char d1=0;
      ticks=(float)((tmrofc*256)+TMR0);
      time=ticks*1.6;
      s=time*0.00346;
      d0=(int)s%10;
      d1=(int)(s*10)%10;
      Display_Segments(d0,d1);
      
   }
}
Dear Neo,
I know something about function prototype.According to my knowledge,Not want function prototype as this coding,

Code: Select all

void display(int a, int b){
     your code here
}

void main(void){

     call display function.....
}
In my program call function always in top of code.caller function always in bottom.like above example.
Is it correct? I think it's not good way :?:

But,I used function prototype after you said,
I used function prototype as this,

Code: Select all

void Display(float);
and functionlike this,

Code: Select all

void Display(float s){
      unsigned char d0=0;
      unsigned char d1=0;
	
	d0=(int)s%10;
   d1=(int)(s*10)%10;
   RA0=1;
   RA1=1;
   getDigit(d0);
   getDigit(d1);
   
}

void interrupt ISR(){
   if(T0IF==1){
      tmrofc++;
   }
   if(INTF==1){
      float s=0;//distance in m
      float ticks=0;
      float time=0;

      ticks=(float)((tmrofc*256)+TMR0);
      time=ticks*1.6;
      s=time*0.00346;
      Display(s);
      
   }
}
This coding Build success!!! :) It's my first coding.
I added extra function prototype only....

Dear Semiconductor,
If function prototype like this,
void Display()
(not float type in brackets) compiler error is previous one.
Error [1098] C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c; 38.22 conflicting declarations for variable "Display" (C:\Users\Nandika\Desktop\PIC_Project\HC-SR04_Distance\HTC\main.c:8)
What is real problem ? I think,function prototype problem as Neo said..
I searched my each project file for Display.There is no display word.

Thank both of you.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: HI-TECH C "can't generate code for this expression" Error.

Post by SemiconductorCat » Mon Aug 12, 2013 10:21 pm

>>
What is real problem ? I think,function prototype problem as Neo said..
I searched my each project file for Display.There is no display word.
>>

It's hard to answer that question.
It could be a preprocessed macro. To check that you need to send your .C file thorough preprocessor and check it's
output file for 'Display'.

It could be defined on the linker script or crt0.o as well, in such case it should be normally documented on the
manual.

Sometimes compiler defines variables and functions too, for a example functions for dynamic upcasting and
down casting. '__dynamic_cast'. They are normally starts with two underscores.

Strange in Display() here. And more strange to hear that it solves error 712, Because error 712 is claim to be a
rash case than this. So which means you are leaving a root case behind. If you need to continue your project [
due to deadlines] by bypassing that root case, then pls document it there with /*COMPILER */

Code: Select all

/* 
 :COMPILER: Display(int) gives compiler error 712, 
  compiler claims to be Disply variable have defined somewhere else.
  can't find the root case.
  :KLUDGE: So continuing with Display_Segment()
*/

May be what Neo told, I need to review the full source to come into a decision. And the line number which
fails in each cases.
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: HI-TECH C "can't generate code for this expression" Error.

Post by Nandika » Tue Aug 13, 2013 7:51 pm

This is my .C file
main.c
(1.74 KiB) Downloaded 351 times
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: HI-TECH C "can't generate code for this expression" Error.

Post by SemiconductorCat » Tue Aug 13, 2013 10:36 pm

OH, that's it. Error 712,
it's a stackoverflow issue as I'm guessing now.
Thanks to the compiler for stopping you in here. Otherwise you will enjoy hours of debugging time
and even without any clue what's gone wrong there.

Think why, your code is compiled as a "C" file instead of "C++" file.So

Code: Select all

void Display();
is equivalent to

Code: Select all

void Display(...);
in C++. See elipse operator. http://en.wikipedia.org/wiki/Ellipsis_( ... ogramming)

and as you already know almost all PIC devices have a limited number of stack. probably 8-16 bytes deep.
But the story does not end here. The real story is when it feels stack is not enough for passing arguments
it uses heap RAM area. But here for variable number of parameters it could not be used here. So compiler
gives up generating the code. That's what I assuming what had happened here. I may be wrong here, I just
only read the "compiler construction course in under-grad level". And I don't have a copy of HI-TECH C.Just
reviewing your source that's the assumption that I could think.

For more, I suggest you to try to see the generated assembly language code for the variable number of
parameter function.
Post Reply

Return to “Microcontrollers”