Programming SIM300 and PIC 18F45k20

Status
Not open for further replies.

td micro

Member level 5
Joined
Jun 26, 2012
Messages
86
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,929
hi,
in our project, we are sending SMS through cell phone to turn on and off lamp and fan. its based on GSM. this is our 1 st project. i dont have any idea in gsm pic 18f45k20 communication. i heared we are using AT commands. so whether we have to include AT commands in pic ? how sim 300 and pic communicating?
in pic programing whether we have to use interrupt while receiving SMS?
actually i know only basic C programing. in embedded C i dont have any prev experience. so please help me..
 

Re: cellphone controller

unsigned char tmp[50],i=0,j=0;
void usart_send(unsigned char *txt);
void snd(unsigned char);
void usart_send1(unsigned char *txt);
void interrupt()
{
if (pir1.RCIF == 1) // do we have uart rx interrupt request?
{
pir1.RCIF=0; //rx flag clear
tmp = UsART_Read(); // get received byte
i++;
}
}
void main(void)
{
trisd=0;///////portd as o/p
portd=0x03;//////////portd initialized as zero
trisb.f0=0;//33 pin o/p
portb.f0=0;
trisb.f1=1;//34 pin o/p
usart_init(9600);
intcon.gie=1; ///global interrupt enabled
PIE1.rcie=1; /// enable reciever interrupt
usart_send("AT");
delay_ms(2000);
usart_send("at+CMGF=1"); //cmgf=1
Delay_ms(2000);
///////at+cpms"sm"/////////////////
usart_send1("at+CPMS");
Usart_Write(0x22); // to send the "
USART_SEND1("SM");
Usart_Write(0x22); // to send the "
USART_WRITE(0XD);
delay_ms(2000);
for(; ///forever loop
{
usart_send("at+CmgR=1"); //command for reading message no.1
delay_ms(5000);
portd=0;
///read message//////////
for(j=0;j<50;j++)
{
if(tmp[j]=='$')
{
portd.f0=1;
if(tmp[j+1]=='2')/////sent status msg back
{
portb.f0=0;//off tubewel
portd.f1=1;///led high
snd(0);
}
else if (tmp[j+1]=='1')
{
portb.f0=1;///on tubewell
portd.f1=1;led high
snd(1);
}
}
}
usart_send("at+Cmgd=1"); //delate all read messages
delay_ms(2000);
///humidity low////
if(portb.f1==1)
{
snd(2);
}
}
}
void snd(unsigned char k)
{
usart_send1("AT+CMGS=");
Usart_Write(0x22); // to send the "
USART_send1(" "); //00xxxxxxxxxxxxxx
USART_Write(0x22); // to send the "
USART_Write(0x0d); // to send <Enter>
delay_ms(2000);
if(k==0)
{
usart_send1("off");
}
else if(k==1)
{
usart_send1("on");
}
else if(k==2)
{
usart_send1("humidity low");
}
USART_Write(26); // to send <Ctr+z>
delay_ms(10000);
}
void usart_send1(unsigned char *txt)
{
while(*txt)
{
usart_write(*txt++);
}
}
void usart_send(unsigned char *txt)
{
while(*txt)
{
usart_write(*txt++);///transmit command
}
UsART_Write(0x0D); // enter
}
 

Re: cellphone controller

hi
thanks for reply..
i write one program to send sms from pic through gsm mode.gsm modem works perfectly when connected with PC. and pic also communicating with PC.ie, i checked both pic and modem individually..but when i connected PIC with modem, i couldnt send sms.can u please help me to find out the problem?

Code:
void usart_init();
void sms_read();
void sms_send();
char output[12];
char a;
int i;

void main() 
{

	OSCCON =0b01100000;
    usart_init();             
    Delay1KTCYx(50);               
    //sms_read();
	sms_send();
while(1);
}

void sms_send()
{
int i;
putrsUSART("AT\n\r");
//putcUSART(0x0D);
Delay10KTCYx(500);
putrsUSART("AT+CMGF=1\n\r");
//putcUSART(0x0D);
Delay10KTCYx(500); 
putrsUSART("AT+CMGS=");
putcUSART(0x22);           
putrsUSART("+919967602845");
putcUSART(0x22);        
//putcUSART(0x0D);
putrsUSART("\n\r");
Delay10KTCYx(500);

putcUSART(0x3E);
putrsUSART("halloooo");
Delay10KTCYx(500);
putcUSART(0x1A);// send ctrl + Z  
//putrsUSART("\n\r");
}

thanks
 
Last edited:

Re: cellphone controller

thanks for reply..

but i gave 4.2 v to modem and
3.25v to max232 and pic 18f. then power issue means?
 

Re: cellphone controller

ok but td modem some time require up to 2amp current
 

Re: cellphone controller

thanks for reply..
but how can i do that? plz help me..
 

use to regulator 7805 and then using two seperate diodes in series of each regulator this will make 4.2 volt on each and then connect both to Vbat of modem. this will make a 4.2 volt but modem can get maximum current
 

actually i dont initialize the modem.. only rx, tx, vcc, gnd pins are connected.. can u please tell me how to initialize modem?for that any external circuit is needed?for that any additional codes are used in pgm?
 

just gnd pkey pin permanently or while modem does not start like usual mobile phone power key
 

thanks for reply
use to regulator 7805 and then using two seperate diodes in series of each regulator this will make 4.2 volt on each and then connect both to Vbat of modem. this will make a 4.2 volt but modem can get maximum current
i generated the voltage like this.then also the modem is not responding.


i have connected rx of modem to tx of pic and vice verse. and also i connected rx of level converter(max3232) to tx of pic and vice verse.
and vbat, gnd, power key are taken from modem. no other pins of modem are connected to pic. whether i have to connect RING pin of modem?
please help me.
 
Last edited:

hi, i have connected rx ,tx pin of pic 18f (3.3v) directly to modem sim 300 (4.2v) tx, rx respectivly.and given the grnd common.then gave the power key also(with some delay). eventhough i couldnt send sms.. is there any extra connection is there?

thank you
 

i used to regulator 7805 .but couldnt send sms .
 

i used
Code:
putcUSART(0x1A);// send ctrl + Z
can i connect rx, tx pin of 3.3v pic to tx, rx pin of 4.2v gsm modem directly?
 

why r u not using 5volt for pic,u can connect this but problem is somewhere in your code. have u tested it in proteus using virtual terminal
 

maximum volt that can be given to pic 18f45k20 is 3.3v.
i have tested this code in hyperterminal, by connecting level converter and pic. but when i connect modem with pic sms is not sending.. here is my code..
Code:
#include <p18f45k20.h>
#include <usart.h>
#include <delays.h>

# pragma config FOSC=INTIO67
# pragma config WDTEN = OFF
# pragma config LVP = OFF
    #pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF

// OSCCON =0b01100000;

  
// code for ASCII control-Z is 0x1A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//enter its 0x0d;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


void usart_init();
void sms_read();
void sms_send();
char output[12];
char a;
int i;

void main() 
{

	OSCCON =0b01100000;
	TRISA=0;	
	
    usart_init();              // Initialize UART module at 9600 bps
    Delay1KTCYx(50);                 // Wait for UART module to stabilize
    //sms_read();

//printf("press key");

	PORTAbits.RA1=0;
	Delay10KTCYx(1000);
	PORTAbits.RA1=1;
	Delay10KTCYx(1000);
	PORTAbits.RA1=0;
	Delay10KTCYx(1000);

putrsUSART("AT+IPR=9600\n\r");
putcUSART(0x0D);
Delay10KTCYx(500); 


while(1)
{		  
  //while(BusyUSART());    
    
    
  // while (!DataRdyUSART());


    //putrsUSART("\r\nYou enter:  ");    
    

//a=ReadUSART ();
//WriteUSART (a);
//putcUSART(a);

//if (a=='a')
//{
//printf("\r\nu enter a\r\n");
	sms_send();
//}


//else
//printf("\r\nplz enter a\r\n");
}

}

 
void sms_send()
{
int i;

putrsUSART("AT\n\r");
//putcUSART(0x0D);
Delay10KTCYx(500);
putrsUSART("AT+CMGF=1\n\r");
//putcUSART(0x0D);
Delay10KTCYx(500); 
putrsUSART("AT+CMGS=");
putcUSART(0x22);           //for " character
putrsUSART("9769153924");
putcUSART(0x22);           // for "
//putcUSART(0x0D);
putrsUSART("\n\r");
Delay10KTCYx(500);
//putcUSART(a);
//putcUSART(0x3E); //for >
putrsUSART("halloooo");
Delay10KTCYx(500);
putcUSART(0x1A);// send ctrl + Z   it will deliver sms
putrsUSART("\n\r");

Delay10KTCYx(10000);
}


thanks
 

thanx for asking me for help

the number u have written"9769153924" should be"+9769153924";
if okeyed then ok if not then write this send function
void sms_send()
{
int i;
putrsUSART("AT+CMGS=");
putcUSART(0x22); // to send the "
putrsUSART(" "); //00xxxxxxxxxxxxxx
putcUSART(0x22); // to send the "
putcUSART(0x0d); // to send <Enter>
Delay10KTCYx(1000);
putrsUSART("off");
putcUSART(26); // to send <Ctr+z>
Delay10KTCYx(10000);
}
if not then mail me complete project at zia_abbasi786@hotmail.com
i will try my best to help u
 

thank you for reply..
now i can send sms.. that was delay problem. i include some delay in main() before sending sms.. now its sending and receiving sms.
while reading sms, i got the rply like this
Code:
AT+CMGR=1
+CMGR: "REC READ","+918108111649",,"12/07/22,14:24:11+22"
halloo

OK
from this, i have to extract the sms "halloo". but in c18 we have one function for reading ..
getsUSART(a,5);
but using this function, i couldnt read to pic.then i use interrupt. then also i couldnt read to pic
please give me some ideas..
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…