| Author |
Message |
sakura41308
Joined: 22 Mar 2009 Posts: 2 Location: Malaysia
|
16 Jul 2009 4:38 pic gsm project |
|
|
|
|
my project is send message from PIC to handset through GSM modem..
i know we can used hyperterminal and AT command..
But, how ?
What kind of languange can used..C or assembly..
what software and compiler need...
PLz help me...
This is my circuit for interface between GSM modem and PIc
|
|
| Back to top |
|
 |
GSM Man
Joined: 15 Apr 2009 Posts: 357 Helped: 46 Location: New Jersey, USA
|
16 Jul 2009 13:06 pic gsm modem |
|
|
|
|
| sakura41308 wrote: |
i know we can used hyperterminal and AT command..
But, how ?
|
Hyperterminal is a 'Terminal Emulation' program that runs on the PC. If you are using the PIC to send/receive, HYperterminal doesn't apply.
| sakura41308 wrote: |
What kind of languange can used..C or assembly..
what software and compiler need... |
You can use any language.
| sakura41308 wrote: |
| This is my circuit for interface between GSM modem and PIc |
It's curious that you have seperate schematcis for the send and receive circuits - why not make one schematic?
All GSM handsets/Modems following a set of standards for communicating with them. You send the device commands using the serial interface. Each command starts with the letters "AT", hence they are called 'AT' commands. These are based on the Hayes Modem command set developed in the 1970's for analog modems.
You should get a copy of the software manual for the handset you are using, and see what command it supports.
|
|
| Back to top |
|
 |
codewiz
Joined: 14 Sep 2008 Posts: 75
|
16 Jul 2009 17:46 pic gsm |
|
|
|
|
| I have been confused considering the interfacing of microcontroller to mobile phone. thanks GSM Man for clearing some doubt. But my greatest doubt is: when you connect a mobile phone to PIC, where do you put the AT command and how do you code the PIC to understand the signal from the phone. for instance, when a particular sms arive in the mobile phone, how will the PIC detect and decode the message? thanks.
|
|
| Back to top |
|
 |
GSM Man
Joined: 15 Apr 2009 Posts: 357 Helped: 46 Location: New Jersey, USA
|
16 Jul 2009 18:16 serial interfacing with gsm modem |
|
|
|
|
| codewiz wrote: |
| But my greatest doubt is: when you connect a mobile phone to PIC, where do you put the AT command |
You connect the serial port of the phone to the serial port of the PIC, then you send the 'AT' commands through the serial port.
| codewiz wrote: |
| and how do you code the PIC to understand the signal from the phone. for instance, when a particular sms arive in the mobile phone, how will the PIC detect and decode the message? thanks. |
You write code to receive a packet from the phone, parse the message out of the packet and decode the message to determine what it is, and then act upon it.
|
|
| Back to top |
|
 |
codewiz
Joined: 14 Sep 2008 Posts: 75
|
17 Jul 2009 4:01 gsm pic project |
|
|
|
|
| Thanks GSM Man for your swift and expert reply. what i understood in your explanation is that the Tx and Rx of the PIC is connected to that of the mobile phone in a standard serial communication. then the AT commands will be in form of messages transmitted to the mobile phone. And message from the mobile phone is filtered by the PIC to do action according to code. am i right? i don't know how to parse message. i think i need a sample code, book or tutorial for this. i'm completely newbie to this but willing to learn.
|
|
| Back to top |
|
 |
Google AdSense

|
17 Jul 2009 4:01 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
GSM Man
Joined: 15 Apr 2009 Posts: 357 Helped: 46 Location: New Jersey, USA
|
17 Jul 2009 13:58 serial communication with pic 16f877a |
|
|
|
|
| codewiz wrote: |
| Thanks GSM Man for your swift and expert reply. what i understood in your explanation is that the Tx and Rx of the PIC is connected to that of the mobile phone in a standard serial communication. then the AT commands will be in form of messages transmitted to the mobile phone. And message from the mobile phone is filtered by the PIC to do action according to code. am i right? |
That's correct.
| codewiz wrote: |
| i don't know how to parse message. i think i need a sample code, book or tutorial for this. i'm completely newbie to this but willing to learn. |
When you read an SMS message from the modem it will be a string that contains other data such as the caller's number, date & time. For example, a message with the text "This is a test" may look like this:
| Code: |
+CMGR: "REC UNREAD","19085551212",,"09/07/17,08:52:57-16"
This is a test |
You need to write code to extract the information you want. Parsing data is a common task in software and you should be able to find a lot of references to parsing methods. Just do a diligent search on the internet and I'm sure you'll figure out how to do it.
|
|
| Back to top |
|
 |
