PROTEUS showing Stack overflow error

Thread Starter


Joined Jul 2, 2018
I wanted to generate a delay of 1ms by using PIC18F2550 Timer0 Interrupt Service Routine using MIKROC for pic
when i tried to simulate this in PROTEUS, i got some errors

[PIC18 STACK] PC=0x0038. Stack overflow is forcing device reset. [U1]

Here is my code..
//Timer0, Prescaler 1:8; TMR0 Preload = 6; Actual Interrupt Time : 1 ms//
#define Pulse LATB

/***************Interrupt Service Routine for Timer1******************/
void interrupt_Timer0_ISR()
//void interrupt_1()
if (TMR0IF_bit)
    TMR0IF_bit = 0;    /* Make Timer0 Overflow Flag to '0' */
    TMR0L    = 0x06;

  //Enter your code here
    Pulse =~ Pulse;   /* Toggle PortB at of 500 Hz */


void Timer0_start()
    T0CON = 0xC2;
    TMR0L    = 0x06;/* Load Count for generating delay of 1ms */

    GIE_bit =1;        /* Enable Global Interrupt */
    TMR0IE_bit =1;    /* Enable Timer0 Overflow Interrupt */
    TMR0IF_bit = 0;

void main()
   // OSCCON =0x72;    /* Configure oscillator frequency to 8MHz */
    TRISB = 0;      /* Set as output Port */
    Pulse = 0xff;      /* Send high on PortB */



My question is what is Stack overflow???
Please correct my code if there is any error

Ian Rogers

Joined Dec 12, 2012
Stack overflow is just that.... The stack has 16 levels and your program has achieved 16+..
As your program ONLY has an ISR I assume that a rogue interrupt is firing causing issues..

As you didn't include a snapshot of your config box, I can't see what could be causing your problem..

"Stack overflow" shouldn't even be displayed if the compiler is worth any salt!!
The error is hardware stack and not software stack...…

Is your watchdog running?????


Joined Oct 2, 2009
How does the compiler know which is the interrupt ISR?
Is the name of the ISR predetermined in the interrupt vector table?
Should you not be declaring:
void interrupt Timer0_ISR(void)

Did you clear the interrupt flag in the ISR?


Joined Jul 4, 2015
Mention your oscillator or crystal frequency to fix the code.

You should use something like this.

void interrupt() {
    if((TMR1IE_bit) && (TMR1IF_bit)) {
         TMR1IF_bit = 0;
         //Reload timer here.
         //Set a flag here 
Use flag test in main loop and run the reuired code in main loop and after running the reuired code in main loop clear the flag.