Advertisement
hidromotic

BlinkMultidestello

May 3rd, 2020
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 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 Multidestello
  15.  *
  16.  * Led conectado en el pin 0 del PORTD
  17.  *
  18.  */
  19. #include "config.h"
  20.  
  21. //Escribiendo el valor los registro
  22. //#define CONFIGURAR_LED_TEST       TRISD = TRISD & ~(1<<0)
  23. //#define ENCENDER_LED_TEST         LATD = LATD | 1
  24. //#define APAGAR_LED_TEST           LATD = LATD & 0b11111110
  25. //#define CS_LED_TEST               2
  26.  
  27. //Accediendo por el nombre del bit
  28. #define CONFIGURAR_LED_TEST     TRISD0=0
  29. #define ENCENDER_LED_TEST       LD0=1
  30. #define APAGAR_LED_TEST         LD0=0
  31. #define CS_LED_TEST             5
  32.  
  33. //Accediendo mediante la unión
  34. //#define CONFIGURAR_LED_TEST   TRISDbits.RD0=0
  35. //#define ENCENDER_LED_TEST     LATDbits.LD0=1
  36. //#define APAGAR_LED_TEST       LATDbits.LD0=0
  37. //#define CS_LED_TEST           10
  38.  
  39. void BlinkMultidestello(void)
  40.     {
  41.     const unsigned char t_off=8;            //
  42.     const unsigned char t_on=2;         //200ms
  43.     const unsigned char cant_pulsos=5;
  44.    
  45.     static unsigned long centiseg_ini=0;
  46.     static unsigned char t_espera=0;
  47.     static bit led=0;
  48.     static unsigned char pulso=0;
  49.    
  50.     if(centiseg-centiseg_ini < t_espera) return;
  51.     centiseg_ini=centiseg;
  52.    
  53.     if(led)
  54.         {
  55.         led=0;
  56.         ENCENDER_LED_TEST;
  57.         t_espera=t_on;
  58.         if(!pulso) pulso=cant_pulsos;
  59.         }
  60.     else   
  61.         {
  62.         led=1;
  63.         APAGAR_LED_TEST;
  64.         pulso--;
  65.         if(t_espera)    pulso=t_on;
  66.         else            pulso=t_off;
  67. //      t_espera=pulso ? t_on: t_off;
  68.         }
  69.  
  70.     }
  71. void main(void)
  72.     {
  73.     setup();
  74.     CONFIGURAR_LED_TEST;
  75.    
  76.     while(1)
  77.         {
  78.         BlinkMultidestello();
  79.         }
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement