Page 1 of 1

16F877 Tutorial PR4 and PR5 Compilation errors

PostPosted: Wed Jan 11, 2012 11:30 pm
by ddkeo
Hi,

Can anyone help me with a compilation error when trying to compile a couple of the 16F877 Tutorial Projects PR4 and PR5.

I am using MPLAB IDE 8.30 and HI-TECH 9.65PL1compiler (tried both Lite and PRO versions and also 9.60 Lite and PRO)

Error is [712] C:\.....\Project_4\lcd.c; 276. can't generate code for this expression (same error for both PR4 and PR5)

The lcd.c file is the same one as used in all the projects that use an LCD and it compiles fine in PR1 and PR13 (haven't tried the others).

Any ideas? or has anyone managed to compile these without any problems?

Thanks,
Dave (ddkeo)

Re: 16F877 Tutorial PR4 and PR5 Compilation errors

PostPosted: Thu Jan 12, 2012 12:11 am
by ddkeo
Further to my above post I have now tried to compile all the other projects that use an LCD and all failed to compile with the same error message except PR15 which had two error messages. Below is the error messages and code snippets for PR15;

Error message [712] C:\.......\lcd.c; 276. can't generate code for this expression

Error line:

unsigned int ui_decimal[5] ={ 0 };

Code snippet:

void lcd_bcd(unsigned char uc_digit, unsigned int ui_number)
{
unsigned int ui_decimal[5] ={ 0 };
//extract 5 single digit from ui_number
ui_decimal[4] = ui_number/10000; // obtain the largest single digit, digit4
ui_decimal[3] = ui_number%10000; // obtain the remainder
ui_decimal[2] = ui_decimal[3]%1000;
ui_decimal[3] = ui_decimal[3]/1000; // obtain the 2nd largest single digit, digit3
ui_decimal[1] = ui_decimal[2]%100;
ui_decimal[2] = ui_decimal[2]/100; // obtain the 3rd largest single digit, digit2
ui_decimal[0] = ui_decimal[1]%10; // obtain the smallest single digit, digit0
ui_decimal[1] = ui_decimal[1]/10; // obtain the 4th largest single digit, digit1

if (uc_digit > 5) uc_digit = 5; // limit to 5 digits only
for( ; uc_digit > 0; uc_digit--)
{
lcd_putchar(ui_decimal[uc_digit - 1] + 0x30);
}
}


Error message [712] C:\.......\Project_15.c; 56. can't generate code for this expression

Error line:
unsigned int data[4] = { 0 };

Code snippet:

while (p_con_status) // loop forever if PS2 controller is Connected to SKPS
{
unsigned char no = 0;
unsigned int data[4] = { 0 };

for(no=0 ; no<16 ; no++) // loop from 0 to 16 decimal
{
uc_skps(no); // check the skps
case_num = no; // save 'no' at 'case_num' for case swtching
if (RCREG == 0) // if SKPS is detected a button pressed on PS2
{
display(); // display text on LCD
no = 0; // reset 'no' back to 0
}
}

From the above it would seem that the the problem is with unsigned integers (see Error Lines above)

It would be nice to know if anyone has managed to compile any or the the following 16F877 Tutorial projects; PR4,PR5,PR6,PR7,PR9,PR10 or PR15 and if so which version of MPLAB and which compiler did they use?

Also maybe someone at Cytron could advise what setup they used to compile the supplied code?

Thanks again,
Dave (ddkeo)

Re: 16F877 Tutorial PR4 and PR5 Compilation errors

PostPosted: Fri Jan 13, 2012 6:30 pm
by ddkeo
HI,

For anyone who is interested, I have now resolved this problem for all put PR5 which I still cannot compile.

BTW these projects are The SK40C Tutorial Projects which you can find at:
http://tutorial.cytron.com.my/2011/08/0 ... -tutorial/ and not the Project DIY ones shown on the Cytron web site. Sorry for any confusion!

The error message [715] can't generate code for this expression - is due to most of the recent Hi-Tech compilers being unable to generate code for so called "complex expressions"..!!!! (see my Code snippets in previous post for examples).

However after a great deal of testing I found that Hi-Tech Compiler V9.70 WILL compile them with no problem. So it would seem that all the later versions of Hi-Tech's compilers all have (in Hi-Tech's words) a "Limitation" (I think they mean a bug!) which they are too lazy to fix..!!!

Their solution..!! - "The expressions should be simplified to work around this. This may require the use of additional variables to store intermediate results. This is most likely with long integer or floating-point arithmetic" - I.E its not their problem any more, it's now ours!

Anyway I will just stick to using V9.70 and save myself all the hassle of re-writing the code!

All the best with your projects - and just remember don't write anything that's too complex :lol: ,

Dave (ddkeo)

Re: 16F877 Tutorial PR4 and PR5 Compilation errors

PostPosted: Mon Jan 16, 2012 1:27 pm
by ober
ddkeo WROTE:HI,

For anyone who is interested, I have now resolved this problem for all put PR5 which I still cannot compile.

BTW these projects are The SK40C Tutorial Projects which you can find at:
http://tutorial.cytron.com.my/2011/08/0 ... -tutorial/ and not the Project DIY ones shown on the Cytron web site. Sorry for any confusion!

The error message [715] can't generate code for this expression - is due to most of the recent Hi-Tech compilers being unable to generate code for so called "complex expressions"..!!!! (see my Code snippets in previous post for examples).

However after a great deal of testing I found that Hi-Tech Compiler V9.70 WILL compile them with no problem. So it would seem that all the later versions of Hi-Tech's compilers all have (in Hi-Tech's words) a "Limitation" (I think they mean a bug!) which they are too lazy to fix..!!!

Their solution..!! - "The expressions should be simplified to work around this. This may require the use of additional variables to store intermediate results. This is most likely with long integer or floating-point arithmetic" - I.E its not their problem any more, it's now ours!

Anyway I will just stick to using V9.70 and save myself all the hassle of re-writing the code!

All the best with your projects - and just remember don't write anything that's too complex :lol: ,

Dave (ddkeo)


Dave, thanks for the help. PR5 is very super old project, and I think it is being compiled using very old Hitech Compiler, maybe v9.00 or older. As time pass, compiler upgraded and there are "minor" changes as highlighted shahrul in another thread, but it is not possible for us to catch up those changes and upgrade the sample source code due to too many sample source code. We do appreciate your findings and sharing. Thanks.