|
|
View previous topic :: View next topic |
Author |
Message |
Audi80
Joined: 07 Sep 2007 Posts: 41
|
Interruptions problem |
Posted: Fri Nov 30, 2007 9:44 am |
|
|
Hi there. I´m using a pic16f876a with 3 interruptions INT_RDA INT_CCP1 and
INT_CCP2, my problem is that when one of the interruptions happens at the same time as another my pic gets stuck! How can i avoid this to happen? thanks in advance...
Code: | #include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <rs232.h>
#include <card_reader.h>
#include <keyboard.h>
//////////////////////////////////////////////
char temp[50];
//////////////////////////////////////////////
//////////////////////////////////////////////
#int_rda
void serial_isr() {
char aux;
aux=getc();
if(aux=='C'){
printf("Cartao -> ");
while(aux=descarrega_cartao()){
printf("%c",valida_numero(aux));
}
printf("\r\n");
printf("Teclado -> ");
while(aux=descarrega_buffer()){
printf("%c",aux);
}
printf("\r\n");
init_cartao();
init_teclado();
}
}
#INT_CCP1
void coluna1() {
carrega_buffer();
}
#INT_CCP2
void coluna2() {
carrega_buffer();
}
void main() {
enable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(INT_CCP1);
enable_interrupts(INT_CCP2);
setup_ccp1(CCP_CAPTURE_RE);
setup_ccp2(CCP_CAPTURE_RE);
printf("Leitor de tags V1.0\r\n");
init_cartao();
init_teclado();
while(true){
le_cartao();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 30, 2007 1:51 pm |
|
|
If you can't service the RDA interrupt for more than 3 character times,
the UART will lock up. That's probably what is happening.
One solution is to keep all interrupt routines very short. Don't call
printf() inside an interrupt routine.
You can tell the compiler to put in code which will automatically clear
a locked up UART receiver. You do this by adding the ERRORS
directive to your #use rs232() statement, as shown in bold below:
Quote: | #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) |
You should do this anytime you use the Hardware UART. Do it in all
your programs and you won't have this problem anymore. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|