hidromotic

BlinkSimetrico_PIC

May 6th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. /*
  2.  * File:   demo2.c
  3.  * Author: Alejo
  4.  *
  5.  * Created on 6 de mayo de 2020, 16:13
  6.  */
  7. // Blink --> Activar la salida RD1 un cierto tiempo y desactivar RD1 otro tiempo
  8.  
  9. #include "config.h" //-->  https://pastebin.com/iCVtqpfB
  10. //config.c --> https://pastebin.com/KRXRaxR8
  11.  
  12.  
  13. #define CONFIGURAR_LED_TEST     TRISD1=0
  14. #define ENCENDER_LED_TEST       LD1=1
  15. #define APAGAR_LED_TEST         LD1=0
  16.  
  17. #define ACTIVAR_SALIDA          LD1=1
  18. #define DESACTIVAR_SALIDA       LD1=0
  19.  
  20.  
  21. //#define ACTIVAR_SALIDA       LATD |= 0b00000010       //Poner en alto el bit 0 (RD0)
  22. //#define DESACTIVAR_SALIDA    LATD &= ~0b00000010       //Poner en bajo el bit 0 (RD0)
  23.  
  24. //#define ACTIVAR_SALIDA      LATDbits.LD1=1
  25. //#define DESACTIVAR_SALIDA   LATDbits.LD1=0
  26.  
  27.  
  28.  
  29. void BlinkSimetrico(void)
  30.     {
  31.     static unsigned long centiseg_ant=0;
  32.     const unsigned char tpo_espera=5;
  33.     static bit salida_activada=0;
  34.    
  35.     //Actviar la salida, esperar un tiempo, desactivar la salida, esperar un tiempo
  36.    
  37.     if(centiseg - centiseg_ant < tpo_espera) return;
  38.     centiseg_ant= centiseg;
  39.    
  40.     salida_activada = !salida_activada;
  41.    
  42.     if(salida_activada) ACTIVAR_SALIDA;
  43.     else                DESACTIVAR_SALIDA;
  44.     }
  45.  
  46. void main(void)
  47.     {
  48.     setup();
  49.     CONFIGURAR_LED_TEST;
  50.  
  51.     while(1)
  52.         {
  53.         BlinkSimetrico();
  54.         }
  55.     return;
  56.     }
Add Comment
Please, Sign In to add comment