Orcino
Joined: 07 Sep 2003 Posts: 56
|
PIC16f630 error in interrupt with serial (SOLVED) |
Posted: Tue Oct 12, 2010 11:37 am |
|
|
I fogot put #int_TIMER1 in function.
*************************************************************
Hi ever body.
In the code below when I enable interrupt TIMER1 the program enters an infinite loop. But it works ok without interruption.
Can anyone help?
Thanks in advance.
Code: | #include <16F630.h>
#FUSES NOWDT // No Watch Dog Timer
#FUSES HS // High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT // Code not protected from reading
#FUSES NOBROWNOUT // No brownout reset
#FUSES MCLR // Master Clear pin enabled
#FUSES NOCPD // No EE protection
#FUSES PUT // Power Up Timer
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A2,rcv=PIN_C0,bits=8, ERRORS)
#define RL_TX1 PIN_C3
#define RL_TX2 PIN_A0
//******************************************************************************
// Funções
//******************************************************************************
void acionaRlTX1(void);
void acionaRlTX2(void);
void desligaReles(void);
//******************************************************************************
// Variaveis globais
//******************************************************************************
int8 contTempo=0,
segundos=0;
char x=0;
int1 flagTempoOver=0,
flagTX1=0,
flagTX2=0;
//******************************************************************************
//
//******************************************************************************
void TIMER1_isr(void)
{
contTempo++;
if(contTempo==10)
{
segundos++;
contTempo=0;
}
if(segundos==15)
{
flagTempoOver=1;
}
}
//******************************************************************************
//
//******************************************************************************
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_comparator(NC_NC);
disable_interrupts(INT_TIMER1);
disable_interrupts(GLOBAL);
while(1)
{
if(kbhit())
{
x = getc();
if (x=='A')
{
acionaRlTX1();
segundos=0;
}
if( x=='B')
{
acionaRlTX2();
segundos=0;
}
}
if(flagTempoOver)
desligaReles();
}
}
//******************************************************************************
//
//******************************************************************************
void acionaRlTX1(void)
{
if(!flagTX1 && !flagTX2)
{
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
clear_interrupt(int_timer1);
output_high(RL_TX1);
flagTX1=1;
}
}
//******************************************************************************
//
//******************************************************************************
void acionaRlTX2(void)
{
if(!flagTX1 && !flagTX2)
{
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
clear_interrupt(int_timer1);
output_high(RL_TX2);
flagTX2=1;
}
}
//******************************************************************************
// Desliga os reles e reinicia todas as variaveis
//******************************************************************************
void desligaReles(void)
{
disable_interrupts(INT_TIMER1);
disable_interrupts(GLOBAL);
output_low(RL_TX1);
output_low(RL_TX2);
flagTX1=0;
flagTX2=0;
flagTempoOver=0;
} |
|
|