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

16f877 hangs up in ISR (RDA)

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







16f877 hangs up in ISR (RDA)
PostPosted: Fri Apr 16, 2004 12:44 am     Reply with quote

The programm shall output on Port b when the input is > 0.
This works only for the first time and then the pic hangs itself up.

Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#define buffer_SIZE 10
BYTE buffer[buffer_SIZE]={0};
BYTE tail = 0;
BYTE receivedFrame = 0;

BYTE T1;
BYTE T2;
BYTE T3;
BYTE L1;
BYTE L2;
BYTE L3;
BYTE A1;
BYTE A2;
BYTE A3;

#INT_RDA
void serial_isr()
{

  buffer[tail] = getc();

     if(buffer[tail] == '\r' || tail == (buffer_SIZE - 1))
     {
       receivedFrame = 1;
       disable_interrupts(int_rda); //disable???
       disable_interrupts(global);  //test CCS
       printf("\n\r...Interrupts disabled...");
     } //end if
     else
     {
       tail++;
     } //end else

} //end serial_isr()

void message_handler()
{
int i;

T1=buffer[0];
T2=buffer[1];
T3=buffer[3];
L1=buffer[4];
L2=buffer[5];
L3=buffer[6];
A1=buffer[7];
A2=buffer[8];
A3=buffer[9];




   if(T1>'0') output_high(PIN_B0);
   if(T2>'0') output_high(PIN_B1);
   if(T3>'0') output_high(PIN_B2);
   if(L1>'0') output_high(PIN_B3);
   if(L2>'0') output_high(PIN_B4);
   if(L3>'0') output_high(PIN_B5);
   if(A1>'0') output_high(PIN_B6);
   if(A2>'0') output_high(PIN_B7);


for(i=0;i<BUFFER_SIZE-1;i++) buffer[i]=0;
printf("\n\r...message_handler ended...");
} //end meassage_handler()


void main()
{
  BYTE head = 0;
  enable_interrupts(global);
  enable_interrupts(int_rda);

  while (TRUE)
  {
    if(receivedFrame == 1)
    {
//      while(head != tail){
//        putc(buffer[head++]);
      puts(buffer);

      message_handler();

      delay_ms(2500);
      OUTPUT_B(0x00);

      head = tail = 0;
      receivedFrame = 0;
      enable_interrupts(int_rda);
      enabel_interrupts(global);
    } // end if
  } // end while true

}// end main

RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Fri Apr 16, 2004 2:20 am     Reply with quote

There are several things that look suspicious to me:

Code:
for(i=0;i<BUFFER_SIZE-1;i++) buffer[i]=0;


This won't clear the entire buffer out, so the final character might still be the \r, thus the second pass would always be short by one character.

This doesn't look like a crash scenario, however.

Actually, this won't compile, right? enabel_interrupts() I don't think will fly. Therefore, perhaps in the compile-ready version, there might be more clues.

Good luck,

Smile Robert
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