Advertisement
hidromotic

BlinkSimetrico

May 3rd, 2020
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. /*
  2.  * File:   demo.c
  3.  * Author: Ing. Alejo S. Giles
  4.  *
  5.  * UNLPam
  6.  * Fac. de Ingeniería
  7.  * Computación II
  8.  *
  9.  * Created on 29 de abril de 2020, 17:26
  10.  *
  11.  * Compilador: XC8
  12.  *
  13.  * Funcionalidad:
  14.  * Blink Simetrico
  15.  *
  16.  */
  17. #include "config.h"
  18.  
  19. //Conectamos un LED en RD0
  20. //Escribiendo el valor los registro
  21. //#define CONFIGURAR_LED_TEST       TRISD = TRISD & ~(1<<0)
  22. //#define ENCENDER_LED_TEST     LATD = LATD | 1
  23. //#define APAGAR_LED_TEST           LATD = LATD & 0b11111110
  24. //#define CS_LED_TEST               2
  25.  
  26. //Accediendo por el nombre del bit
  27. #define CONFIGURAR_LED_TEST     TRISD0=0
  28. #define ENCENDER_LED_TEST       LD0=1
  29. #define APAGAR_LED_TEST         LD0=0
  30. #define CS_LED_TEST             5
  31.  
  32. //Accediendo mediante la unión
  33. //#define CONFIGURAR_LED_TEST   TRISDbits.RD0=0
  34. //#define ENCENDER_LED_TEST     LATDbits.LD0=1
  35. //#define APAGAR_LED_TEST       LATDbits.LD0=0
  36. //#define CS_LED_TEST           10
  37.  
  38. void BlinkSimetrico(void)
  39.     {
  40.     static unsigned long centiseg_ini=0;
  41.     static bit led=0;
  42.    
  43.     if(centiseg-centiseg_ini < CS_LED_TEST) return;
  44.     centiseg_ini=centiseg;
  45.    
  46.     led= !led;
  47.    
  48.     if(led) ENCENDER_LED_TEST;
  49.     else    APAGAR_LED_TEST;
  50.  
  51.     }
  52. void main(void)
  53.     {
  54.     setup();
  55.     CONFIGURAR_LED_TEST;
  56.    
  57.     while(1)
  58.         {
  59.         BlinkSimetrico();
  60.         }
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement