Sunday, July 3, 2011

mikroC Pro v4.60 bug

Serendipitiously the mikroC Pro v5.00--successor to v4.60--was just released a couple of days ago. Because I ran into a brick wall programming the PIC12F1822 with the 4.60. The firmware compiled without a hitch for the PIC12F615 but then the compiler started going bananas when I changed the MCU to 12F1822 (had to change the MCU because it turns out I need EEPROM which unfortunately doesn't exist in the 12F615). After systematically commenting out various parts of the program to isolate what was tripping the compiler, I narrowed down the problem to a local variable that the 4.60 demanded be initialized, else it would give me a "362 Not enough RAM 'R15' P12F1822.c" error message upon compilation. Here's an example. The following will result in an error:

char  i;

void Mozza()
{
  char i;
  for (i=1; i<8; i++)  ;
}

void main()
{
  Mozza();
  while(1) ;
}
You can change for (i=1; i<8; i++) to something else, like PORTA += i; and the compiler will cough out the same error message. On the other hand, the following versions will compile properly:

char  i;

void Mozza()
{
  char i=0;    // no error if variable initialized
  for (i=1; i<8; i++)  ;
}

void main()
{
  Mozza();
  while(1) ;
}


char  i;

void Mozza()
{
  // char i;   no error if global variable is used
  for (i=1; i<8; i++)  ;
}

void main()
{
  Mozza();
  while(1) ;
}
So using a global variable or initializing the local var should've been an easy workaround. Unfortunately, when mikroC's built-in EEPROM write functions are present even these tricks fail to lick the problem.

I just installed v5.00 and they've apparently fixed this bug. The firmware (still a work in progress) has thus far compiled without the error 362 message popping up.

No comments:

Post a Comment