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

Proteus simulation 4x4 Matrix Keypad with Arduino and LCD screen

Digital Clock with Arduino and RTC Module and P10 LEDmatrix

Interfacing KY038 sound sensor with Raspberry pi Pico