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 CCS Technical Support

int_rda strange problem

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



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

int_rda strange problem
PostPosted: Fri Aug 12, 2011 5:53 am     Reply with quote

Hi,

I am interfacing the pic16f877a with GSM sim300 module. My requirement is, when the two pins (port b0, portb 1) pins are high it should call to the specific number and should raise alarm.

If the gsm has the call from that specific number, the system should cut the call and it should not raise any alarm and call.

I have written the code and interfaced with gsm. If one ofthe inputs are high, the system is making call to the specified number without any problem(it is always working perfectly.)

But, if i want to switch off the alarm from the system, sometimes it is not working. I have tested this for more than 20 times, but 13 times it is working and 7 times is not. (Sometimes the system cuts the call from 1st ring only, sometimes with 3rd or 4th ring)..

Below i have given my code,
Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)


#include "lcd_Driver.c"


#define message_end 26

int1 flag = 0;
int i ;

char number_off[15] = {0};
int count_off = 0;

char phone_number[10] = {'9','0','4','7','8','6','3','0','0','7'}; //phonenumer



#int_RDA                 // receive interrupt
void  RDA_isr(void)
{
   number_off[count_off] = getc();
   count_off ++;

 
}




void main()
{
   int count = 0;
   int i;

   set_tris_b(0x8F);

   output_high(pin_b7);
   output_low(pin_b6);
   output_low(pin_b5);
   set_tris_c(0xc0);

   enable_interrupts(INT_RDA);
   //enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

   lcd_init();

   delay_ms(5000);

   printf("at\n\r");
   printf("at+clip=1\n\r");
   printf("at+cmgf=1\n\r");

   printf(lcd_putc,"WELCOME");
   delay_ms(1000);

     
   for(count = 0; count < 10; count++)
   {
      write_eeprom(count, phone_number[count]);
   }




   while(1)
   {
   
     
      if((input(pin_b0) || input(pin_b1)))  // checking for input change
      {
        if(flag == 0)             //checking whether the alarn disabled by user
        {
         output_high(pin_b6);
         output_high(pin_b5);
         printf("AT\n\r");
         printf("ATD+");              // call to the specified number
         printf("91");
         for(i = 0; i < 10; i++)
         {
             printf("%c",read_eeprom(i));
         }
         printf(";\n\r");
         delay_ms(15000);
         printf("ATH\n\r");
         delay_ms(10000);
        }

     
      }

      else
      {
         if(number_off[count_off-1] == '+')
         {
            count_off = 0;
           
         }
         
         if(number_off[0] == '9')
         {
           
            if(count_off > 11)
            {
               
               if('1' == number_off[1] &&
               read_eeprom(0) == number_off[2] &&
               read_eeprom(1) == number_off[3] &&
               read_eeprom(2) == number_off[4] &&
               read_eeprom(3) == number_off[5] &&
               read_eeprom(4) == number_off[6] &&
               read_eeprom(5) == number_off[7] &&
               read_eeprom(6) == number_off[8] &&
               read_eeprom(7) == number_off[9] &&
               read_eeprom(8) == number_off[10] &&
               read_eeprom(9) == number_off[11] )
     
              {
                  disable_interrupts(INT_RDA);
                  disable_interrupts(GLOBAL);
                  printf("ATH\n\r");                    // to cut the call
                  output_low(pin_b6);
                  output_low(pin_b5);
                  for(i = 0; i < 12; i++)
                  {
                     number_off[i] = 0;
                  }
                  count_off = 0;
                  flag = 1;
                  printf("AT+CMGS=");            // to send the message
                  putc('"');
                  printf("91");
                  for(i = 0; i < 10; i++)
                  {
                     printf("%c",read_eeprom(i));
                  }
                  putc('"');
                  printf("\n\r");
                  printf("SYSTEM IN OFF CONDITION");
                  printf(lcd_putc,"\nsystem off");
                  putc(message_end);
                 
              }
   
            }
         }
         else
            count_off = 0;
      }

   }


}

_________________
embedding innovation in engineers
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Aug 15, 2011 4:37 pm     Reply with quote

First off:
Your INT_RDA handler is very unforgiving, as it makes no allowance for
for trash or unexpected characters.
If your 'key character' , 9 is not found anywhere but the first position
-
just for a START - I suggest you think about what could happen if you have TWO or more characters in the buffer when you inspect it - as in '+9' for instance.

I believe you will find it far more profitable to code a CIRCULAR receive buffer and then extract characters and examine them through another read function, so that you NEVER just blindly collapse the read buffer when the first char is not what you want.
Thus sometimes you cause the problem you have with this code.

This is NOT a CCS compiler issue - but more a problem of not understanding timing issues in async serial data reception.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 15, 2011 6:35 pm     Reply with quote

In addition to the above info: a good example of the circular buffer implementation for serial receiving can be found in the example program ex_sisr.c
evaradharaj



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 17, 2011 5:29 am     Reply with quote

Thank for the replies...
I will look the code and will check in real time...
_________________
embedding innovation in engineers
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