Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <16F876.h>
  2. #use delay(clock=1000000) //reloj de 4MHz
  3.  
  4. int16 tiempo;
  5. int16 count; //count es ahora la FRECUENCIA de pulsos a visualizar
  6. int display; //indica el dígito a visualizar
  7. const int tabla[10]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x6f};
  8. const int16 factor[4]={1000,100,10,1};
  9.  
  10. #int_EXT
  11. void llega_pulso(void) {
  12. tiempo=get_timer1();
  13. set_timer1(0); //reinicia para nuevo pulso
  14. }
  15.  
  16.  
  17. #INT_TIMER0
  18.  
  19. void refresco_display(void){
  20. output_A(0); //apaga todos los dígitos
  21. output_c(~tabla[count/factor[display]%10]); //pone los segmentos
  22. switch(display) { /////recorre los cuatro dígitos
  23. case 0: output_high(PIN_A0); //enciende decenas
  24. break;
  25. case 1: {output_high(PIN_A1); //enciende unidades y punto decimal
  26. output_low(PIN_C7);
  27. } //fin de case 1
  28. break;
  29. case 2: output_high(PIN_A2);
  30. break;
  31. case 3: output_high(PIN_A3);
  32. break;
  33. } //////fin del switch
  34. if(++display==4) display=0;
  35. delay_ms(5); /////tiempo que se mantiene encendido cada dígito
  36. output_high(PIN_C7); ////apaga el punto decimal
  37. }
  38.  
  39.  
  40. void main() {
  41. //Configuramos temporizadores e interrupciones:
  42. setup_timer_0(T0_INTERNAL | T0_DIV_8);//va a cambiar de dígito cada 8,2 ms aprox.
  43. setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //prescaler máximo para llegar a
  44. //medir frecuencias bajas
  45. enable_interrupts(INT_TIMER0);
  46. ext_int_edge(L_TO_H);//por defecto ya es así
  47. enable_interrupts(INT_EXT);
  48. enable_interrupts(GLOBAL);
  49. while (TRUE) {
  50. delay_ms(10); //actualizamos la medida cada 200ms
  51. count=100000000/((int32)tiempo * 32); //frecuencia en Hz*100
  52. } //fin del while
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement