Está en la página 1de 3

use_portb_lcd TRUE

#include < main . h >


#include < LCD2 . c >
#include "PIC16F877A_registers.h"
#bit btn1 = _PORTB . 1
#bit LED = _PORTB . 5
#bit BUZZ = _PORTB . 4
#bit tbtn1 = _TRISB . 1
#bit tLED = _TRISB . 5
#bit tBUZZ = _TRISB . 4
#define cargaTMR1 3036
#define cargaTMR0 61
#define tiempoSonido 2
int16 contador , contador2 , contDelay , contTMR1 ;
int contSeg ;
#INT_EXT //interrupcion para el conteo de pulsos
void ext ()
{
if ( contDelay == 0 )
{
contador ++;
LED = 1 ;
BUZZ = 1 ;
contDelay = tiempoSonido ;
}
}
#INT_TIMER1 //interrupcion para el conteo de segundos
void timer1 ()
{
set_timer1 ( cargaTMR1 );
if ( contTMR1 > 0 )
{
contTMR1 --;
}
else
{
contTMR1 = 9 ; //1 segundo
if ( contSeg > 0 )
{
contSeg --;
}
else
{
contSeg = 19 ; //se carga el contador de segundos para tener 20 seg. 53: contado
r2 = contador ; //se copia el valor del contador hasta los 20seg
contador = 0 ;
}
}
}
#INT_TIMER0 //interrupcion para el conteo de milisegundos del BUZZER 61: void ti
mer0 ()
{

set_timer0 ( cargaTMR0 );
if ( contDelay > 0 )
{
contDelay --;
}
else
{
LED = 0 ;
BUZZ = 0 ;
}
}
void main ()
{
int i ;
//configuracion de puertos de entrada/salida
set_tris_a ( 0xFF );
set_tris_b ( 0xFF );
set_tris_c ( 0xFF );
set_tris_d ( 0xFF );
tbtn1 = 1 ;
tLED = 0 ;
tBUZZ = 0 ;
//resistencia PULL-UP
_RBPU = 0 ;
//configuracion de los TIMERs
LED = 1 ;
enable_interrupts ( GLOBAL | PERIPH | INT_TIMER0 );
enable_interrupts ( INT_EXT_H2L );
enable_interrupts ( INT_TIMER1 );
SETUP_TIMER_1 ( T1_INTERNAL | T1_DIV_BY_8 );
SETUP_TIMER_0 ( T0_INTERNAL | T0_DIV_256 );
//presentacion en pantalla
lcd_init ();
led = 1 ;
lcd_gotoxy ( 4 , 1 );
printf ( lcd_putc , "Espinoza" );
lcd_gotoxy ( 5 , 2 );
printf ( lcd_putc , "Macias" );
delay_ms ( 750 );
led = 0 ;
printf ( lcd_putc , "\f" );
//carga de TIMERs e inicializacion de vcariables
set_timer1 ( cargaTMR1 );
set_timer0 ( cargaTMR0 );
contTMR1 = 9 ;
contSeg = 19 ;
contDelay = 0 ;
contador2 = contador = 0 ;
//programa principal
while ( 1 )
{

if ( btn1 == 0 )
{
contTMR1 = 9 ; //1 segundo
contSeg = 19 ;
contador2 = 0 ;
contador = 0 ;
}
lcd_gotoxy ( 1 , 1 );
printf ( lcd_putc , "%4lu pulsos" , contador );
lcd_gotoxy ( 15 , 1 );
printf ( lcd_putc , "%2d" , contSeg );
lcd_gotoxy ( 1 , 2 );
printf ( lcd_putc , "%5lu PPM" , contador2 * 3 );
delay_ms ( 200 );
}
}

También podría gustarte