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

sms controller with pic16f873

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



Joined: 05 Feb 2010
Posts: 5

View user's profile Send private message

sms controller with pic16f873
PostPosted: Sat Feb 06, 2010 6:00 am     Reply with quote

Hi Guys, I have small problem and I will apreciate little help. I just started developing sms controller, based on pic16f873 using CCS. Initially I was thinking that I will find some examples on the net to use as starting point, but after 10-15 days of browing I am berried in archived projects, but not relly what I can use. I need to control relays and send GPS data. I am using AT commands (this is what SIM508 modile operates with). This module has GPS receiver, so I just need to get the data and transmit with the relay status let say every 2 hours. I manage to configure the module to GSM and GPS part to work with 9600 boud speed, so I will use UART of the PIC. Can some one help ?
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sat Feb 06, 2010 8:32 am     Reply with quote

Post the code you need help with.

That is how you attract attention that will help you.

The first step is YOU making a start with your code on display.

I don't come here looking to do your work for you - only to see what parts you don't get. & help with THAT.

If you don't even know how to start -
then you are in the wrong line of work.
and looking in the wrong place too.
Vivi



Joined: 05 Feb 2010
Posts: 5

View user's profile Send private message

connection problem
PostPosted: Sat Feb 06, 2010 3:41 pm     Reply with quote

Hi Asmboy,
the first problem I have is the connection between the max232 and the SIM module. When I post AT commands from my PC using hyperterminal and the gsm module sends SMS. I have transferred these same commands into the PIC ( I am using UART & max232). When I test this by connecting the PIC's port to the SIM module and run the SW- nothing appears. No SMS is sent (at least I didn't receive it).
I believe my connection is not correct. I am using only 2, 3 and 5 pin of the 9 pin connector. I have seen people shorting 4 and 7pin or 1,6 and4 + 7 and 8. This is the 9 pin conector from the SIM module side. What is the correct connection?
The second problem is what if I just ignore the incoming reply from the GSM modem. I can just wait 1 second (until the modem replies OK for example) and post the next command. Is this OK or I must handle the reply?


Last edited by Vivi on Sat Feb 06, 2010 4:44 pm; edited 1 time in total
Vivi



Joined: 05 Feb 2010
Posts: 5

View user's profile Send private message

PostPosted: Sat Feb 06, 2010 3:52 pm     Reply with quote

The code I am using for testing is below.
Code:
// test SMS v6
#include "C:\Program files\PICC\Devices\16f873.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
#use delay(clock=20000000)
  //#include <lcd.h>
#Byte PortA=0x05
#Byte PortB=0x06
#use fast_io(A)
#use fast_io(B)
#Define Nop #Asm Nop #EndAsm


send_SMS();

void send_SMS(void)
{
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
  printf("AT\r\n");
  delay_ms(5000);
  printf("at+cmgf=1\r\n");
  delay_ms(5000);
  printf("at+cmgs=\"+4478XXXXXXXX\"\r\n");
  delay_ms(5000);
  printf("This is the message.");
  putc(0x1A);
  delay_ms(5000);
}

void main()
{   
   SET_TRIS_A( 0b10000110 );
   SET_TRIS_B( 0b00000101 );   delay_ms(1);

   send_SMS();
 
     while(1)
     {
         // Toggle led
         PORTA ^= 1;
         // Simple delay
         delay_ms(500);
     }

}
Guest








PostPosted: Sat Feb 06, 2010 7:58 pm     Reply with quote

OK. I have this running. I had to connect pin 7+8 and 1 +4 on the connector going to the SIM module. I am not sure I need both connections but I will check tomorrow and I will post my findings.
Vivi



Joined: 05 Feb 2010
Posts: 5

View user's profile Send private message

PostPosted: Thu Feb 11, 2010 5:41 am     Reply with quote

I have also the function send_SMS running. However, I have some problem receiving SMS.

Last edited by Vivi on Sun Feb 21, 2010 4:14 pm; edited 2 times in total
Vivi



Joined: 05 Feb 2010
Posts: 5

View user's profile Send private message

problem receiving SMS
PostPosted: Sun Feb 21, 2010 6:10 am     Reply with quote

Hi Guys, I have problem receiving SMS. I have tested the code only with single character and it is working perfect. However, when I want to parse a text it fails. Can someone help?
The code which is working is:
Code:


#include "C:\Program files\PICC\Devices\16f873.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Byte PortA=0x05
#use rs232(baud=9600,parity=N,bits=8,xmit=PIN_C6,rcv=PIN_C7,stream=GSM,errors)
// **************** Function definitions ******************
read_SMS();
char b; char x;
// ************* interupts ************************
#int_rda
void serial_isr()
{
  char c;
   c=getc();
    if('*'==c)b=1;

}
void read_SMS()
{
   b=0;
   fprintf(GSM,"AT\r\n");
   delay_ms(2000);
   fprintf(GSM,"at+cmgf=1\r\n");
   delay_ms(2000);
   fprintf(GSM,"AT+CMGL=\"ALL\"\r\n"); 
   delay_ms(2000);                      // start saving message at the begining of the array

}


