ON/OFF with Push button using PIC16F877A microcontroller






 void main() {


     trisb.f0=1;     // set port B 0 as an input

     trisb.f1=1;     // set port B 1 as an input

     trisb.f2=0;     // set port B 2 as an output

     portb.f2=0;     //set default walue of port B is LOW



     while(1)

     {

            if(portb.f0==1)  //button 1 pressed if value of port B 0 is equal to 1 or HIGH 

            {

                portb.f2=1;  //turn on the led.set the value of Port B2 to High



            }

            if(portb.f1==1) //button 2 pressed.if value of port B 1 is equal to 1 or HIGH

            {

               portb.f2=0;  //tum off the LED.set the value of Port B2 to Low

            }




     }


}

Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico