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

INT_RDA trouble? comm from pc 2 pic

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







INT_RDA trouble? comm from pc 2 pic
PostPosted: Mon Apr 12, 2004 11:00 am     Reply with quote

i've ran into some troubles with my programm using int_rda.
it's only executed one time. after i hit enter a second time, it doesn't display anything.
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;

int8 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);
  }
  else
  {
    tail++;
  }
}

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;
}


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);
    } // end if
  } // end while true

}// end main


hyperterm output:
Code:

5656
00000
111
000
00
1111
555
Ì11


[/code]
drolleman
Guest







PostPosted: Mon Apr 12, 2004 3:40 pm     Reply with quote

you disable the interupt right after you start the funtion and reenable it before exiting the funtion
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Apr 13, 2004 7:26 am     Reply with quote

I perfer to use a buffer that is zero indexed rather than circular because of some efficiencies in decoding the recieved packet. Puting that aside I think this line is not going to work.
Code:
while(head <= tail)

It should be this instead.
Code:
while(head != tail)


Here is an example of how I handle serial packets.
http://home.houston.rr.com/neutone/serial.c
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

interrupts
PostPosted: Tue Apr 13, 2004 2:10 pm     Reply with quote

Try disabling your global interrupts when you disable your int_rda just as a test. Try putting printf() around in the program to see if you are reaching points in the program when you should be. Helps to know exactly where your program stops working. Good place is in #int_rda itself to echo back each char received.
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