HOW DO I USE A PUSH BUTTON TO TURN ON AND OFF A RELAY CONNECTED TO PIC16F877A

Home Forums Microcontrollers PIC Microcontroller HOW DO I USE A PUSH BUTTON TO TURN ON AND OFF A RELAY CONNECTED TO PIC16F877A

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12661
    ebenmoore
    Participant

    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

    #12674
    Ligo George
    Keymaster

    Which is the compiler you are using ?? Following links might help you.

     

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
>