This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Handle Interrupt

Hi. I'm doing my thesis on 8051 and i'm programming interrupt routines in Keil C and simulate them. But I can't use variables inside interrupt routines because they generate unpredictable effects on simulations. Does anybody can help me please?

Parents
  • I use Modeltech for simulate the program.
    For unpredictable effects I mean that things happen like address bus for reading ROM that goes much much ahead the real limit of the program. This is the situation:
    this part works correctly:

    #include <reg51.h> /* define 8051 registers */
    #include <stdio.h> /* define I/O functions */
    #include <stdlib.h>


    /* Main - Program entry point
    *
    * INPUT: N/A
    * RETURNS: N/A
    */

    unsigned int i;

    void external_int (void) interrupt 0 using 0

    {

    /* The interrupt was generated. */


    P1 = P1 + 1;

    /* Reset Interrupt */


    }


    void main(void)

    {

    /*-----------------------------------------------
    Configure INT0 (external interrupt 0) to generate
    an interrupt on the falling-edge of /INT0 (P3.2).
    Enable the EX0 interrupt and then enable the
    global interrupt flag.
    -----------------------------------------------*/

    IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)

    EX0 = 1; // Enable EX0 Interrupt

    EA = 1; // Enable Global Interrupt Flag

    PS = 0; /* Interrupt Seriale */

    PT1 = 0; /* BBh Priority Interrupt Timer 1 */

    PX1 = 0; /* BAh Priority Interrupt extern INT 1 */

    PT0 = 0; /* B9h Priority Interrupt Timer 0 */

    PX0 = 1; /* B8h Priority Interrupt extern INT 0 */

    P2 = 0; /* Port 2 will be initialized */

    /*
    * Now the counter loop begins. Because this program is intended
    * to run in an embedded system with no user interaction, and will
    * run forever, the rest of the program is placed in a non-exiting
    * while() loop.
    */


    while (1)

    {
    /*
    * This is a very unpredictable method of implementing a delay
    * loop, but remains the simplest. More reliable techniques
    * can be done using the using the built-in timers. In this
    * example, though, the for() loop below will run through 60000
    * iterations before continuing on to the next instruction.
    * The amount of time required for this loop varies with the
    * clock frequency and compiler used.
    */


    for (i = 0; i < 5; i++)


    /* Increment Port 0 */

    P2 = P2 + 1;
    }
    }

    If I change the value of the i variable (or use another variable) inside the interrupt routine suddenly nothing works and strange things happen in the simulation.

Reply
  • I use Modeltech for simulate the program.
    For unpredictable effects I mean that things happen like address bus for reading ROM that goes much much ahead the real limit of the program. This is the situation:
    this part works correctly:

    #include <reg51.h> /* define 8051 registers */
    #include <stdio.h> /* define I/O functions */
    #include <stdlib.h>


    /* Main - Program entry point
    *
    * INPUT: N/A
    * RETURNS: N/A
    */

    unsigned int i;

    void external_int (void) interrupt 0 using 0

    {

    /* The interrupt was generated. */


    P1 = P1 + 1;

    /* Reset Interrupt */


    }


    void main(void)

    {

    /*-----------------------------------------------
    Configure INT0 (external interrupt 0) to generate
    an interrupt on the falling-edge of /INT0 (P3.2).
    Enable the EX0 interrupt and then enable the
    global interrupt flag.
    -----------------------------------------------*/

    IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)

    EX0 = 1; // Enable EX0 Interrupt

    EA = 1; // Enable Global Interrupt Flag

    PS = 0; /* Interrupt Seriale */

    PT1 = 0; /* BBh Priority Interrupt Timer 1 */

    PX1 = 0; /* BAh Priority Interrupt extern INT 1 */

    PT0 = 0; /* B9h Priority Interrupt Timer 0 */

    PX0 = 1; /* B8h Priority Interrupt extern INT 0 */

    P2 = 0; /* Port 2 will be initialized */

    /*
    * Now the counter loop begins. Because this program is intended
    * to run in an embedded system with no user interaction, and will
    * run forever, the rest of the program is placed in a non-exiting
    * while() loop.
    */


    while (1)

    {
    /*
    * This is a very unpredictable method of implementing a delay
    * loop, but remains the simplest. More reliable techniques
    * can be done using the using the built-in timers. In this
    * example, though, the for() loop below will run through 60000
    * iterations before continuing on to the next instruction.
    * The amount of time required for this loop varies with the
    * clock frequency and compiler used.
    */


    for (i = 0; i < 5; i++)


    /* Increment Port 0 */

    P2 = P2 + 1;
    }
    }

    If I change the value of the i variable (or use another variable) inside the interrupt routine suddenly nothing works and strange things happen in the simulation.

Children