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

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



Joined: 03 Sep 2011
Posts: 5
Location: Tunisie

View user's profile Send private message AIM Address MSN Messenger

SMS controller
PostPosted: Sat Sep 03, 2011 5:47 am     Reply with quote

hello to all,
I'm trying to order a printer via SMS such a way that the printer prints the SMS received by the GSM. Indeed, I used GL865 Telit GSM module, a PIC16F877, a thermal printer. the communication between GL865 is via serial port. If the GSM received a message, the microcontroller will transfer the message to the printer via serial port. My problem is the program of the PIC.
I am looking for a full program or for example used in this application.
Help me please.
Thank you in advance
Sad
idham85



Joined: 03 Sep 2011
Posts: 5
Location: Tunisie

View user's profile Send private message AIM Address MSN Messenger

interface GSM
PostPosted: Sat Sep 03, 2011 9:06 am     Reply with quote

I just want a code of the connection between PIC and GSM module. Receiving and sending messages between the two.
idham85



Joined: 03 Sep 2011
Posts: 5
Location: Tunisie

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Sat Sep 03, 2011 9:59 am     Reply with quote

Please I need code for PIC. Just the first part ie how to communicate between GSM and PIC such a way that I receive only SMS and save them.
I use PICC compiler
temtronic



Joined: 01 Jul 2010
Posts: 9142
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 04, 2011 5:06 am     Reply with quote

I don't have that GSM module and when I go to download the hardware PDF, IE8 doesn't unblock it but goes to new Google.....arrgh ,so I can't get the PDF!
In general though you'll need some 'MAX232' chips and some simple serial software.There are several examples on this forum,just use the 'search' option on the top of the screen.
Be sure that all hardware is compatible, especially voltage levels! You MUST have level translators if GSM is 3.3v and the PIC is 5v.
fiolin



Joined: 04 Sep 2011
Posts: 2
Location: Uruguay

View user's profile Send private message

PostPosted: Sun Sep 04, 2011 2:51 pm     Reply with quote

I made a kind of sms's control remote with a gsm module and 16F886 pic. Before to start the pic program I've used hyperterminal in order to understand how works the incomming sms. In my case only I've used phone number and the text message in my program.
Here a little part if you send the sms On you turn on Led_out and if you send Off you turn off Led Out (pin_B4).
Code:

 #include <16F876.h>
           
#byte PORTA    = 0x05
#byte PORTB    = 0x06
#device *=16
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#use fast_io(A)
#use fast_io(B)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES DEBUG                    //Debug mode for use with ICD

#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)
#include <stdlib.h>

#define led_out      PIN_B4 //Led out
#define led_state      PIN_B5 //Led monitor
#define IN_ONOFF       PIN_B0   //When goes down send a sms
#define BUFFER_SIZE 60 //Buffer size you can adjust this size

char  buffer[BUFFER_SIZE];            // buffer
char b=0x00;                     // Last characters recived
int  xbuff=0x00;
short sms_mode=false;//It's a flag when is true read sms( lee_sms())

// Declaración de Funciones ///////////////////////////////////////////////////
void send_sms();//send sms routine
void lee_sms();
void inicbuff(void);               // Limpia buffer
void demora(unsigned int repetir);//delay rutine
void verifica_ok (void);//checkl OK sending byl modem
void inicmodulo(void);

//****************************************************************************
#int_RDA
RDA_isr()
{
if(kbhit()){
b=getc();
if(b=='+'){//first character of phone number
   xbuff=0;//para que comience a escribir a la var buffer desde la 1º posición
    sms_mode=true;   
   }
buffer[xbuff++]=b;               // add character to the buffer vector
}
return 0;
}

//******************************************************************************
// Programa principal
//******************************************************************************

void main(void){
   set_tris_A(0b00000000);          //config port A
   set_tris_B(0B10000011);          //config port B
  setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);   
   output_high(led_state);//enciende el led monitor de estado
   output_low(led_out);//apaga el led   de salida
   inicbuff();
   inicmodulo();     
   
 for(;;)
{
if(input(IN_ONOFF)==0)
delay_ms(200);
{
if(input(IN_ONOFF)==0)   
   {
     send_sms();
   while(input(IN_ONOFF)==0);
   }
}
if(sms_mode==true)//si sms_mode=true se pasa a la función lee_sms()
{
   output_high(led_state);
   lee_sms();
    sms_mode=false;
   output_low(led_state);
      } 
}//for(;;)
}//main()

