#include <18F8722.h>
#device ADC=10
#priority timer0
#fuses WDT,WDT1024,H4,NOPROTECT,NOIESO,NOBROWNOUT,NOPUT,NOCPD,noSTVREN,nODEBUG,NOLVP,NOWRT,NOCPB,NOEBTRB,NOEBTR,CCP2C1,NOWRTD,NOWRTC,NOWRTB,NOFCMEN,LPT1OSC,MCLR,NOXINST,MCU,BBSIZ4K
#use delay(clock=40000000, crystal=10000000,RESTART_WDT)
#use rs232(baud=19200,xmit=PIN_G1,rcv=PIN_G2,parity=N,bits=8,restart_wdt,stream=HYPERTERMINAL)
#byte porta=0xF80 #byte portb=0xF81 #byte portc=0xf82 #byte portd=0xf83 #byte porte=0xf84 #byte portf=0xf85 #byte portg=0xf86 #byte porth=0xf87 #byte portj=0xf88
int timerCont=0; // Para incrementar la cuenta del timer0
int cont_Seg_Falla=0;
int timerActivo = 0; // Se almacenará el estado del timer. Si está activo estara en 1, si no en 0.
int vectorFalla[14];
int t_vectorFalla[14]={0,0,0,0,0,0,0,0,0,0,0,0,0};
int a=0, hayFalla=0; // Variable "a" comodín, es decir, se hace uso de ella desde varias funciones.
const char msgAdvertencia[]=" > Advertencia del sistema: Se estan enviando ALERTAS";
#INT_TIMER0 // Función que es llamada por el TIMER0 cuando se produce un desbordamiento.
void TIMER0_isr(void)
{
if(timerActivo==1) // Bandera para poner en marcha la cuenta del timer
timerCont++; // En esta variable se lleva la cuenta de los segundos transcurridos ya que el TMR0 se dispara cada 1 segundos.
if(hayFalla==1)
{
cont_Seg_Falla++;
}
output_toggle(PIN_C5);
set_timer0(26474);
}
void main()
{
porta=0x00; portb=0x00; portc=0x00; portd=0x00; porte=0x00; portf=0x00; portg=0x00; porth=0x00; portj=0x00;
set_tris_a(0b11001111); set_tris_b(0b11011111); set_tris_c(0b10000000); set_tris_d(0b00000000); set_tris_e(0b00000000);
set_tris_f(0b00000001); set_tris_g(0b00110100); set_tris_h(0b00000000); set_tris_j(0b00000000);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); // desborda cada 1 segundo
set_timer0(26474);
disable_interrupts(INT_TIMER0);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
a = 0;
enable_interrupts(INT_TIMER1);
while(TRUE)
{
for(a=0;a<14;a++)
{
if(vectorFalla[a]==1 && t_vectorFalla[a]==0)
{
if(hayFalla==1)
{
hayFalla=1;
timerActivo=1;
}
else
{
hayFalla=1;
timerActivo=1;
}
t_vectorFalla[a]=1;
}
else if(vectorFalla[a]==0 && t_vectorFalla[a]==1)
{
t_vectorFalla[a]=0;
timerActivo = 0;
hayFalla = 0;
}
}
if(timerActivo==1)
{
enable_interrupts(INT_TIMER0);
}
else
{
timerCont = 0;
}
if(timerCont>=5 && timerActivo==1)
{
disable_interrupts(INT_TIMER0);
fputs(msgAdvertencia, HYPERTERMINAL);
timerCont = 0;
hayFalla = 0;
timerActivo = 0;
}
}
}