Hollllaaaaaa!!!!!!!
Estoy haciendo un programa que recibe pulsos por RB0, utilizando el timer1 y visualizo la frecuencia por un lcd. Os pego el programa:
#include <18f4550.h>
#fuses HS,MCLR,NOWDT,NOPROTECT,NOPUT,BROWNOUT,NOPBADEN,NOLVP,NOCPD,DEBUG
#use delay(clock=20000000)
#use fast_io(B)
#include "lcd.c"
float const uSxTick = 0.2; // Microsegundos por Tick de TMR1 a 20 Mhz
///////////////////////////////////////////////////////////////////////////
// variables a guardar //
///////////////////////////////////////////////////////////////////////////
long t1;
long tt;
float st1;
float st_tot_overflow;
float f;
float f_final;
int n_overflow;
long t_tot_overflow;
long alarma_max=150;
long alarma_min=0;
long frecuencia();
/////////////////////////////////////////////////////////////////////////
//
// Interrupción por externa por cambio de flanco en RB0 //
//
/////////////////////////////////////////////////////////////////////////
#int_ext
void handle_ext_int()
{
t1=get_timer1();
set_timer1(0);
n_overflow=0;
output_high (PIN_A0);
delay_ms(200);
output_low (PIN_A0);
}
#int_timer1
void overflow()
{
++n_overflow;
}
void main ()
{
/////////////////////////////////////////////////inicializaciones generales///
delay_ms(333); // Espero a que todo se estabilice e ...
disable_interrupts(global); // Inicializo el Micro y ...
disable_interrupts(int_timer1); // deshabilitando todo lo no necesario ...
disable_interrupts(int_rda);
disable_interrupts(int_ext);
disable_interrupts(int_ext1);
disable_interrupts(int_ext2);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_0(RTCC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_b_pullups(FALSE);
delay_ms(333);
/////////////////////////////////////////////////////////////////////////
set_tris_b(0xFF);
lcd_init();
Delay_ms(1000);
lcd_putc("\f");
lcd_putc(" pulsometro \n");
Delay_ms (1000);
ext_int_edge(0,L_to_H);
enable_interrupts(int_ext); // Habilito las interrupciones necesarias
enable_interrupts(int_timer1);
clear_interrupt(int_ext);
clear_interrupt(int_timer1);
enable_interrupts(global);
while (true)
{
lcd_putc("\f");
lcd_gotoxy (2,10);
printf(lcd_putc,"%5.2f \n",f_final);
delay_ms (1000);
}
}
////////////////////////////////////////////////////////////////////////////////
//
// funciones
//
////////////////////////////////////////////////////////////////////////////////////
long frecuencia ()
{
st1 = uSxTick * t1; // calculo el tiempo en microsegundos
t_tot_overflow = (((2^16)-1) * n_overflow); // ticks de todos los overflow
st_tot_overflow = (t_tot_overflow * uSxTick); //tiempo overflows
tt = st_tot_overflow + st1; //tiempo total
f = 1 / (tt * 1000000); // frecuencia
f_final = f * 60;
return (f_final);
}
La interrupción del salto salta porque el led de A1 se enciende cada vez que llega un pulso pero no consigo visualizar en el display el tiempo, ya que sólo veo 0.00.
He estado mirando unos ejemplos de la pagina de redpic pero no encuentro el fallo que tengo. ¿me podeis echar un cable?
muchas gracias. No sabeis lo que me está ayudando este foro para ir haciendo mis programillas porque hace unas semanas no sabía ni lo que era el c