///////////////////////////////////////////////////////////
//Envia los comandos AT para inicializar el modulo sms
//////////////////////////////////////////////////////////
void inicmodulo(void){   
   printf("AT\n\r"); //
   delay_ms(500);   
   verifica_ok ();
   inicbuff();
   printf("ATE0\n\r"); //cancel echo mode
   output_high(led_state);//enciende el led
   delay_ms(500);   
   verifica_ok ();
   inicbuff();
   printf("AT+CPMS=\"SM\",\"SM\"\n\r");//Selecciono la mem sim para recibir y leer sms
   output_high(led_state);//enciende el led
   delay_ms(500);   
   verifica_ok ();
   inicbuff();                         
   printf("AT+CNMI=2,2,0,0,0\n\r");//los sms se envían directamente al puerto serie
   output_high(led_state);//enciende el led
   delay_ms(500);   
   verifica_ok ();
   inicbuff();
   printf("AT+CMGF=1\n\r"); //Habita el modo texto de los sms
   output_high(led_state);//enciende el led
   delay_ms(500);
   verifica_ok ();
   inicbuff();
         
}

///////////////////////////////////////////////////////////
//Funcion para envío de sms
///////////////////////////////////////////////////////////
void send_sms()
{
char in_state='D';
char out_state='D';
if(input(IN_ONOFF)==0) in_state='A';
if(bit_test(PORTB,4)==1) out_state='A';
output_high(led_state); //enciende el led
printf("AT+CMGS=\"xxxxxxxx\"\n\r");//here your cellphone number
delay_ms(500);
printf("Inputs - Outputs\n\r");
printf("1  / 1\n");
printf("%c / %c\n",in_state,out_state);//here send state of inputs & outputs
delay_ms(500);
putc(26);// envia ctrl + Z
demora(5);
verifica_ok();// compruebo si se envió el sms
return;
}

////////////////////////////////////////////////////////////
//Función para leer el sms recibido
///////////////////////////////////////////////////////////
void lee_sms(void){

char *ptr;
char r2_on[]="On";
char r3_off[]="Off";
char r4_estado[]="Estado"; 
   output_high(led_state);   
   delay_ms(500);
   printf("AT+CMGD=1\n\r");
     ptr=strstr(buffer,r2_on);//busca la palabra On en buffer[]
if(strncmp(ptr,r2_on,2)==0){     
      output_high(led_out);//activa la salida
      inicbuff();
       send_sms();
       output_low(led_state);               
   }
ptr=strstr(buffer,r3_off);//busca la palabra Off en buffer[]
if(strncmp(ptr,r3_off,3)==0){     
      output_low(led_out);//desactiva la salida
      inicbuff();
       send_sms();
       output_low(led_state);               
   }

ptr=strstr(buffer,r4_estado);//busca la palabra Estado en el vector buffer
if(strncmp(ptr,r4_estado,6)==0){
      inicbuff();     
       send_sms();//Si la encuentra manda un sms reportando el estado de entrada y salida
       output_low(led_state);               
   }

   
return;
}

///////////////////////////////////////////////////////////
//Pone ceros en toda la variable buffer
///////////////////////////////////////////////////////////
void inicbuff(void){
int i;
for(i=0;i<buffer_size;i++){
buffer[i]=0x00;
restart_wdt();
}
xbuff=0x00;
sms_mode=false;
return;
}

/////////////////////////////////////////////////////////////
//Delay routine minim de 1 sec                            /
/////////////////////////////////////////////////////////////
void demora(unsigned int repetir)
{
int i;
for(i=repetir;i--;)
{
delay_ms(1000);
restart_wdt();
}
return;
}

/////////////////////////////////////////////////
void verifica_ok (void){//esto la uso para comprobar el OK que envía el modem luego de enviarle algún comando AT
char *ptr;
char r1_ok[]="OK";
ptr=strstr(buffer,r1_ok);//busca la palabra OK en el vector buffer
if(strncmp(ptr,r1_ok,2)==0){
output_low(led_state);//me guio por el led para saber si el modem manda OK
   }
return;
}
idham85



Joined: 03 Sep 2011
Posts: 5
Location: Tunisie

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Sun Sep 04, 2011 4:12 pm     Reply with quote

Thank you very much for your help.
May you explain how this code and the connecting pins of Port.
I want to understand your code because it validated by the compiler for that I'll change it to suit my application. My application is to make communication between the PIC and the mobile phone as follows:
- The PIC enters a wait loop by sending the command "AT + CMGS" to the GSM receives an SMS in the PIC responds to a Command "+ CMGS"
-The PIC sends a command to receive the message and displays it on an LCD screen.
-Each SMS received by the PIC, it sends a confirmation message to the GSM.
May you help me please.
fiolin



