LED not working properly after changing from Edge trigger to Level trigger !

Discussion in 'Embedded Systems and Microcontrollers' started by nickatnite, Apr 8, 2009.

  1. nickatnite

    Thread Starter Member

    Mar 31, 2009
    Hey guys,
    I have a 8051 from silabs ( f330 ) . I wrote a program for ISR on it with edge trigger and it was working PERFECTLY !
    but today my boss told me to change it to Level trigger which i did , except the LED is not blinking properly. The pin is set to High , So when there is a level trigger , THE led would turn off !!

    But rather than this happening, The LED is in ON state before the interrupt , except - the light is not as bright.
    and when I give it an interrupt , the led sometimes turns off, sometimes it becomes bright.
    doesn't make sense ..

    It should just toggle between NO led and LED. !! i can't understand why this would happen.

    please give some inputs from your experience or why you think this would happen, I really appreciate your help.
  2. efox


    Aug 8, 2006
    Post your code.
  3. peajay

    Well-Known Member

    Dec 10, 2005
    It sounds like your interrupt signal is inverted. When you think it is inactive, it is actually active, and so your interrupt handler is being called repeatedly, constantly turning the LED on and off, and thus making it appear half brightness. When you think it is active, it is actually inactive, which stops the interrupt handler from being called, and so the LED remains in whichever state it was last in.
  4. nickatnite

    Thread Starter Member

    Mar 31, 2009

    Here's my code

    #include <C8051F330.h>
    #define SYSCLK 245000000
    sbit SW1 = P0^5;
    sbit LED = P1^3;
    void Oscillator_Init (void);
    void Port_Init (void);
    void Ext_Interrupt_Init (void);

    void main (void)
    PCA0MD &= ~0x40;
    Port_Init ();
    EA = 1;


    void Oscillator_Init (void)
    OSCICN = 0x83;


    void Port_Init (void)
    P0MDOUT = 0x20; //p0.5 is skiped in crossbar
    P1MDOUT = 0x08; // p0.5 is push pull digital
    P0SKIP = 0x20; // p1.3 for led is also digital push pull
    XBR1 = 0x40; // disable weak pull up is unchecked

    void Ext_Interrupt_Init (void)

    IT01CF = 0x0D; // Level triggered //p0.5 is active high

    EX0 = 1;

    void INT0_ISR (void) interrupt 0
    LED = !LED; //toggle LED

    what do you think ??