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

Receiving Pulses on INT0 interrupt Pin on the LPC932

Hi is there anyway of knowing if the LPC is receiving pulses on its INT0 pin. I have it already set up like this:
IT0 = 1; //Pulses are edge detected
EX0 = 1; //interrupt enable bit
EA =1;

It works fine, but is there anyway to find out if the pulses have stopped coming into this pin? The time the pulses will be present at this pin is unknown.
This message is also posted at http://www.8052.com/forum/post.phtml

Parents Reply Children
  • Here is Stefan, this is the whole program I am testing with out success.
    Thank you


    #include <Reg932.h>
    #include <stdio.h>
    #include <intrins.h>



    void init(void);
    void brkrst_init(void);
    void Time_Base(void);

    unsigned int Sec_Counter = 0;

    void Main(void)
    {
    P2 = 0x00;
    P0 = 0x00;

    init(); // configure ports
    brkrst_init(); //enable UART break detect
    Time_Base();

    }

    void init(void)
    {
    P0M1 = 0x00;
    P0M2 = 0xCD; // Quasi-bidirectional
    P1M1 = 0x00; // Push-pull
    P1M2 = 0xFF;
    P2M1 = 0x00; // push pull output
    P2M2 = 0xFF;
    P1M1 |= 0x18; // make INT0 and INT1 input pins
    P1M2 &= 0xE7;
    ES = 1; // enable UART interrupt
    EA = 1;
    }

    void brkrst_init(void) // This function allows ISP entry through the UART break detect
    {
    SCON = 0x50; // select the BRG as UART baud rate source, pg. 60
    SSTAT = 0x00; //Timer1
    BRGR0 = 0xF0; // 9600 BAUD at @ 7.373MHz internal RC oscillator
    BRGR1 = 0x02; //timer increments every .0271 microsec.
    BRGCON = 0x03; // enable BRG, pg. 59
    AUXR1 |= 0xC0; // enable reset on break detect, pg. 102
    }

    void UART(void) interrupt 4 //Interrupt number for serial port
    {
    RI = 0; // clear receive interrupt flag
    }

    void Time_Base(void)
    {
    ET0 =1;
    TR0 = 0;
    TMOD |= 0x01;
    TAMOD = 0x00;
    TH0 = (65536-30720)/256; // 34816
    TL0 = (65536-30720)%256; // .2
    TF0 = 0;
    EA = 1;
    TR0 = 1;
    }


    void timer(void) interrupt 1 using 1
    {
    Sec_Counter++;
    if (Sec_Counter == 20) // if 1 sec have passed
    {
    Sec_Counter = 0;
    P2 = 0xFF;
    TR0 = 0;
    }
    }

  • This version of the program differs from the earlier one in the timer ISR, which is no longer calling Time_Base(). The ISR needs to clear the overflow flag (TF0) so that the interrupt can re-occur. And since this is a one-shot timer mode, the ISR must also reload the timer registers. I would expect this program to produce one timer interrupt (50 msec after main finishes, assuming the timer values are calcuated correctly).

    When posting source code, if you put the text between the "pre" and "/pre" tags, it will preserve indentation on the left.

    Try something like:

    void T0_Start (void)
        {
        TH0 = (65536-30720)/256; // 34816
        TL0 = (65536-30720)%256; // .2
        TF0 = 0;
        }
    
    
    void Time_Base(void)
        {
        ET0 =1;
        TR0 = 0;
        TMOD |= 0x01;
        TAMOD = 0x00;
    
        T0_Start();
        EA = 1;
        TR0 = 1;
        }
    
    
    void timer(void) interrupt 1 using 1
        {
        T0_Start();  // start timer again
    
        Sec_Counter++;
        if (Sec_Counter == 20) // if 1 sec have passed
            {
            Sec_Counter = 0;
            P2 = 0xFF;
            TR0 = 0;
            }
        }
    

  • Drew Davis I made the changes you posted. It still does not work. I tried it with emulator and it single steps, jumps into the ISR, reloads the timer, but does not clear TF0 flag bit. It increments the sec_counter variable once though. Did you try it yourself. did it work for you. I tried with the actual chip LPC932 revision F and it did not work...I say that because it did not turn on P2 LED's.
    What would be the next step.


    #include <Reg932.h>
    #include <stdio.h>
    #include <intrins.h>



    void init(void);
    void brkrst_init(void);
    void Time_Base(void);
    void T0_Start(void);

    unsigned int Sec_Counter = 0;

    void Main(void)
    {
    P2 = 0x00;
    P0 = 0x00;

    init(); // configure ports
    brkrst_init(); //enable UART break detect
    Time_Base();

    }

    void init(void)
    {
    P0M1 = 0x00;
    P0M2 = 0xCD; // Quasi-bidirectional
    P1M1 = 0x00; // Push-pull
    P1M2 = 0xFF;
    P2M1 = 0x00; // push pull output
    P2M2 = 0xFF;
    P1M1 |= 0x18; // make INT0 and INT1 input pins
    P1M2 &= 0xE7;
    ES = 1; // enable UART interrupt
    EA = 1;
    }

    void brkrst_init(void) // This function allows ISP entry through the UART break detect
    {
    SCON = 0x50; // select the BRG as UART baud rate source, pg. 60
    SSTAT = 0x00; //Timer1
    BRGR0 = 0xF0; // 9600 BAUD at @ 7.373MHz internal RC oscillator
    BRGR1 = 0x02; //timer increments every .0271 microsec.
    BRGCON = 0x03; // enable BRG, pg. 59
    AUXR1 |= 0xC0; // enable reset on break detect, pg. 102
    }

    void UART(void) interrupt 4 //Interrupt number for serial port
    {
    RI = 0; // clear receive interrupt flag
    }

    void Time_Base(void)
    {
    ET0 =1;
    TR0 = 0;
    TMOD |= 0x01;
    TAMOD = 0x00;
    T0_Start();
    EA = 1;
    TR0 = 1;
    }


    void timer(void) interrupt 1 using 1
    {
    T0_Start(); // start timer again

    Sec_Counter++;
    if (Sec_Counter == 20) // if 1 sec have passed
    {
    Sec_Counter = 0;
    P2 = 0xFF;
    TR0 = 0;
    }
    }

    void T0_Start (void)
    {
    TH0 = (65536-30720)/256; // 34816
    TL0 = (65536-30720)%256; // .2
    TF0 = 0;
    }

  • The ISR needs to clear the overflow flag (TF0) so that the interrupt can re-occur
    no need, quoting "the bible"
    Cleared by hardware as the program vectors to the interrupt routine.

    Erik

  • Erik, TF0 could be cleared by software as well...But can any one try it on his simulator or emulator...please.
    Thank you

  • void Main(void)
    {
    P2 = 0x00;
    P0 = 0x00;

    init(); // configure ports
    brkrst_init(); //enable UART break detect
    Time_Base();

    }

    What do you think happens after the call to Time_Base()?

    Stefan