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 and Long Packet

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



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

#int_rda and Long Packet
PostPosted: Sun Sep 05, 2010 2:39 am     Reply with quote

Hi Programmers...
I have project with 2 serial isr (#int_rda and #int_ext) for rs_485 communication and rf_id reader GP20model. My project work good, but when send long packet i.e 50 - 100 bytes to pic16F628A it block if I use #locate directive for GP20_buffer or clear buffer_gp20 without use #locate directive. Any suggestion about this problem ?
My compiler ver. is PCM v.4.104
Thanks before:)

Here is my code
Code:

   #include <16F628A.h>
   #fuses HS, NOWDT,PROTECT,BROWNOUT,PUT,NOLVP,MCLR  ////////////////////////////////////////////
   // #use delay(clock=11 059 200)       //new version v.0.2                                   //
   #use delay(clock=10 000 000)          //old version v.0.1                                   //
   #use rs232(baud=9600,rcv=PIN_B1,xmit=PIN_B2,errors,enable=PIN_B3,STREAM=rs_485,DISABLE_INTS)//
   #use rs232(baud=9600,rcv=PIN_B0,INVERT,STREAM=GP_20,DISABLE_INTS)                           //
   ///////////////////////// standart_bytes//////////////////////////////////////////////////////
   #define stx_rx               0xd2     // Start_byte of received packet
   #define etx_rx               0xd3     // Stop_byte  of received packe
   #define stx_tx               0xc2     //
   #define etx_tx               0xc3     //
   #define cop_send_id_tx       0x94     // 
   /////////////////////////////////////////////////////////////////////////////   
   #define buffer_size_GP20       14
   #define buffer_size_485_tx     16
   #define buffer_size_485_rx      7
   /////////////////////////////////////////////////////////////////////////////
   #define r_led   PIN_A1
   #define g_led   PIN_A0
   /////////////////////////////////////////////////////////////////////////////
#priority ext,rda
   // Global variable //
   int   buffer_485_tx    [buffer_size_485_tx];
   int   buffer_485_rx    [buffer_size_485_rx];
    //#locate buffer_485  = 0x70
   int   buffer_GP20  [buffer_size_GP20];
    //#locate buffer_GP20 = 0x20
   int1  packet;
   int   index_485_rx;
   int   index_gp20;
   int   x;
   int   address =0xff;
   int   err=0xad;
   int   w=0;
   
#int_ext
   void EXT_GP20_isr()                      // ext_Gp20 interrupt receiver func;
   {
      buffer_GP20[index_gp20] = fgetc(GP_20);
      if(++index_gp20 == buffer_size_GP20)
      {
         index_gp20 = 0;
      }
         set_timer2(46528);
         clear_interrupt(int_TIMER2);       
         enable_interrupts(int_TIMER2);
     
      if (buffer_GP20 [0]==0x02 && buffer_GP20 [13]==0x03)
       {
         clear_interrupt(int_TIMER0);       
         enable_interrupts(int_TIMER0);

         output_high (r_led);
         output_low (g_led);
         
       }
   }
   
   
#int_TIMER0
   void timer_0_isr ()
   {
      w++;
      if (w>2)
      {
        index_gp20 = 0;
      }
      if (w>30)    //  && buffer_GP20 [2] == 0x00
      {
         disable_interrupts(int_TIMER0);
         output_high (g_led);
         output_low (r_led);
         w=0;
      }
   }
   
#int_timer1                 
   void TIMER1_isr()
   {
      disable_interrupts(int_TIMER1);
      packet=1;
      index_485_rx =0;
   }
   
#int_rda                                             
   void rs485_isr ()
   {  x = fgetc(rs_485);     
      if(!packet)                                           
      {  buffer_485_rx[index_485_rx] = x;                                 
         if(++index_485_rx == buffer_485_rx)
         { 
             index_485_rx =0;
         }
         
             set_timer1(46528);//->> 65536-((16.5*XTAL_FREQ)/BAUDRATE)             
             clear_interrupt(int_TIMER1);       
             enable_interrupts(int_TIMER1);
      }
   }


///////////////////////"Main_Function"////////////////////////////////////////////
void main ()

      index_gp20 = 0;
      //init_tx_buffer ();
      packet=0;
      index_485_rx=0;
      index_gp20=0;
      w=0;
     
      setup_vref(FALSE);
      setup_comparator(NC_NC_NC_NC);
      setup_timer_0(T0_INTERNAL|T0_DIV_256);
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
      //setup_timer_2 ( T2_DIV_BY_4, 0xc0, 2);
     
      enable_interrupts(INT_EXT_L2H );
      enable_interrupts(int_rda);                     
      enable_interrupts(global); 
      port_b_pullups (TRUE);
     
      delay_ms (150);
     
      clr_gp20_buffer();
      get_address ();
   
      fprintf (rs_485,"address:%d",address);
     
      output_low (r_led);
      output_low (g_led);
     
while (TRUE){
 
   if (get_packet())
   {
     
      switch (buffer_485_rx [2])
      {
          case 0x22: {
                       fprintf (rs_485,"state_1");
                     }
                               break;
          case 0x33 :{
                       clr_gp20_buffer ();
                     }
                               break;
          case 0x55 :{
                        if (check_gp20_buff ())
                        {
                           send_packet();
                        }else fputc (err,rs_485);
                     }
                               break;
       }
       
    }
 
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 05, 2010 3:14 am     Reply with quote

Quote:

//#locate buffer_485 = 0x70
//#locate buffer_GP20 = 0x20

#int_rda
void rs485_isr ()
{
x = fgetc(rs_485);

if(!packet)
{ buffer_485_rx[index_485_rx] = x;
if(++index_485_rx == buffer_485_rx)
{
index_485_rx =0;
}

This whole thing you're doing here is a mistake. Avoid doing address
tricks. They're unnecessary, and they're left-over from hacker days as
an ASM programmer. When you go to C, all that stuff should be left
behind.

Look at the CCS example file, Ex_sisr.c. It shows how to do an circular
buffer in #int_rda. Here's the file location:
Quote:

c:\program files\picc\examples\ex_sisr.c
Ttelmah



Joined: 11 Mar 2010
Posts: 19436

View user's profile Send private message

PostPosted: Sun Sep 05, 2010 3:23 am     Reply with quote

Also, add #device *=16. This way your processor can use the whole address range of the 628, rather than being stuck with just the low page.

Best Wishes
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Tue Sep 07, 2010 6:54 am     Reply with quote

PCM programmer wrote:
Quote:

//#locate buffer_485 = 0x70
//#locate buffer_GP20 = 0x20

#int_rda
void rs485_isr ()
{
x = fgetc(rs_485);

if(!packet)
{ buffer_485_rx[index_485_rx] = x;
if(++index_485_rx == buffer_485_rx)
{
index_485_rx =0;
}

This whole thing you're doing here is a mistake. Avoid doing address
tricks. They're unnecessary, and they're left-over from hacker days as
an ASM programmer. When you go to C, all that stuff should be left
behind.

Look at the CCS example file, Ex_sisr.c. It shows how to do an circular
buffer in #int_rda. Here's the file location:
Quote:

c:\program files\picc\examples\ex_sisr.c


Thanks PCM ..!
My mistake was little stupid, but now I corrected, and project work well.

correction:
Code:
 if(++index_485_rx == buffer_size_485_rx)
         { 
             index_485_rx =0;
         }
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