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

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

Post by Nandika » Tue Aug 13, 2013 11:28 pm

Thanks Semi...,
Ellipsis is very nice point.
I don't know sound knowledge about PIC stakes. :(
I must learn it.

Thanks for helping
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 » Tue Aug 13, 2013 11:41 pm

I do still see the same issue in the file.

Your function prototype is,

Code: Select all

void Display();
This should be changed to,

Code: Select all

void Display(int, int);
And on the function definition, it should be as follows,

Code: Select all

void Display(int d0, int d1){
I didn't look at the timer interrupt setting in to detail, but calling the display routine so fast from an interrupt routine is just bad practice. It is enough to update the display 60 times a second (Even 25 or 10 would be ok). Human eyes can't go faster than that.

Stack overflows normally appear when you run the program. When you call the display routine within an interrupt, in a re-entrant situation, this function would be call over an over which leads to a stack overflow. So as mentioned earlier, it is advisable not to call heavy functions within hardware interrupt. I mentioned a method before, so not going to repeat that.

Tab indents are wrong which is not nice in programming. For example, the switch block must be tabbed by 1 and there should be a blank line after the function definition as below. Also, nice to have a little comment to mention what it does.

Code: Select all

// This function do this
int DWOP(int n){//DROBOT.LK PNT ENA

	switch(n){
		case 0:
			return 0xC0;
		case 1:
			return 0xF9;
		case 2:
			return 0xA4;
		case 3:
			return 0xB0;
		case 4:
			return 0x99;
		case 5:
			return 0x92;
		case 6:
			return 0x82;
		case 7:
			return 0xF8;
		case 8:
			return 0x80;
		case 9:
			return 0x90;
		default:
			return 0xBF;
	}
}
Post Reply

Return to “Microcontrollers”