Joined: 04 Sep 2011
Posts: 2
Location: Uruguay

View user's profile Send private message

PostPosted: Sun Sep 04, 2011 7:44 pm     Reply with quote

Here you can see the schematic used in this application.

https://picasaweb.google.com/lh/photo/sXjDLImcshe1wU6YgwJwIgLVmRoOFDsaRnAAP4DNjOg?feat=directlink

Tell me if you need more help and sorry my english, spanish is my mother language.
idham85



Joined: 03 Sep 2011
Posts: 5
Location: Tunisie

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Mon Sep 05, 2011 3:59 am     Reply with quote

fiolin wrote:
Here you can see the schematic used in this application.

https://picasaweb.google.com/lh/photo/sXjDLImcshe1wU6YgwJwIgLVmRoOFDsaRnAAP4DNjOg?feat=directlink

Tell me if you need more help and sorry my english, spanish is my mother language.


And me I'm sorry for my english because I'm tunisian and arabic is my mother language
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

gsm
PostPosted: Tue Mar 13, 2012 10:22 am     Reply with quote

In this driver, I found the problem:
1 - Normally this program must receive a sms, on, or off to on or off an LED.
2 - What is the exact role of input input (IN_ONOFF), this button is used for what reason? ,
3-printf("Inputs - Outputs\n\r"); ????why?
4-printf("1 / 1\n"); ????
5-printf("%c / %c\n",in_state,out_state);// ??????????
6-ptr=strstr(buffer,r2_on) What is it? « ptr » , "strstr" ?
7-strncmp(ptr,r2_on,2)? what is it strncmp.
8-what is its role of fonction void demora() ,and , void verifica_ok (void)
9-I found that in all the GSM program, it is used this table (buffer[BUFFER_SIZE]) , this table buffer it is used for what reason


I found no clear explanation on the topics of GSM, I ask all programmers helped me on this subject, especially who applied this driver, I want to understand the operating principle, normally when the Module gsm receive sms, in this case it affects 1 in B4, but why the programmer used the routine send sms, in logic, I use another mobile for the word is sent to my mobile phone unit, so in this case we use in our program that the driver for read sms, what is right? ......
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Mar 13, 2012 12:43 pm     Reply with quote

Hi kamillas,

You are asking such basic 'C' questions, that it's hard not to conclude that this project is well beyond your (demonstrated) abilities with PIC processors and the CCS 'C' compiler. Seriously, at least half of your questions are readily answerable using Google or the forum search. If you consistently show an unwillingness to do any work, no one is going to bother to help you! There is at least one complete program in the forum archives that shows you how to switch LEDs On/Off under SMS control, authored by user 'Gabriel'. Did you find it?

Fundamentally, this is not a difficult task, but you've got to have a good handle on serial communications first, then string parsing, and then string manipulation. So far, you seem to be seriously lacking in the skills for all three tasks.

I don't offer these observations in a mean-spirited way, but rather as a friendly suggestion that you fundamentally change the way you go about your problem solving.

Good Luck!

John
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Famous!
PostPosted: Tue Mar 13, 2012 2:35 pm     Reply with quote

Hey! Thats Me! .....

(insert Rasins Face meme image)

OMG: I am Famous!

;)
_________________
CCS PCM 5.078 & CCS PCH 5.093
hadipic



Joined: 02 Dec 2012
Posts: 2

View user's profile Send private message Yahoo Messenger

Re: Famous!
PostPosted: Tue Feb 17, 2015 4:35 am     Reply with quote

[/code]

