# PIC12F629 memory overflow

I am new to PIC microcontroller programming. I am trying to programming PIC12F629. I have a hex file (size 518bytes). When I am trying to write using PICkit2, it shows memory overflow. Here is my code:

int main()
{
TRISIO=0b00000111;
// ANSEL=0b00000000;
GPIObits.GP0=0;
GPIObits.GP1=0;
GPIObits.GP2=0;
int count;
while(1)
{
jmp1:
if(GP4==1)
{
goto jmp1;
}
else
{
jmp2 :
GP1=1;
__delay_ms(10000);
GP0=1;
count=0;
jmp3:
if(GP5==1)
{
count=0;
GP2=1;
__delay_ms(40000);
goto jmp5;
}
else
{
count++;
__delay_ms(5000);
if(count==60)
{
GP1=0;
goto jmp5;

}
else
{
goto jmp3;
}
}
jmp5:
GP0=0;
GP2=0;
jmp4:
if(GP3==1)
{
goto jmp2;
}
else
{
if(GP4==1)
{
goto jmp1;
}
else
{
goto jmp4;
}
}
}
}

return 0;
}


Flowchart of intended behaviour:

• Can you edit your question? Add all code inside the code brackets, its barely readable this way. What is the purpose of this code? What have you tried already? – JWRM22 Dec 14 '16 at 6:32
• i have put all code inside the code brackets. i have 4 loops and one timers for 5 minutes. i don't know the timers programming or how to do it. so i use delay_ms repeatedly. plz help me. – Sonu Dec 14 '16 at 6:53
• Did you create the .hex file by compiling (building) your source for the 12F629 target? Could you provide that .hex file? Does the pickit2 recognize the 12F629? – Wouter van Ooijen Dec 14 '16 at 7:19
• yes i have the .hex file. and pickit2 recognize it. how to provide it @WoutervanOoijen – Sonu Dec 14 '16 at 7:35
• meta.stackexchange.com/questions/47689/… – JWRM22 Dec 14 '16 at 7:49

Ok, following on from comments, here's a bit of code that compiles ok, roughly follows what I understand from your flowchart, and which doesn't use any goto's.

You will need to verify the logic, calculate and insert the correct configuration for the timer, and make any other changes that have been caused by my misunderstanding of the logic.

You can see that goto only serves to make the flow more difficult to understand. So, start from something that's more like my code than yours and I think your "memory problem" will go away. I suspect the compiler is/was trying to do something clever with the goto logic and ended up with some recursive implementation or something like that.

Here's my code - note that this is only an example!!

void main()
{
// assumptions:
//    I/P1 is GP4
//    I/P2 is GP5
//    I/P3 is GP3
//    O/P1 is GP1
//    O/P2 is GP0
//    O/P3 is GP2

// set inputs/outputs
TRISIO = 0b111000;

// reset O/P1, O/P2 and O/P3
GP1 = 0;
GP0 = 0;
GP2 = 0;

// main loop
while (1)
{
// wait until I/P1 is low
while (GP4 == 1);

// set O/P1 and O/P2 with delay
GP1 = 1;            // O/P1
__delay_ms(10000L);
GP0 = 1;            // O/P2

// start 5 minute timer
// NB - you need to set the registers according to your clock speed etc.
// I'm not going to do the whole thing for you, but this is the idea:
OPTION_REGbits.T0CS = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS = 0b111;  // you choose the correct prescaler value
TMR0 = 0;                   // zeroise the timer

// wait until timer expires or I/P2 goes high
// NB - the 9999 value is what you need to calculate
// to get a 5 min timeout with your clock and prescaler
// it may be necessary to do this differently if your
// clock is too fast, so maybe a loop with a counter
while (TMR0 < 99999 && GP5 == 0);

// check what just happened ...
if (GP5 == 1)
{
// IP/2 went high, set O/P3
GP2 = 1;
__delay_ms(40000L);
}

// in all cases, reset O/P1, O/P2 and O/P3
GP1 = 0;
GP0 = 0;
GP2 = 0;

// the bottom two decision boxes in your flowchart don't
// make sense, but I have assumed some logic and coded below
// so you can see the general way to avoid goto's

// wait until I/P3 or I/P1 goes high
while (GP3 == 0 || GP4 == 0);
};
}

• thanks. tmro register is 8 bit. so it will contain maximum 255. – Sonu Dec 15 '16 at 6:11
• @Sonu, yes I know, that's why I used an invalid number in my example and made that comment. – Roger Rowland Dec 15 '16 at 6:14