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

Yet another project using PIC16F877 to send & receive SM

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



Joined: 14 Mar 2006
Posts: 8
Location: Malaysia

View user's profile Send private message Yahoo Messenger

Yet another project using PIC16F877 to send & receive SM
PostPosted: Tue Mar 14, 2006 2:35 am     Reply with quote

Hi there,

I know that there are many posting regarding this project but I could find one that can help me solve my problem. Here is my situation,

I can successfully send SMS out but I could not receive SMS. I have tested a simple program to read from serial & transmit it back using serial.

However when I connect it to my mobile phone, I can't seem to receive the SMS. I'm using 4MHz crystal with 9600 baud rate.

Btw, I am using a MAX232 as an interface between the PIC and the mobile phone (Ericsson T610).

Just so that you are interested to see my code. Here it is,

Code:
#INT_RDA
SERIAL()
{
   if(kbhit())
   {
      D=GETC();
      if(A<50)
      {
      C[A]=D;
      PRINTF("%c",C[A]);
         //Activate & Locked
         if(C[A-7]=='B' && C[A-6]=='9' && C[A-5]=='5' && C[A-4]=='C' && C[A-3]=='2' && C[A-2]=='E' && C[A-1]=='0' && C[A]=='7')
           {
         A=0;
         LOCK();
         ENABLE_INTERRUPTS(INT_RTCC);
         EN=1;
         SEND_SMS1();
         return EN;
            }   
         //Deactivate & Unlocked
         else if(C[2]=='3' && C[3]=='0' && C[4]=='1' && C[5]=='8' && C[6]=='0' && C[7]=='C' && C[8]=='0' && C[9]=='6')
         {
         UNLOCK();
         DISABLE_INTERRUPTS(INT_RTCC);
         EN=0;
         SEND_SMS2();
         return EN;
         }
         //Check status
         else if(C[2]=='4' && C[3]=='3' && C[4]=='7' && C[5]=='4' && C[6]=='7' && C[7]=='9' && C[8]=='B' && C[9]=='C' && C[10]=='0' && C[11]=='6')
         {
         CHECK();
         }
         A++;
      }
      else
      A=0;
   }
}

Please help.

Thanks....
Code:
Ttelmah
Guest







PostPosted: Tue Mar 14, 2006 5:07 am     Reply with quote

First comment. You don't need 'kbhit'. If the RDA interrupt is called, it is because there _is_ data waiting.
Now comes the 'yetch' bit.
Each array access, is going to involve something like ten machine cycles. You have eight such accesses, in the first 'if', and if this fails, another similar sequence, and then yet another. With the global overhead, the interrupt handler here, is going to reach something in the order of possibly 500 or more instruction cycles, and depending on what is inside the 'send_sms1', 'send_sms2', and 'check' routines, probably vastly more. This is an almost certain fomula for failure...
On top of this, you have a problem that these accesses will address illegal values. On the first pass for example, when you look 'seven bytes back', you will access effectively a negative index into the array, which will 'wrap' (because of integer arithmetic), and will access address 249 in the array, which will probably be somw other variables...
Approach this very differently. First, handle the RS232 transmission, via an interrupt driven buffer. I have posted code to do this on several occassions in the past. This way, assuming that the 'send' routines actually transmit something on the RS232 (as the printf already does), you will not get delayed in the receive routine, waiting for the transmissions to occur.
Then in your receive code, use a state machine. A search here, will find examples of these published in the past. Alternatively, do the decode check, outside the interrupt handler, just setting a flag, when a complete packet has arrived.

Best Wishes
jasonwhw



Joined: 14 Mar 2006
Posts: 8
Location: Malaysia

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Mar 15, 2006 10:38 pm     Reply with quote

So you are suggesting that I should use a buffer for transmission thru RS232. As for the receive code, use a state machine or decode incoming data outside the int_rda interrupt handler.

Do you think you could provide me with the sample code for interrupt driven buffer and the state machine? You will be so nice you could do that for me. Many thanks....
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Mar 16, 2006 3:28 am     Reply with quote

jasonwhw,

Could you plz tell me how did u get the pin configuration of your mobile device and how did u get the serial command to send & get SMS?

10x
jasonwhw



Joined: 14 Mar 2006
Posts: 8
Location: Malaysia

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Mar 16, 2006 3:58 am     Reply with quote

each mobile phone has their own pin configuration.try search the net.you should be able to find your mobile pin configuration.you can send & receive SMS by using AT command.it is a command used for modem.try search the net again for more info on that.different mobile phone might have different AT command.

jasonwhw.
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Mar 16, 2006 4:29 am     Reply with quote

Thank you
HuaWuQue



Joined: 20 Jan 2006
Posts: 5

View user's profile Send private message MSN Messenger

PostPosted: Tue Mar 21, 2006 6:21 am     Reply with quote

hi jasonwhw,

im doing a project which quite similar with u, but i'm using ToothPIC microcontroller. so the connection b/w toothPIC and mobile phone is via bluetooth, no MAX232 is needed.

could u share ur source code of sending sms at here?

i had posted a thread bout my project as well. hope u can give opinion.

http://www.ccsinfo.com/forum/viewtopic.php?t=26238

thanks.
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