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 / Topics / Gsm based eNoticeboard

Gsm based eNoticeboard

|

Microcontroller › 8051 › Gsm based eNoticeboard

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 7 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • October 3, 2012 at 7:10 pm #1979
    sonu
    Participant

    i designed this code as reception of SMS on Modem n get print over a LCD, there is some error when msg recived and have to be print over LCD, please assist something where is the bug…
    my code is plz suggest something where is the fault :(


    #include
    sbit RS=P3^7;
    sbit EN=P3^5;
    sbit RW=P3^6;
    sbit BZ=P3^4;
    sbit BZ1=P3^3;
    #define LCD_PORT P2
    //


    // Forward function declaration
    //


    unsigned char Rxmsg(void);
    void lcdinit(void);
    void lcdData(unsigned char l);
    void lcdcmd(unsigned char k);
    void DelayMs(unsigned int count);
    void InitModem(void);
    void initdisplay(void);
    code unsigned char msg[25]="Welcome to eNotice Board";
    //


    // Main rotine
    //


    void main()
    { RW=0;
    TMOD=0x20; // Configure UART at 9600 baud rate
    TH1=0xFD;
    SCON=0x50;
    TR1=1;

    lcdinit(); // Initialize LCD
    initdisplay();
    DelayMs(5000);
    while(1)
    {
    InitModem();
    Rxmsg();
    }
    }
    //


    // Modem initialization subroutine
    //


    void InitModem(void) // "a", 'a'
    {unsigned int j=0;
    unsigned char i=0,k=0;
    unsigned char a[]="at+cmgf=1";
    //unsigned char b[]="at+cpms="ME","ME","ME"" ;
    unsigned char c[]="at+cmgd=" ;
    unsigned char d[6];

    ReInit:
    for(i=0;i<6;i++)
    d=0x00;

    i=0;
    while(a
    !='')
    {SBUF=a
    ;
    while(TI==0); // ATE0 sending to turn off the echo
    TI=0;
    lcdData(a
    );
    i++;}

    lcdData(' '); // Enter
    SBUF=0x0d;
    while(TI==0);
    TI=0;

    for(i=0;i<4;i++) //command to recv data
    {j=0;
    while(RI==0)
    {if(j>=1000)
    goto ReInit;
    DelayMs(1);
    j++;
    }
    d
    =SBUF;
    RI=0;
    lcdData(d
    );
    }

    for(i=0;i<4;i++) //command to compare data
    {if((d
    =='E') || (d=='R'))
    goto ReInit;
    if((d
    =='O') || (d=='K'))
    goto InitS;}

    InitS:
    for(k=0;k<10;k++)
    {for(i=0;i<6;i++)
    d
    =0x00;

    lcdcmd(0x01);
    DelayMs(10);
    lcdcmd(0x80);
    DelayMs(10);

    i=0;
    while(c
    !='')
    {SBUF=c
    ;
    while(TI==0); // sending AT+CMGD to delete message
    TI=0;
    lcdData(c
    );
    i++;}

    lcdData(k + 0x30); // Enter
    SBUF=k + 0x30;
    while(TI==0);
    TI=0;

    lcdData(' '); // Enter
    SBUF=0x0d;
    while(TI==0);
    TI=0;

    for(i=0;i<5;i++) //command to recv data
    {j=0;
    while(RI==0)
    {
    if(j>=1000)
    goto ReInit;
    DelayMs(1);
    j++;
    }
    d
    =SBUF;
    RI=0;
    lcdData(d
    );
    }
    DelayMs(100);
    }
    //return 0;
    }

    //


    // Recieve message subroutine
    //


    unsigned char Rxmsg(void)
    {unsigned char i=0,ret=0;
    unsigned int j=0;
    unsigned char c[90];
    unsigned char d[6];

    retry:

    lcdinit();
    lcdcmd(0x80);
    DelayMs(10);

    while(msg!='')
    {
    lcdData(msg
    );
    lcdcmd(0x18);
    DelayMs(500);
    i++;
    }

    for(i=0;i<16;i++)
    {
    lcdData(' ');
    lcdcmd(0x18);
    DelayMs(400);
    }

    for(i=0;i<90;i++)
    c
    =0x00;

    for(i=0;i<6;i++)
    d
    =0x00;
    for(i=0;i<4;i++) //command to recv data
    {
    j=0;
    while(RI==0)
    {
    if(j>=1000)
    goto retry;
    DelayMs(1);
    j++;
    }
    d
    =SBUF;
    RI=0;
    lcdData(d
    );
    }

    for(i=0;i<5;i++)
    d
    =0x00;
    for(i=0;i<4;i++) //command to compare data
    {
    if((d
    =='E') || (d=='R'))
    return ret;
    if((d
    =='+') || (d=='C')|| (d=='M')) // message recieved
    goto sucess;
    }

    sucess:
    BZ1=0;
    DelayMs(100);
    SBUF='a';
    while(TI==0);
    TI=0;

    SBUF='t';
    while(TI==0);
    TI=0;

    SBUF='+';
    while(TI==0);
    TI=0;

    SBUF='c';
    while(TI==0);
    TI=0;

    SBUF='m';
    while(TI==0);
    TI=0;

    SBUF='g';
    while(TI==0);
    TI=0;

    SBUF='r';
    while(TI==0);
    TI=0;

    SBUF='=';
    while(TI==0);
    TI=0;

    SBUF='1';
    while(TI==0);
    TI=0;

    SBUF=0x0d;
    while(TI==0);
    TI=0;

    DelayMs(100);

    for(i=0;i<90;i++)
    {
    j=0;
    while(RI==0)
    {
    if(j>=1000)
    goto timeout;
    DelayMs(1);
    j++;
    }
    c
    =SBUF;
    RI=0;
    }
    BZ1=1;
    timeout:

    for(i=0;i<5;i++) //command to recv data
    {
    if((c
    =='E') || (c=='R'))
    return ret;
    }

    for(i=0;i<92;i++)
    {
    if((c
    =='1') && (c[i+1]=='2') && (c[i+2]=='3')&& (c[i+3]=='4') && (c[i+4]=='5') )
    goto sucess1;
    if((c
    =='D') && (c[i+1]=='E') && (c[i+2]=='L'))
    goto delete;
    }

    /*
    sucess1:
    for(;i<92;i++)
    {
    if((c
    =='1') && (c[i+1]=='2') && (c[i+2]=='3')&& (c[i+3]=='4') && (c[i+4]=='5') )
    goto sucess2;
    }
    goto delete; */

    sucess1:
    BZ=0;
    lcdcmd(0x01);
    lcdcmd(0x84);
    DelayMs(1000);
    BZ=1;

    i=i+5;
    j=0;
    while(c[i+4]!='O' && c[i+5]!='K')
    {
    //msg[j]=c
    ;
    lcdData(c
    );
    DelayMs(100);
    i++;
    j++;
    }
    //msg[j]='';

    delete:
    for(i=0;i<90;i++)
    {
    c
    =0x00;
    }

    SBUF='a';
    while(TI==0);
    TI=0;

    SBUF='t';
    while(TI==0);
    TI=0;

    SBUF='+';
    while(TI==0);
    TI=0;

    SBUF='c';
    while(TI==0);
    TI=0;

    SBUF='m';
    while(TI==0);
    TI=0;

    SBUF='g';
    while(TI==0);
    TI=0;

    SBUF='d';
    while(TI==0);
    TI=0;

    SBUF='=';
    while(TI==0);
    TI=0;

    SBUF='1';
    while(TI==0);
    TI=0;

    SBUF=0x0d;
    while(TI==0);
    TI=0;

    for(i=0;i<5;i++) //command to recv data
    {
    j=0;
    while(RI==0)
    {
    if(j>=1000)
    goto delete;
    DelayMs(1);
    j++;
    }
    c
    =SBUF;
    RI=0;
    }

    return ret;
    }

    //


    // Lcd initialization subroutine
    //


    void lcdinit(void)
    {
    lcdcmd(0x38);
    DelayMs(250);
    lcdcmd(0x0C);
    DelayMs(250);
    lcdcmd(0x01);
    DelayMs(250);
    lcdcmd(0x06);
    DelayMs(250);
    lcdcmd(0x80);
    DelayMs(250);
    }

    //


    // Lcd data display
    //


    void lcdData(unsigned char l)
    {
    LCD_PORT=l;
    RS=1;
    EN=1;
    DelayMs(1);
    EN=0;
    return;
    }

    //


    // Lcd command
    //


    void lcdcmd(unsigned char k)
    {
    LCD_PORT=k;
    RS=0;
    EN=1;
    DelayMs(1);
    EN=0;
    return;
    }

    //


    // Delay mS function
    //


    void DelayMs(unsigned int count)
    { // mSec Delay 11.0592 Mhz
    unsigned int i; // Keil v7.5a
    while(count) {
    i = 115; // 115 exact value
    while(i>0) i--;
    count--;
    }
    }

    void initdisplay(void)
    {
    unsigned char d=0,a[]=" SMS Based",c[]=" Notice Board";
    lcdcmd(0x01);
    lcdcmd(0x80);
    while(d!=15)
    {
    lcdData(a[d]);
    d++ ;
    }

    lcdcmd(0xc0);
    DelayMs(10);
    d=0;
    while(c[d]!='')
    {
    lcdData(c[d]);
    d++;
    }
    }

    October 24, 2012 at 4:35 pm #8686
    AJISH ALFRED
    Participant

    Hi Sonu,

    No one would be interseted to go through such a code post. Please make it more comfortable to read.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Chinese Tarrifs – 104%!?! May 21, 2025
  • can a AT89C51 be used as a rom? May 21, 2025
  • Telegram Based Alarm - Sensor cable protection May 21, 2025
  • An Update On Tarrifs May 21, 2025
  • Tariff Updates from JLCPCB as of Today May 21, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media 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 WTWH Media
Privacy Policy | Advertising | About Us

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