# statement limit????

#### gatoulisss

Joined Jan 23, 2015
69
hello everyone...
im programming a pic16f88 mcu and im gonna ask now something that might sound stupid... is there a limit on how many if statements i can use?
im asking this because i have round 7 pages of code, 30% rom free on my mcu and everything works fine but if i add one more if statement on my code then my program reacts like it resets
erasing this if statement everything goes back to normal again

does anyone knows what might be happening?

thank you!!

#### upand_at_them

Joined May 15, 2010
766
Is this C code? The compiler, of course, has to keep track of everything so it can produce a viable machine language (hex) program. So the limit is going to be whatever the developer(s) set, if they are nested. If the statements aren't nested it wouldn't make sense to have a limit.

It's possible that your program is crossing page boundaries and not properly handling it. What compiler are you using?

#### JohnInTX

Joined Jun 26, 2012
4,438
Any compiler warnings?
TS is using Mikro C FWIW.

#### upand_at_them

Joined May 15, 2010
766
Try adding something other than IF's and see if that triggers it.

#### Papabravo

Joined Feb 24, 2006
16,107
One hard limit is the size of the code space. There may be others, but if there are there should be some mention in the compiler documentation

#### gatoulisss

Joined Jan 23, 2015
69
no the if is not nested , im using mikro c and the olny cahnge is one line i dont get any errors
here is the code without the problem :
Code:
trisa=0b00001111;
trisb=0b00000001;
portb=0x00;
porta=0x00;
on=0;
hx=1;
x=0;
j=0;
a=0;
er=1;
flag=0;

sound_init(&portb,3);
and this one is WITH the problem
Code:
trisa=0b00001111;
trisb=0b00000001;
portb=0x00;
porta=0x00;
on=0;
hx=1;
x=0;
j=0;
a=0;
er=1;
flag=0;

if (er==1){x=7;}            //this line is the only change

sound_init(&portb,3);

#### JohnInTX

Joined Jun 26, 2012
4,438
I don't see anything wrong with the 'if' statement.
What version of MikroC are you using and what are you debugging with?

Can you run it in the MikroC debugger? Set a breakpoint at the first EEPROM statement then step through the code. Open the assembly language output window to see what it is actually executing and where it goes at the 'if' statemant. Open the Watch window and inspect PCLATH and STATUS to ensure that the proper bits are set for banking.
Disable the hardware WatchDog Timer if you haven't already.

Consider manually clearing the IRP bit in STATUS after the EEPROM stuff. In MikroC ver 6 (mine) you have to manually handle IRP and the EEPROM registers are in bank 2 which would require the compiler set IRP if it were using FSR... You'd have to look at the assembler output to know for sure.

If that doesn't work, post the whole code with any include files along with the Project Setup information and we can maybe get it to compile and dig deeper for you.

Good luck!

EDIT: be sure you've turned ON Errors, Messages and Hints in the Messages Window.

Last edited:

#### BobaMosfet

Joined Jul 1, 2009
1,768
hello everyone...
im programming a pic16f88 mcu and im gonna ask now something that might sound stupid... is there a limit on how many if statements i can use?
im asking this because i have round 7 pages of code, 30% rom free on my mcu and everything works fine but if i add one more if statement on my code then my program reacts like it resets
erasing this if statement everything goes back to normal again

does anyone knows what might be happening?

thank you!!
You mean you have NESTED if statements? Compiler might have a nesting limit. There are better ways to do whatever you're doing. If you share the code, we all can help you improve the code significantly.