Ticker

6/recent/ticker-posts

Pushbutton with delay for turn on led



This code to turn ON the LED for 0.5 sec(500) when switch is pressed. What i use Microcontroller AT89C51 and use port 1 for pushbutton and port 2 for output LED.





Programming c++ for Keil 

#include /*special functionregister declarations*/
sbit LED_pin = P2^0;  // Defining LED PIN
sbit Switch_pin = P1^0;  // Defining Switch PIN
void Delay(int); // Function Prototype declaration
void main(void)
{
Switch_pin = 1; // Making Switch PIN Input
 while(1)
{
if (Switch_pin == 0) //if switch pressed
{

LED_pin = 0; //led will turn on
Delay(500); //delay for 0.5 sec
}
 else
{
       LED_pin = 1; //led turn off
Delay(500); //delay for 0.5 sec
}
}
}
void Delay(int k) //this for delay
{
int i;
for(i=0;i }// end of main


Catat Ulasan

0 Ulasan