codewiz
Joined: 14 Sep 2008 Posts: 75
|
17 Jul 2009 20:34 16f877a gsm |
|
|
|
|
| thanks. things are getting clearer. i'll search and have my hands on simple task. it will really be great to control the devices in my room from outside.
|
|
| Back to top |
|
 |
sakura41308
Joined: 22 Mar 2009 Posts: 2 Location: Malaysia
|
30 Jul 2009 1:00 pic, gsm modem, circuit |
|
|
|
|
Gsm man...can u check my interface circuit...and plz help me correct the circuit ..
include the value 0f each component
as example : what value of crystal are used , 20 Mhz or 4 Mhz...
- and gsm man..can u give me your email..so, we can chat and you can help me. along this project process .. (",). i
|
|
| Back to top |
|
 |
GSM Man
Joined: 15 Apr 2009 Posts: 357 Helped: 46 Location: New Jersey, USA
|
30 Jul 2009 1:47 interface pic with gsm modem |
|
|
|
|
| sakura41308 wrote: |
| can u give me your email..so, we can chat and you can help me. along this project process .. (",). i |
Just clcik on the PM button on any of my posts and you can send me a Personal Message
Added after 19 minutes:
| sakura41308 wrote: |
Gsm man...can u check my interface circuit...and plz help me correct the circuit ..
include the value 0f each component
as example : what value of crystal are used , 20 Mhz or 4 Mhz...
|
Crystal - you can use any value you want. Selection depends on your power reqirements, resolution required for Timers, Baud Rate Generator, SPI, I2C interface etc. Assuming you aren't running on battery power (and need low current consumption) I would typically opt for the highest frequency the device supports (20MHz).
Capacitor C2 & C6 - these are the loading caps for the crystal oscillator. Their value depends on the crystal you use - typically 15pF to 39pF - you need to consult the crystal manufacturer's specification to determine their value
- All of the caps on the MAX232 should be 1uF. However, the one end of C5 should be connected to Vcc (pin 16) NOT GROUND. Also, make sure you place a cap between Vcc and ground. You may want to look at the datasheet on the Maxim web site for calrification: http://www.maxim-ic.com/quick_view2.cfm/qv_pk/1798
|
|
| Back to top |
|
 |
max123
Joined: 22 Sep 2009 Posts: 1 Location: india
|
23 Sep 2009 6:44 Re: GSM modem with PIC 16F877A |
|
|
|
|
hi... gsm man
we can send sms from gsm modem.but cant receive sms and to display it on lcd by pic16f877a..
pl help me..we are in deadline.check my code and correct it.
#include <16f877a.h>
#include "string.h"
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, bits=8, parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=GSM)
#define RS PIN_E0
#define E PIN_E1
void out_lcd_string(char *string);
char initialize[] = "Initialize....";
void clear();
void cmd();
void lcddata(char value);
void LCDInit();
void display(char *x);
char char_rcvd;
void readindex(void);
void ledtest(void);
byte data[70];
int t = 0;
int i= 0;
/*void dwr()
{
//character to LCD display
output_high(RS);
output_high(E);
output_low(E);
delay_ms(2);
}
LCDPutchar( int t)
{
delay_ms(25);
output_b((unsigned char)t);
dwr();
delay_ms(25);
}*/
/*#int_rda
void serial_isr()
{
char_rcvd = fgetc(GSM);
while(char_rcvd !='\0')
{
//char_rcvd = fgetc(GSM);
data[i]=char_rcvd;
i++;
}
i=0;
//data[i] = 0; // return new line shows that all character has been collected
}*/
#int_rda
void serial_isr()
{
int i= 0;
//char_rcvd = fgetc(GSM);
// while (char_rcvd!='\0')
while(i!=2)
{
char_rcvd = fgetc(GSM);
data[i]=char_rcvd;
output_high(PIN_B7);
i++;
}
i=0;
t=1;
//data[i] = 0; // return new line shows that all character has been collected
}
void cmd()
{
//command for lcd display
output_low(RS);
output_high(E);
output_low(E);
delay_ms(2);
}
void readindex(void)
{
//while(1)
//{
delay_ms(1000);
fputc('A',GSM);
fputc('T',GSM);
fputc('+',GSM);
fputc('C',GSM);
fputc('M',GSM);
fputc('G',GSM);
fputc('f',GSM);
fputc('=',GSM);
fputc('1',GSM);
fputc(0x0D,GSM);
//fprintf(GSM, "AT+CMGF = 1\r\n"); //set to GSM to text mode
delay_ms(1000);
enable_interrupts(int_rda);
fputc('A',GSM);
fputc('T',GSM);
fputc('+',GSM);
fputc('C',GSM);
fputc('M',GSM);
fputc('G',GSM);
fputc('R',GSM);
fputc('=',GSM);
fputc('1',GSM);
fputc(0x0D,GSM);
//fprintf(GSM, "AT+CMGR = 1\r\n"); //read SMS at location inedex one
while(t!=1){} // wait til interrupt
disable_interrupts(int_rda);
delay_ms(100);
t = 0;
output_high(PIN_B6);
out_lcd_string(data); //send SMS string to LCD
}
void out_lcd_string(char *string) //this function will display all string of SMS from GSM
{
unsigned int i;
for(i =0; i<strlen(string); i++)
{
output_b((int)string[i]);
delay_ms(1);
output_high(PIN_E1); //enable
output_high(PIN_E0); //low disable
delay_ms(1);
output_low(PIN_E1);
delay_ms(1);
}
}
void lcddata(char value)
{
output_b(value); //put the value on the pins
output_high(PIN_E0); //rs high
output_high(PIN_E1); // enable pins H-L pulse
delay_ms(15);
output_low(PIN_E1); //enable pins
}
void LCDInit()
{
output_b(0x38);
cmd();
output_b(0x10);
cmd();
output_b(0x0f);
cmd();
output_b(0x06);
cmd();
output_b(0x01);
cmd();
}
void clear()
{
output_b(0x01);
cmd();
output_b(0x80);
cmd();
}
void display(char *x) //this function will display a string of character
{
int i = 0;
for(i = 0; i<strlen(x); i++)
lcddata(x[i]);
}
void main()
{
clear();
delay_ms(300);
LCDInit();
delay_ms(200);
//setup_adc_ports(NO_ANALOGS);
//setup_adc(ADC_OFF);
//setup_psp(PSP_DISABLED);
//setup_spi(FALSE);
//setup_wdt(WDT_OFF);
//setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(global);
enable_interrupts(int_rda);
//cmd(); // display on, cursor on
//delay_ms(200);
//setup_oscillator(False);
/*
output_low(PIN_B7);
output_low(PIN_B6);
output_low(PIN_B5); // goes low for GSM modem*/
/*poweron();
delay_ms(200);
delay_ms(500);
lcdcmd(0x38); // init LCD 2 lines 5x7 matrix
delay_ms(200);
lcdcmd(0x0e); // display on, cursor on
delay_ms(200);
lcdcmd(0x01); // clear LCD
delay_ms(200);
lcdcmd(0x80); //shift cursor
delay_ms(200);*/
display( initialize ); //display initialize on LCD
delay_ms(300);
readindex();
delay_ms(200);
while(1)
{
//out_lcd_string(data);
//delay_ms(200);
//}
/*void lcdcmd(int value1)
{
output_low(PIN_E0); //rs low
output_low(PIN_E1); //enable
output_d(value1) ; //put the value on the pins
output_high(PIN_E1); //strobe the enable pins H-L pulse
delay_ms(15);
output_low(PIN_E1); //enable
}*/
/*void clear_lcd(void)
{
output_low(PIN_E1); //enable bit
output_low(PIN_E0); // Rs= 0
output_d(0x01); //clear display
output_high(PIN_E1); // H-L pulse
delay_ms(1);
output_low(PIN_E1); // H-L pulse
}*/
/*void poweron(void)
{
output_low(PIN_B5);
output_high(PIN_B5);
delay_ms(2000);
output_low(PIN_B5);
}
*/
}
}
|
|
| Back to top |
|
 |
amila133
Joined: 13 Oct 2009 Posts: 28 Location: Sri Lanka
|
19 Oct 2009 7:23 Re: GSM modem with PIC 16F877A |
|
|
|
|
Hi,
I want to send and read SMS using PIC. I hope to use AT commands for this purpose. I found lot of AT commands. But I am confuse with How should I process AT commnds with PIC.
I am going to use MikroC for PIC programming, Is it suitable?
Can any one explain this Using simple example?
|
|
| Back to top |
|
 |
nipuna84
Joined: 01 Jul 2007 Posts: 1
|
06 Nov 2009 10:18 Re: GSM modem with PIC 16F877A |
|
|
|
|
| amila133 wrote: |
Hi,
I want to send and read SMS using PIC. I hope to use AT commands for this purpose. I found lot of AT commands. But I am confuse with How should I process AT commnds with PIC.
I am going to use MikroC for PIC programming, Is it suitable?
Can any one explain this Using simple example? |
Hi amila, I think I can help you. I have done many projects with AT commands & PIC's. reply me through nipuna84(at)gmail.com
nipuna84(at)gmail.com
University of Moratuwa
Sri Lanka
|
|
| Back to top |
|
 |
coldy
Joined: 07 Nov 2009 Posts: 3 Location: Bozuyuk
|
07 Nov 2009 16:05 Re: GSM modem with PIC 16F877A |
|
|
|
|
Hi everybody,
I am trying to prepare a common project for checking and controlling some stuff in my village house; Sensor -> Pic -> Mobile Phone and Mobile Phone -> Pic -> Actuator by using SMS.
But already I spent a considerable time and still I could not succeed. In fact I already checked the forum, but unfortunately still could not succeed .
And as a general information;
Mobile phone is T630 sony ericsson, which supports txt mode.
I use 16F877 (20/P), MAX232, 4 MHz Crystal,
I use pic basic pro,
Below I put some info about my latest situation:
(1) I can communicate between pic to hyper terminal and hyper terminal to pic without problem.
I used a USB1.1 to RS232 converter cable, because I don’t have serial port on my notebook.
Schematic is as shown:
PBP code is as shown:
| Code: |
' Initialization
TRISB=%00000000
PORTB=%00000000
'Definitions
DEFINE OSC 4
DEFINE HSER_TXSTA 20h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
BEGIN:
PORTB = 0
HIGH PORTB.7
PAUSE 1000
LOW PORTB.7
HIGH PORTB.6
HSerout ["AT",13,10] 'TEST COMMUNICATION
HSERIN 5000,begin,[WAIT("OK")]
HIGH PORTB.5
PAUSE 500
GOTO begin
'END
End |
Hyper Terminal Settings are as below:
Bits per second:2400 / Data Bits:8 / Parity : None / Stop Bits:1 / Flow Control :None
Both simulation and real test are succeeded;
(2) I can communicate between pc to mobile and mobile to pc without problem. Below you can see some of commands and answers.
Again I used a USB1.1 to RS232 converter cable.
AT
OK
AT+CMGF=?
+CMGF: (0,1)
OK
AT+CMGF=1
OK
AT+CMGS="0XXXXXXXXXX",129 ‘ ”0XXXXXXXXXX” – TEL NO ‘
> "SELAM DENEME MESAJIDIR"
+CMGS: 0
OK
(3) Test Communication between pic and mobile phone,
The same
- pic basic pro program same as above,
- 16f877, 4Mhz, 2400 8-N-1 baud rates.
- the same connections as:
RS232 pins 1-4-6 interconnected, pins 7 and 8 interconnected, pin 5 earth,
RS232 pin2(RX) to leg7(T2OUT) of max232
RS232 pin3(TX) to leg8(R2IN) of max232
PIC RC6/TX to leg10(T2IN) of max232
PIC RC7/RX to leg9(R2OUT) of max232
But this time I can not see the 3rd led, wait 5 seconds and return back to loop.
This is where I stopped, My biggest concerns are :
- baud rate,
- crystal 4Mhz may be not enough,
May I have you kind suggestions? Thanks in advance for your support
|
|
| Back to top |
|
 |
amila133
Joined: 13 Oct 2009 Posts: 28 Location: Sri Lanka
|
08 Nov 2009 8:51 Re: GSM modem with PIC 16F877A |
|
|
|
|
Hi,
Although PC is USB host, your PIC doesn't act as the USB host. because both PIC and Phone are USB clients as I know. check furthue about this matter.
If you found the real solution pls inform to me. Because I am also doing same project
Regards,
Amila
|
|
| Back to top |
|
 |
coldy
Joined: 07 Nov 2009 Posts: 3 Location: Bozuyuk
|
08 Nov 2009 19:47 Re: GSM modem with PIC 16F877A |
|
|
|
|
hmmmm nice point, i will consider about this for sure thanks.
Forsure i can share if i can succeed, i believe in gain & gain
Regards,
|
|
| Back to top |
|
 |
linoko
Joined: 25 Jun 2004 Posts: 43 Helped: 2
|
09 Nov 2009 9:58 Re: GSM modem with PIC 16F877A |
|
|
|
|
Hi coldy,
Try to change baud to 9600 or 19200
Best regards
Linoko
|
|
| Back to top |
|
 |
coldy
Joined: 07 Nov 2009 Posts: 3 Location: Bozuyuk
|
09 Nov 2009 17:18 Re: GSM modem with PIC 16F877A |
|
|
|
|
Hmmm ok i will try,
But frankly speaking i believe there should be another reason,
even maybe tooooo simple hehe
thanks anyway,
Added after 4 hours 33 minutes:
Thanks to your kind suggestions all,
In fact, Ajay Bhargav from 8051projects.net forum, I really appreciate his latest comment .
The solution is; making some additional connections at GSM serial port, as below;
Before I only connected, RX,TX and GRND pins of the GSM serial port.
And below you can see the general connection latest I made:
And a program to send sms and or call a phone number is as follows:
| Code: |
'Definitions
DEFINE OSC 4 'for 4 Mhz
'DEFINE OSC 8 'for 8 Mhz
DEFINE HSER_TXSTA 20h 'I wonder shall I define as DEFINE HSER_TXSTA 24h???
DEFINE HSER_RCSTA 90h 'same for all
DEFINE HSER_BAUD 2400 'for 2400 Baud rate
'DEFINE HSER_BAUD 4800 'for 4800 Baud rate
'DEFINE HSER_BAUD 9600 'for 9600 Baud rate
DEFINE HSER_SPBRG 25 'for 4Mhz/2400 & 8Mhz/4800 with an error %0.16
'DEFINE HSER_SPBRG 12 'for 4Mhz/4800 & 8Mhz/9600 with an error %0.16
DEFINE HSER_CLROERR 1 'same for all
' Initialization & Declaration
i var byte
TRISB=%00000000
PORTB=%00000000
TRISD=%00001111
PORTD=%00000000
' CHECK
FIRSTCHECK:
HIGH PORTB.7
PAUSE 500
HIGH PORTB.6
PAUSE 500
HIGH PORTB.5
PAUSE 500
HIGH PORTB.4
PAUSE 500
PORTB=%00000000
GSM_CHECK:
HSEROUT ["AT",13] 'Send AT to modem followed by a CR
HSERIN 5000, GSM_CHECK, [WAIT("OK")] 'Check OK reply, wait 5sec max.
HIGH PORTB.7
PAUSE 1000
HSEROUT ["AT+GMM",13] 'Ask model name
HSERIN 5000, GSM_CHECK, [WAIT("T610 series")] 'Check model name
HIGH PORTB.6
PAUSE 1000
HSEROUT ["AT+IPR=2400",13] 'Set transfer speed
HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
HIGH PORTB.5
PAUSE 1000
HSEROUT ["AT+CMGF=1",13] 'send AT to modem followed by a CR and line feed
HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
HIGH PORTB.4
PAUSE 1000
PORTB=%00000000
BEGIN:
IF PORTB.5=1 THEN ERROR_CALL
IF PORTB.6=1 THEN ERROR_SMS
HIGH PORTB.7
pause 1000
LOW PORTB.7
if PORTD.2 = 0 then SEND_SMS
IF PORTD.3 = 0 THEN CALL_PHONE
PAUSE 1000
GOTO BEGIN
SEND_SMS:
HIGH PORTB.6
HSEROUT ["at+cmgs=",34,"XXXXX",34,13]
PAUSE 1000
HSEROUT ["this is a test message",26]
HSERIN 10000, BEGIN, [WAIT("OK")]'Check OK reply, wait 5sec max.
LOW PORTB.6
GOTO BEGIN
CALL_PHONE:
HIGH PORTB.5
HSEROUT ["atd[XXXXX];",13]
HSERIN 5000, BEGIN, [WAIT("OK")]'Check OK reply, wait 5sec max.
PAUSE 2000
LOW PORTB.5
GOTO BEGIN
ERROR_CALL:
FOR i = 1 to 5
HIGH PORTB.4
PAUSE 500
LOW PORTB.4
PAUSE 500
next i
PORTB=%00000000
GOTO BEGIN
ERROR_SMS:
FOR i = 1 to 5
HIGH PORTB.4
PAUSE 500
LOW PORTB.4
PAUSE 500
next i
PORTB=%00000000
GOTO BEGIN
' END
End |
Thanks again for your attention and time, I will continue with :
- Improving the program to a real case scenario,
- Think more about the real case scenario, because at first stage I would like to use this as an alarm system for my garden house. I will need some sensors for unexpected visitors or animals.
Do you have any idea, what kind of sensors I can use to detect unexpected visitors?
Regards,
|
|
| Back to top |
|
 |
amila133
Joined: 13 Oct 2009 Posts: 28 Location: Sri Lanka
|
10 Nov 2009 8:56 Re: GSM modem with PIC 16F877A |
|
|
|
|
| Thanks coldy, great effort
|
|
| Back to top |
|
 |