simple question regarding interrupts problem

General discussion on mikroC PRO for 8051.
Post Reply
Author
Message
r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

simple question regarding interrupts problem

#1 Post by r.duke » 27 Feb 2015 10:41

i was just wondering why setting the timer 1 overflow enable bit in the interrupt enable register appears to mess with my other interrupts?

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: simple question regarding interrupts problem

#2 Post by darko.minic » 02 Mar 2015 13:06

Hi,

Can you send me some simple zipped project which describes the problem, so I can be able to reproduce it?

Regards,
Darko

r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

Re: simple question regarding interrupts problem

#3 Post by r.duke » 06 Mar 2015 11:02

I initially made this post to help troubleshoot my problem, but once identified the problem was the timer overflow interrupts I rephrased the question.
This is the code i had.

Code: Select all

int on = 0, wet = 0, z = 0, t = 0;

 void Init()
 {
  P0 = 0;                          // starts with leds on
  IE = 0b10100101;               // [1]-enable interrups [00]-reserved [0]-serial [0]T1 (1 inhibits interrupts) [1]ex1 [0]t0 [1]ex0
  Scon = 0b01000000;         // [01]-8-bit uart  [0]-Address recognition disabled [0]-Recieve disabled (simplex) [0000]-Operational bits
  Pcon.B7 = 0;                  // baud rate is not doubled
  Tmod = 0b00100000;          // Timer 1 - [00]-software control [10]-mode 2 (8-bit auto-reload) [0000]-timer 2
  Th1 = 253;                //253 loaded into timer 1 register for 9600 baud
  Delay_ms(100);             // let uart stabilize (test without this, may not be needed)
  } /* Timer 1 could only run when water detection interrupt is triggered */

void timer2() iv IVT_ADDR_ET2 ilevel 0 ics ICS_AUTO 
{
 TF2_bit = 0;          // reset overflow flag
}

 void serial_data_out(unsigned char x)             // function to move character x to sbuf register
{
     SBUF = x;                               // writes character x to SBUF
     while(TI_bit == 0);                     // Waits for transmission to complete
     TI_bit = 0;                             // ckears transmission bit
}

 void interrupt0() iv IVT_ADDR_EX0 ilevel 0 ics ICS_OFF     // Interrupt 0 P3.2
  {
  on = 1;                                   // On/Off indicator
  }

void interrupt1() iv IVT_ADDR_EX1 ilevel 0 ics ICS_OFF   // Interrupt 1 P3.3
     {
     if(on)                                             // serial transmission enabled only if ON
     {
     wet = 1;                                    // set flag
     }
     }



void main() 
{                               // Main program
Init();                                // Init function
while(1){                                 // Unending loop

        if (on)                                  //if on
         {
         if (wet == 0)                         // and if not wet
          {
           P0 = 255;                             // toggle leds before entering idle
           Delay_ms(200);                        // delay to debounce led toggle on press of P3.2
           Pcon.B0 = 1;                          // set device to idle mode
           P0 = 0;
           }
            if (wet == 1)
            {
             for ( z = 0; z < 4; z++ )                 //loop serial data out
              {
                P1 = 255 - z;
                TR1_bit = 1;                            // starts timer (software control)
                serial_data_out('H'); serial_data_out('E'); serial_data_out('L'); serial_data_out('P');

                TR1_bit = 0;                              // stops timer after transmission
                if (z <3)                                 // if message has been sent 3 times or less (ensures no delay before idle mode after 4th transmission)
                 {
                  do                                      // loop timer 2 variable increment
                     {
                     P0 = 255;                             // toggle leds before entering idle
                     T2MOD = 0x00;                         // set up t2
                     T2CON = 0b00000100;                   // run timer 2 (16-bit auto-reload)
                     Pcon.B0 = 1;                          // set device to idle mode
                     z = z;
                     z = z;
                     P0 = 0;
                     t = t ++;                             //increments counter every 71.11mS
                     P2 = (255 - (t*1.808));                // P2 counts to 255 in 10 seconds
                     }while(t <141);                        // loop counter for ten seconds
                     t = 0;                                 // reset t for use during 100s delay
                  }
                    if (z == 3)                            // after 4 transmissions
                    {
                     do
                     {
                     P0 = 255;                             // toggle leds before entering idle
                     T2MOD = 0x00;                         // set up t2
                     T2CON = 0b00000100;                   // run timer 2 (16-bit auto-reload)
                     Pcon.B0 = 1;                          // set device to idle mode
                     z = z;
                     z = z;
                     P0 = 0;
                     t = t ++;                             //increments counter every 2.22 seconds
                     P2 = (255 - (t/5.514));
                     }while(t <1406);                        // come out of loop after 100 seconds
                     t = 0;                                // reset t variable
                     P2 = 255 - t;
                     }
               }
             }
         }
        }
}
I have finished my program for this application, but i am still intrigued as to why the timer interrupt bit seemed to inhibit all interrupts

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: simple question regarding interrupts problem

#4 Post by jumper » 06 Mar 2015 11:35

Could it be so simple that if you enable an interrupt and that interrupt flag is never cleared in your software the interrupt will happen again and again and again .. and seem to lock up the system

r.duke
Posts: 84
Joined: 26 Aug 2014 12:27

Re: simple question regarding interrupts problem

#5 Post by r.duke » 06 Mar 2015 14:53

thanks jumper.
I expected it to be so simple, not that i new what the issue was haha.

Jumpers got the answers!

Post Reply

Return to “mikroC PRO for 8051 General”