EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / hiiiii…..i made a c code to

hiiiii…..i made a c code to

|

Microcontroller › 8051 › GSM based smart information system for lost cards › hiiiii…..i made a c code to

January 27, 2012 at 12:12 pm #7083
arun kumar yadav
Participant

hiiiii…..

i made a c code to send a msg through gsm module. but i did not get desired result. plz check the code and help…

 

#include<reg51.h>
#define FREQ 12000000
#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1)

sbit gas=P2^0;
sbit pir=P2^1;
sbit fire=P2^2;

int i=0,j,k,temp;
unsigned char *sms_service=”AT+CSMS=1″;
unsigned char *sms_format=”AT+CMGF=1″;
unsigned char *sms_write=”AT+CMGS=”7520487033″”;  // 10-Digit Mobile Number
unsigned char *sms=”gas leakage”;
unsigned char *smss=”moving body”;
unsigned char *smsss=”fire”;
unsigned char *sms_report=”SMS Sent…”;
unsigned char sms_terminate=0x1A;
unsigned char enter=0x0D;

void delay(unsigned int msec)        // Function for delay
{
    int i,j;
    for(i=0;i<msec;i++)
        for(j=0; j<1275; j++);
}

void init_serial()            // Initialize serial port
{
    TMOD=0x20;            // Mode2
    TH1=0xFD;            //buad rate
    SCON=0x50;            // Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit, Receiving on
    TR1=1;                // Start timer
}

void tx_data(unsigned char str)        // Transmit data function
{
    SBUF=str;                  //Store data in SBUF
    while(TI==0);                 //Wait till data transmits
    TI=0;
}

void gsm_cmd(unsigned char *string)
{
    i=0;j=0;
    while(string!=’’)
    {
        temp=0;
        if(string
==0x5C)        // Not to send ” cahracter
        i++;
        tx_data(string
);        // Send by serial communication
        i++;
        while(temp!=1);
    }
    temp=0;
    tx_data(enter);                // Send ASCII code for ‘Enter’ key
    while(temp!=1);
}

void main()
{
    P2=0xFF;
    P2=0x00;
    init_serial();
    while(1)
    {
    
        if(gas==1)
        {
           gsm_cmd(sms_service);
            gsm_cmd(sms_format);
            delay(1000);
gsm_cmd(sms_write);
            delay(1000);
gsm_cmd(sms);
            tx_data(0x1A);
            delay(1000);
        }
        else if(pir==1)
        {
        gsm_cmd(sms_service);
            gsm_cmd(sms_format);
            delay(1000);
gsm_cmd(sms_write);
            delay(1000);
gsm_cmd(smss);
            tx_data(0x1A);
            delay(1000);
        }

        else if(fire==1)
        {
        gsm_cmd(sms_service);
            gsm_cmd(sms_format);
            delay(1000);
gsm_cmd(sms_write);
            delay(1000);
gsm_cmd(smsss);
            tx_data(0x1A);
            delay(1000);
        }

}
}

RSS feed: Recent Posts Recent Posts

  • Portable charger for my mate's new leg October 16, 2026
  • solderless sma screw mounting RF causaliy problem October 15, 2026
  • Almost Very New in PCB / KICAD DESIGN October 15, 2026
  • Delco alternator (12SI) AC-tap - what is the mate to this connector called and where to find it? October 15, 2026
  • Semi-automatic battery handler October 15, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy | Advertising

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise