// PIC12F675 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG
#pragma config FOSC = INTRCCLK  // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // GP3/MCLR pin function select (GP3/MCLR pin function is MCLR)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF         // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)


#define __XTALFREQ 4000000
#define relay GP0
#define kapcsolo GP1
void main(void)
{
    GPIO=0;
    TRISIO=0b00111110;
    ANSEL=0x00; //MINDEN PORT DIGIT
    OPTION_REGbits.nGPPU=0; //felhúzás engedélyezés
    WPU=0b00000010;
    relay=0;
    //int alma=1;
    while(1) 
    {
       // if(kapcsolo==1) alma=1;
        
             if(relay==0 && alma!=0)
                {
                 if(kapcsolo==0)
                     {
                     __delay_ms(20);
                      while(kapcsolo==0){};    
                     }
                 relay=1;
                }
        
             if(relay==1)
                {
                 if(kapcsolo==0)
                  {
                     __delay_ms(20);
                     while(kapcsolo==0){};    
                  }
                relay=0;
                }
        
            /*if(relay==1 && kapcsolo==0)
            {
             __delay_ms(50);
             if(kapcsolo==0)
             relay=0;   
             alma=0;
            }   */
           
    }
}