Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: demo.c
- * Author: Ing. Alejo S. Giles
- *
- * UNLPam
- * Fac. de Ingeniería
- * Computación II
- *
- * Created on 29 de abril de 2020, 17:26
- *
- * Compilador: XC8
- *
- * Funcionalidad:
- * Blink Multidestello
- *
- * Led conectado en el pin 0 del PORTD
- *
- */
- #include "config.h"
- //Escribiendo el valor los registro
- //#define CONFIGURAR_LED_TEST TRISD = TRISD & ~(1<<0)
- //#define ENCENDER_LED_TEST LATD = LATD | 1
- //#define APAGAR_LED_TEST LATD = LATD & 0b11111110
- //#define CS_LED_TEST 2
- //Accediendo por el nombre del bit
- #define CONFIGURAR_LED_TEST TRISD0=0
- #define ENCENDER_LED_TEST LD0=1
- #define APAGAR_LED_TEST LD0=0
- #define CS_LED_TEST 5
- //Accediendo mediante la unión
- //#define CONFIGURAR_LED_TEST TRISDbits.RD0=0
- //#define ENCENDER_LED_TEST LATDbits.LD0=1
- //#define APAGAR_LED_TEST LATDbits.LD0=0
- //#define CS_LED_TEST 10
- void BlinkMultidestello(void)
- {
- const unsigned char t_off=8; //
- const unsigned char t_on=2; //200ms
- const unsigned char cant_pulsos=5;
- static unsigned long centiseg_ini=0;
- static unsigned char t_espera=0;
- static bit led=0;
- static unsigned char pulso=0;
- if(centiseg-centiseg_ini < t_espera) return;
- centiseg_ini=centiseg;
- if(led)
- {
- led=0;
- ENCENDER_LED_TEST;
- t_espera=t_on;
- if(!pulso) pulso=cant_pulsos;
- }
- else
- {
- led=1;
- APAGAR_LED_TEST;
- pulso--;
- if(t_espera) pulso=t_on;
- else pulso=t_off;
- // t_espera=pulso ? t_on: t_off;
- }
- }
- void main(void)
- {
- setup();
- CONFIGURAR_LED_TEST;
- while(1)
- {
- BlinkMultidestello();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement