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;
}
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;
}
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