HOW DO I USE A PUSH BUTTON TO TURN ON AND OFF A RELAY CONNECTED TO PIC16F877A – electroSome https://electrosome.com/topic/using-push-button-to-turn-on-and-off-a-relay-pic16f877a/feed/ Sat, 18 Mar 2023 05:00:09 +0000 https://bbpress.org/?v=2.6.9 en-US https://electrosome.com/topic/using-push-button-to-turn-on-and-off-a-relay-pic16f877a/#post-12661 <![CDATA[HOW DO I USE A PUSH BUTTON TO TURN ON AND OFF A RELAY CONNECTED TO PIC16F877A]]> https://electrosome.com/topic/using-push-button-to-turn-on-and-off-a-relay-pic16f877a/#post-12661 Tue, 05 Jul 2016 12:02:20 +0000 ebenmoore I have been having troubles doing the above topic and i will love if you guys can help me out.

I started programming few weeks back. I want to design a switch in which when the push button is pressed, my fan will ON, and when i need to turn it of, i press the same push button. so here is my code below.

#define OUTPUT 0
#define INPUT 1
#define ON 1
#define OFF 0
#define SWITCH1 PORTC.F0

#define LED1 PORTD.F0

void main() {

TRISC=INPUT;    TRISD=OUTPUT;
PORTC=OFF;       PORTD=OFF;

while(1){
if(SWITCH1==ON){
delay_ms(100);
if(SWITCH1==ON){
LED1=ON;
delay_ms(100);
}           }

if(SWITCH1==ON)
{
delay_ms(100);
if(SWITCH1==ON){
LED1=OFF;
delay_ms(100);
}          }

}

I will love to hear response from my fellow programmers. Thanks

]]>
https://electrosome.com/topic/using-push-button-to-turn-on-and-off-a-relay-pic16f877a/#post-12674 <![CDATA[Reply To: HOW DO I USE A PUSH BUTTON TO TURN ON AND OFF A RELAY CONNECTED TO PIC16F877A]]> https://electrosome.com/topic/using-push-button-to-turn-on-and-off-a-relay-pic16f877a/#post-12674 Sun, 10 Jul 2016 05:26:45 +0000 Ligo George Which is the compiler you are using ?? Following links might help you.

 

]]>