GSM Interfacing with 8051

GSM module is used in many communication devices which are based on GSM (Global System for Mobile Communications) technology. It is used to interact with GSM network using a computer. GSM module only understands AT commands, and can respond accordingly.




1) Gsm.c

/*
1. dail number
2. answer
3. hang
4. send text message
*/
#include "gsm.h"
sbit dial=P2^0;
sbit answer=P2^1;
sbit hang=P2^2;
sbit smssend=P2^3;
void delay(int n)
{
int i=0;
for(;i<n*1000;i++);
}
void main()
{
char * dial_str="ATD9821239040";
char * answer_str="ATA";
char * hang_str="ATH";
char * msg_type="AT+CMGF=1";
char CtrlZ=0x1A;
char * msg="hello world";
char * cmd_cmgs="AT+CMGS=\"9821239040\"";
gsm_init();
dial=answer=hang=smssend=1;
if(dial==0)
{
gsm_trfr(dial_str);
gsm_tx(0x0d);// enter
delay(10);
}
if(answer==0)
{
gsm_trfr(answer_str);
gsm_tx(0x0d);// enter
delay(10);
}
if(hang==0)
{
gsm_trfr(hang_str);
gsm_tx(0x0d);// enter
delay(10);
}
if(smssend==0)
{
gsm_trfr(msg_type);
gsm_tx(0x0d);// enter
gsm_trfr(cmd_cmgs);
gsm_tx(0x0d);// enter
gsm_trfr(msg);
gsm_tx(0x0d);// enter
gsm_tx(CtrlZ);
gsm_tx(0x0d);// enter
delay(10);
}
}


Simulation




No comments:

Post a Comment