<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3X8HLBGM49"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-3X8HLBGM49');
</script>/*
 * File:   main.c
 * Author: Dudas Levente
 * MPLAB-X
 * Created on 2016. marcius 19., 12:54
 */

#include <stdio.h>
#include <stdlib.h>
#include <pic.h>

__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_ON);
__CONFIG(WRT_OFF & STVREN_ON & BORV_LO & LVP_OFF);

unsigned int ADC(unsigned char ch);
void delay(unsigned int k);
void villam(unsigned int d);

int main(int argc, char** argv)
{
    unsigned int s = 0;
    unsigned int sm = 0;
    PORTA  = 0;
    PORTB  = 0;
    PORTC  = 0;
    LATA   = 0;
    LATB   = 0;
    LATC   = 0;
    TRISA  = 3;
    TRISB  = 0;
    TRISC  = 0;
    ADCON0 = 1;
    ADCON1 = 0b10000000;
    ANSELA = 3;

    while(1){
        sm = s;
        s = ADC(0);
        if( sm < s - 10 ) villam(120);
    }

    return (EXIT_SUCCESS);
}

unsigned int ADC(unsigned char ch){
    ADCON0 = 1 | ( ch << 2 );
    GO = 1;
    while(GO);
    return ADRESH * 256 + ADRESL;
}

void delay(unsigned int k)
{
    while(k>0) k--;
}

void villam(unsigned int d)
{
    unsigned char i;
    unsigned char t = 1;
    for( i = 0; i < 8; i++ ){
        LATC |= t;
        t 