Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem in HiTech C, Error = Can't create code for this statement

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
I am having a very good experience with the HiTech C Compiler, but today when i am trying to experimenting something i get stuck in a strange error,
compiler givies me error that it can't create code for this expression,
can anyone help me to solve this problem..
i am using pic18f4550 for my programming purpose and attaching the small module which is giving error

Code:
#include <htc.h>

#ifndef GLCD_CS1
	#define GLCD_CS1 PORTBbits.RB0   // Chip Selection 1
#endif

#ifndef GLCD_CS2
	#define GLCD_CS2 PORTBbits.RB1   // Chip Selection 2
#endif


//Function Prototype
void Select_Side(bit side);

void main()
{
	TRISB = 0x00;
	Select_Side(0);   [color:red][B][I]//ERROR at this line "can't generate code for this expression"[/I][/B][/color]
	while(1);
}

//Function definition
void Select_Side(bit side)
{
	if(side)            [color:red][B][I]//ERROR at this line "can't generate code for this expression"[/I][/B][/color]
		GLCD_CS2 = 1;
	else
		GLCD_CS1 = 1;
}

Pls tell me how to solve this problem.

I had tried this code for 8051 Controller and it works fine in keil but when importing code for pic and using hi-tech c compiler it doesn't works, pls suggest me some thing.


Even changing lines to this doesn't solve my problem

Code:
void Select_Side(bit side)
{
	if(side == 1)            [color:red][B][I]//ERROR at this line "can't generate code for this expression"[/I][/B][/color]
		GLCD_CS2 = 1;
	else
		GLCD_CS1 = 1;
}


Waiting for reply

Thanks in Advance
 

I don't use hitech or keil, but the first thing that occurs to me is to change the Select_Side's passed variable from bit to int. Perhaps hitech isn't happy about passing a bit variable.

Thus:
Code:
void Select_Side(int side)
{

}
 
Thanks..
That solves my problem, but in my code i have to change the bit to int or unsigned char which will increase my code size.

Actually i am writing function for Graphical LCD

in that i have used several macros like

#define GLCD_LEFT 0
#define GLCD_RIGHT 1

I thought i can pass these as "bit" in function but now i am passing them as unsigned char...
i will report whether this code is working correctly or not
 

Are you sure that you actually get a smaller compiled code using a bit variable there? I'm dubious because my guess is that the compiler will create a standard byte-multiple variable for the local function scope, to hold the 'bit', and might even generate more code to do so.

Have you tested it (in Keil) and compared the compiled size with both a bit and a char variable? If you have multiple bit variables in that function though, then it might then consolidate them, saving variable storage space.

If you do get a smaller code with the bit variable as in your code, then I'll be impressed with the compiler.
 
Thanks.. Nice information...

Actually i don't know what compiler do before this post, i though bit will only take one bit, but it will form a multibyte from a byte..

I got it..

Now i don't know regarding the code size, that was just my guess..

Anyways thanks alot for help..
 

You could use bool, if your compiler supports stdbool.h, which is pretty standard.
 

Sorry my compiler doesn't support bool..

Even changing to int doesn't fulfill the required task..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top