code not read by compiler

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
press9761
Posts: 9
Joined: 18 Dec 2010 01:52

code not read by compiler

#1 Post by press9761 » 14 Jun 2011 19:11

Hello

I see the compiler is not reading some of my code. I think this has to do with code optimization however,..I'm not sure.
I made a small function that sets some register bits. I saved that function (called config) as a .H file and included it into the project.
When I run the code, I see the simulator skips right over it. When testing it, I see it doesn't work. When I place the same instructions in my
main function it works.

Let me show you what I mean

Code: Select all

sbit  ack_led at portc.b0;              // make an alias for the led_ack pin
#include "config_sys.h"
void main() {
      config();
    while(1){
      delay_ms(500);
      ack_led=1;
      delay_ms(500);
      ack_led=0;
    }
}

In the function "config()" this is contained:

Code: Select all

void config(void){
 //set up system clock to run at 8 Mhz
////////////////////////////////////////////////////////////////////////////////
 OSCCON.b6=1;
 OSCCON.b5=1;
 OSCCON.b4=0;  //8mhz
 OSCCON.b1=1;
////////////////////////////////////////////////////////////////////////////////
ANSEL.AN4=1;
TRISC.TRISC0=0;
return;
}
I can see in the simulator that all the code in "config()" is skipped right over.
When I run the code,...it doesn't work.

However, when I place the instructions found in "config()" in the main() function I can see the
simulator reads the instructions I can also see that it works when I test it on the actual chip.

Let me show you what I mean:
(this code works fine)

Code: Select all

sbit  ack_led at portc.b0;              // make an alias for the led_ack pin
#include "config_sys.h"
void main() {
config(); 
//set up system clock to run at 8 Mhz
////////////////////////////////////////////////////////////////////////////////
 OSCCON.b6=1;
 OSCCON.b5=1;
 OSCCON.b4=0;  //8mhz
 OSCCON.b1=1;
////////////////////////////////////////////////////////////////////////////////
 ANSEL.AN4=1;
 TRISC.TRISC0=0;
 while(1){

  delay_ms(500);
  ack_led=1;
  delay_ms(500);
  ack_led=0;
  }
Just like in the previous code, all the instructions in "config" are skipped.
However, the same instructions are fallowed in main().

My questions is why is this happening???
How can I know when this is going to happen??
What can I do to avoid this??

I have seen this before in more complicated code. It's hard to debug your code when instructions are not being fallowed.
What an I doing wrong?

I have other config files that I use, they include many more instructions, they compile fine. Why?


Thank you

JP

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: code not read by compiler

#2 Post by slavisa.zlatanovic » 15 Jun 2011 10:53

Hi!

Please, create a minimal project which depicts the issue you're talking about and send it to me.
slavisa.zlatanovic@mikroe.com
I'll try to reproduce it and suggest further steps.
Also, tell me which compiler version are you using?
Thanks!
Best regards
Slavisa

Post Reply

Return to “mikroC PRO for PIC General”