Advertisement
RuiViana

Temporizador.c

Jun 8th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. //######################################################################
  2. //PROJETO : TEMPORIZADOR COM DOIS BOTAO
  3. //NOME:..............................................................
  4. //             PIC12F675                                      COPILADOR:   MIKROC VERSAO 4.15.0.0
  5. // PORTA PARA POTENCIOMETRO GPIO.F0
  6. //###########################################################################
  7.  
  8. #define BOTAO1 GPIO.F1          // aciona
  9. #define BOTAO2 GPIO.F2          // aciona
  10. #define LED GPIO.F4             // led que indic teporizando
  11. #define RELE GPIO.F5            // saida do rele
  12.                                 // GPIO.F0 ligado o potenciometro 10k
  13. int leitura = 0;
  14. //-----------------------------------------
  15. void main()
  16. {
  17.   ANSEL = 0b00000001;           // Seleciona o AN0 como entrada analógica
  18.   ADCON0 = 0b00000001;          // Seleciona a entrada AN0
  19.   CMCON = 7;                    // Desliga comparadores
  20.    
  21.   TRISIO =  0b00000111; ;       // GPIO.F0 seja uma entrada
  22.   GPIO = 0;                     // Inicia tudo em low
  23.  
  24.   while(1)                      // Loop
  25.   {
  26.     leitura = ADC_Read(0);      // Leia analogico em leitura
  27.     while ((Button(&GPIO, 1, 1, 0)) & (Button(&GPIO, 2, 1, 0)))  // Se ambos botoes estao em LOW
  28.     {
  29.        leitura--;                   // Decrementa valor de leitura
  30.        delay_ms(1);                 // delay de 1 ms
  31.        if (leitura <=0)             // Se a leitura for igual ou menor que 0
  32.        {
  33.          RELE = 1;                  // Acione rele
  34.          LED = 1 ;                  // Acende LED
  35.        }
  36.        delay_ms(100);               // taxa de atualização do ADC
  37.     }                               // end while
  38.   }                                 // end main
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement