CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Interruptions problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

Interruptions problem
PostPosted: Fri Nov 30, 2007 9:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 30, 2007 1:51 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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