/***********************send PDU sms*********************/
void GSM_Sent_PDU_Message(char *num,char *txt1,int1 center)
{
unsigned char i;
int16 tr_in;
int8 strlen_txt,strlen_msg;
const char se_iranceel[24]="079189390500410031000B81"; //989350001400
const char se_hamrahaval[22]="0691891901500031000B81";


//char str2[]={"AT+CMGF=0\r\n"}; //
//char str4[]={}; //

disable_interrupts(INT_timer3);


fprintf(gsm,"AT+CMGF=0\r\n"); //set PDU =0 txt =1 mode,send a Chinese sms
delay_ms(500);

fprintf(gsm,"AT+CSCS=\"HEX\"\r\n");
delay_ms(500);

//fprintf(gsm,"AT+CSMP=167,0,2,8\r\n");
fprintf(gsm,"AT+CSMP=17,169,0,8\r\n");
delay_ms(500);




// strlen_msg=strlen_txt/2)-strlen_cen;
strlen_msg=strlen(txt1);
strlen_txt=28+strlen_msg; //


//fprintf(rs232,"number=%c0%c%c%c%c%c%c%c%cF%c\r\n",num[3],
// num[5],num[4],num[7],num[6],num[9],num[8],num[11],num[10],num[12]);


fprintf(gsm,"AT+CMGS=%d\r\n",(strlen_txt/2));





counter_read=0;
tr_in=0;
while(counter_read<=1 && tr_in++ < 0xfff1) // read all data
{
// output_high(PIN_D1); // signal ready to receive sms
delay_us(1);

}


delay_ms(40); //humity , temper ,batry

// sprintf(string," ÓÇá %d ãÇå %d ÑæÒ %d ",yar ,mon ,day);
// sprintf(string," ÓÇÚÊ %d ÏÞíÞå %d",hor,min );
// fprintf(gsm,"%S%c" txt1,26); // 0x1a => ctrl-z


if (center==0)

{
//strlen_txt=strlen_txt+8;
for (i=0; i<24;i++) fprintf(gsm, "%c",se_iranceel[i]);
}
else
{
//strlen_txt=strlen_txt+7;
for (i=0; i<22;i++) fprintf(gsm, "%c",se_hamrahaval[i]);
}
// 9053793576F5
// 09359753675
// 9053793576F5

fprintf(gsm,"%c%C%c%c%c%c%c%c%c%cF%c00081D",num[1], // 1d> 3 hours 47 >6 hours A7 one day
num[0],num[3],num[2],num[5],num[4],num[7],num[6],num[9],num[8],num[10]);


fprintf(gsm, "%X",(strlen_msg/2));
for (i=0; i<strlen_msg;i++) fprintf(gsm, "%c",txt1[i]);
fprintf(gsm, "%C",26);

counter_read=0;

while(counter_read<=16 && tr_in++ < 0xfff1) {delay_ms(1);} // read ok send sms


if(GET_OK(0X0E)) {

// printf (" sucsses");
delay_ms(1000);
}
else
{

// printf ("not sucsses")

delay_ms(1000);


//fprintf(gsm,"AT+CSCS=\"GSM\"\r\n");
//delay_ms(200);



enable_interrupts(INT_timer3);

}



}





int1 make_call(char*num,int8 num_ring)
{



//fprintf(gsm,"AT+CHFA: 1");//AT+CHFA: 0 hanset 1 aux
//fprintf(gsm,"ATL5"); // seting sound volum
//fprintf(gsm,"ATH"); // hang out
//fprintf(gsm,"ATA"); // answer
//fprintf(gsm,"ATDL"); // redial

int32 tr_in;
int8 i,temp;

fprintf(gsm,"ATD%c%c%c%c%c%c%c%c%c%c%c;\r\n",num[0],num[1],num[2],num[3],num[4],
num[5],num[6],num[7],num[8],num[9],num[10]);

//@pwav/music.wav \n
// @aATD09359753675;\r\n
//fprintf(gsm,"ATD05133490059;\r\n");

tr_in=0;
While(counter_read<=20 && ( tr_in++ < 0x1fffff*num_ring)) // read all data
{

delay_us(2);
}



for(i=0;i<num_buf_sms;i++)
{

fputc(Recieve_String[i],rs232);
// fprintf(rs232," %c=%U "Recieve_String[i],i);
// delay_ms(60);
if(Recieve_String[i]=='C' && Recieve_String[i+1]=='O') {temp=i;break;}

}

if (Recieve_String[1+temp]=='O'&&Recieve_String[2+temp]=='L' // +COLP: hang on number
&&Recieve_String[3+temp]=='P')

{

Return(1);
}




if(GET_OK(0X0E))
Return(1);
else return(0);


}[code]


Last edited by hadipic on Wed Aug 26, 2015 10:00 am; edited 3 times in total
ckielstra



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

View user's profile Send private message

PostPosted: Tue Feb 17, 2015 1:33 pm     Reply with quote

@hadipic: This post makes no sense. Why did you post it?

- You are posting in a thread that was silent for 3 years.
- There is no question or remark for why you posted the code.
- The code is incomplete.
- The code is difficult to read because you didn't use the 'code' buttons.
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