void main()

   SET_TRIS_A( 0b10000110 );
   enable_interrupts(int_rda);
   enable_interrupts(global);
   output_high(PIN_A0);
   read_SMS();
    while(1)
 {
  while(b)
  {
  // Toggle led
         PORTA ^= 1;
         // Simple delay
         delay_ms(500);
  } 
 }
}



The code which is NOT working
Code:

#include "C:\Program files\PICC\Devices\16f873.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Byte PortA=0x05
#Define CR 0x0D // Carriage return
#use rs232(baud=9600,parity=N,bits=8,xmit=PIN_C6,rcv=PIN_C7,stream=GSM,errors)

int RX_Command_ready;
int RX_Command_beginning;
#define RX_SIZE 80 //RS232 buffer for serial reception
char RxBuffer[RX_SIZE];
int Serial_Index;
read_SMS();
char b; char x;
// ************* interupts ************************
#int_rda
void serial_isr()
{
if(RX_Command_Ready==0)
{
    RxBuffer[Serial_Index]=fgetc(GSM); //getRx data


    switch(RxBuffer[Serial_Index])
   {

    case 'A':
        if((RX_Command_Beginning==0) && (Serial_Index>0) &&(RxBuffer[Serial_Index-1]=='*'))
        {
         RxBuffer[1]=RxBuffer[Serial_Index];
         Serial_Index =2;
         RX_Command_Beginning=1;
        }
        else
        {
          if(RX_Command_Beginning==0) Serial_Index=1;
          else Serial_Index=(Serial_Index+1) % RX_SIZE;
        }
        return;
     // CR the command is completed
    case CR:
       
           if(RX_Command_Beginning==1)
                RX_Command_Ready=1;
            else
               Serial_Index=1;
          return;
           default: // update the buffer pointer
       if(RX_Command_Beginning==1)
         Serial_Index=(Serial_Index+1) % RX_SIZE;
       else
       { RxBuffer[0]=RxBuffer[Serial_Index];
         Serial_Index=1;
       }
    }//switch
}

}
void read_SMS()// thank you gabriel-> http://www.ccsinfo.com/forum/viewtopic.php?t=39913&highlight=sms
{  b=0;
   fprintf(GSM,"AT\r\n");
   delay_ms(2000);
   fprintf(GSM,"at+cmgf=1\r\n");
   delay_ms(2000);
   fprintf(GSM,"AT+CMGL=\"ALL\"\r\n");     //putchar(0x0D);
   delay_ms(5000);                      // start saving message at the begining of the array

}
void main()
{  SET_TRIS_A( 0b10000110 );
setup_adc_ports(NO_ANALOGS);
ext_int_edge(h_to_l);
   enable_interrupts(int_rda);
   enable_interrupts(global);
   output_high(PIN_A0);
   read_SMS();
   disable_interrupts(int_rda);
   disable_interrupts(global);
if(RX_Command_ready>0)

b=1;
   while(1)
 {
  while(b)
  {
  // Toggle led
         PORTA ^= 1;
         // Simple delay
         delay_ms(500);
  }
 }
}


Sad may be I need some optimization of my int_rda. I can see the SMS clearly on Hyperterminal when I test separately. The message is "*A123".
yousafzai82



Joined: 04 Mar 2010
Posts: 13
Location: Pakistna

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

PostPosted: Fri Mar 05, 2010 12:35 am     Reply with quote

HI vivi

I have studied your project and it was helpful for me. I am doing the same kind of project. I have to take 2 adc results plus one status (high or low) and then send the data through sms. Also if possible I can receive sms on microcontroller side and trip some relays. Help from your side will be a great favour...
Please check the following link to see my coding....

http://www.ccsinfo.com/forum/viewtopic.php?t=41926&highlight=pic16f877+programming+++bit+adc
_________________
zaky
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 3:05 am     Reply with quote

I have looked at your code and think it needs serious attention:-

Code:

  case 'A':
        if((RX_Command_Beginning==0) && (Serial_Index>0) &&(RxBuffer[Serial_Index-1]=='*'))
        {
         RxBuffer[1]=RxBuffer[Serial_Index];
         Serial_Index =2;
         RX_Command_Beginning=1;
        }
        else
        {
          if(RX_Command_Beginning==0) Serial_Index=1;
          else Serial_Index=(Serial_Index+1) % RX_SIZE;
        }
        return;


Firstly, you should be using a break instruction to break out of case statements, I am sure return works fine but looks messy, in your code you can just replace the returns with break.

more importantly I don't think it will ever work. Your problem is this:-
&&(RxBuffer[Serial_Index-1]=='*')

I ran through the code in my head and from what I can see serial_index -1 will allways be 0 which will allways contain the char 'A' as you never overwrite this index!

based on the response :-
Code:

AT+CMGR=2\0D
\0D
\0A
+CMGR: "REC UNREAD","01150971734","Dn55 Movil","09/08/14,19:51:49-12"\0D
\0A
*LED1 1*\0D
\0A
\0D
\0A
OK\0D
\0A

First char is 'A' this gets stored at index 0.
Serial_Index is then set to 1.
RX_Command_Beginning remains at 0

Actually, looking at it again you never see another 'A' so it will never enter the case 'A' block again. Unless your message contains an 'A' ?

But even if it did the problem I stated before remains, Serial_Index - 1 will never = '*' as far as I can see. I could be wrong Smile
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