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

momentory blinking of LED in the start

I was writing code in c language for 8051 micro controller. In my application, a switch ( when pressed)connects P3^0 (which is initialized as an input port by writing a 1 to it in the start of the code) to ground. Then my code continuously checks for the switch status and whenever pressed it will make P2^0 high for 1 second time. To P2^0, an LED is connected. in the start of the code i have made P2^0 =0 to avoid the LED blinking before the switch is pressed. I have checked my code and found working fine except for a minor problem. Whenever power is made ON (or controller is reset), the P2^0 becomes high for a moment AND LED also blinks for a moment. This is something i don't want to happen in my application.I am not getting any idea to tackle this problem. kindly help me..

thanking you
satish kumar
mumbai, india.

  • HI SATISH KUMAR PILLAI
    Ur intention is when ever u press the switch then only the led will glow...?
    can you place Ur code here.

    Regards
    Vikram

  • thank you vikram for responding.
    yes my intention is that only.my code is as follows.

    #include <reg51.h>
    sbit in_bit = P3^0;
    sbit out_bit = P2^0;
    void delay_1s();
    void main (void)
    { out_bit =0; in_bit = 1; TMOD = 0x01; while (1) { while (in_bit==1); out_bit = 1; delay_1s(); out_bit = 0; while (in_bit==0); }
    } void delay_1s ()
    { unsigned char count; for (count = 14; count > 0; --count) { TL0 = 0x00; TH0 = 0x00; TR0 = 1; while (TF0 ==0); TR0 = 0; TF0 = 0; } return;
    }

    thanks n regards

    satish kumar pillai.

  • Better to Check the switch condition by using if.
    Late you try this method

    if(our condition)
    {
     LED_ON
    delay function
    }
    else
    {
     LED_OFF
    delay function
    }
    


    ok.

    Regards
    Vikram

  • "Whenever power is made ON (or controller is reset), the P2^0 becomes high for a moment AND LED also blinks for a moment. This is something i don't want to happen in my application."

    You know, by reading the data sheet, that the port pins are "high" in reset state and during the startup code UNTIL you set it low in your code.

    If the LED is ON in reset state, and you do not want that, then change the hardware, so simple is that.

  • Lots of processors are much better at sinking current than sourcing current. So it's quite common to connect the LED so it turns on when the processor pin is held low.

    Obviously, the smart thing to do is to make sure you understand what a processor does with the pins before your program gets in control, and design the hardware based on actual processor behaviour.

  • thank you for your suggestion. in fact in the final project there will be a relay (5v dc operated) instead of LED. earlier i was planning to have a npn transistor with its base connected to p2^0 through a resistor and the relay connected as a collector load. now i feel to avoid the initial unwanted energization of relay during start up, i need to use a pnp transistor with one end of the relay connected to ground. am i thinking in right direction? pl. advise me.if possible can you please suggest some hardware for that? resistance of relay coil = 70ohm.
    thanks n regards
    satish kumar pillai

  • Hi
    Are you check the code...? Now the code was working...?

  • Haven't you spent time with Google?

    Haven't you already found lots of articles how to connect a relay to a 8051 chip?

    You feel Google is bad for you? Not productive to use?