Advertisement
hidromotic

BlinkAsimetrico

May 3rd, 2020
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 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 BlinkAsimetrico(void)
  39.     {
  40.     const int t_off=8;      //
  41.     const int t_on=2;       //200ms
  42.    
  43.     static unsigned long centiseg_ini=0;
  44.     static unsigned char t_espera=0;
  45.     static bit led=0;
  46.    
  47.     if(centiseg-centiseg_ini < t_espera) return;
  48.     centiseg_ini=centiseg;
  49.    
  50.     led= !led;
  51.    
  52.     if(led)
  53.         {
  54.         ENCENDER_LED_TEST;
  55.         t_espera=t_on;
  56.         }
  57.     else   
  58.         {
  59.         APAGAR_LED_TEST;
  60.         t_espera=t_off;
  61.         }
  62.  
  63.     }
  64. void main(void)
  65.     {
  66.     setup();
  67.     CONFIGURAR_LED_TEST;
  68.    
  69.     while(1)
  70.         {
  71.         BlinkAsimetrico();
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement