Blinking a Led connected in sink mode .

 

 Code : 

 #include<reg51.h>                                           //  Include 8051 library.
 sbit led = P1^0;                                                 //  Set the port where the led is connected.
 void delay (int t);                                              // Delay for turning ON and OFF LED,
 void main()                                                       // Main function starts
{
    led = 1;                                                          // Led turned OFF.
    while(1)                                                        // Infinite loop.
{
        led = 0;                                                      // Led turned ON.
        delay(2);                                                   // Delay function calling.
        led = 1;                                                     // Led turned OFF.
        delay(2);                                                  // Delay function calling.
}
}
void delay(int t)                                               // Delay function
{
    int i ,j;                                                          // Assigning integer i & j. 
       for(i=0;i<100*t ; i++)                              // For loop for delay
           for(j=0;j<=1275;j++);                         // Nested  For loop for delay
}


     :  Circuit Diagram     

        

           Led is connected in sinking mode. Sinking mode is when cathode of          LED is connected to Port of 8051 and anode is connected to Vcc.

            A ballast resistor is added in series with led to limit the flow of current       through the led and prevent excess current that can blow the led. 


       
        

Blinking Led Result   : 

   Initially we make the port(P1.0) high for the led to turn off.

  As soon as port(P1.0) becomes low the led forward biases and it turns on.

A delay function is used to provide an interval between switching ON and OFF of  led .

Once the delay time completes the port turns high the led switches off and the whole process keeps on repeating because of while infinite loop.
 


Comments