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 / problem in receving message with pic16f877a

problem in receving message with pic16f877a

|

Microcontroller › PIC › problem in receving message with pic16f877a

  • This topic has 11 replies, 3 voices, and was last updated 11 years, 5 months ago by kittythakur.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • December 28, 2013 at 9:56 am #2782
    kittythakur
    Participant

    heelo guys …. i m making project to switch on and off led by sms….i m using p16f877a with sim900a modem 

     

    i m able to send message from modem to mobile but i m getting problem while receiving text

     

    i m using AT+CMGR=1 

    and getting +CMGR: “REC READ”,”+917696897725″,,”12/07/22,14:24:11+22″

    #a1

     

    i want to extract #a1 from the string and rest string i want to skip 

    i apllied various logic but did’t get right output

     

    here is my code

     
    if(UART1_Data_Ready()>0)
     {
    inchar=UART1_Read();
    i++;
    delay_ms(10);
            if (inchar==’#’)
            {i++;
            if(inchar==’o)’
            {i++;
            if(inchar==’n’)
     
                    {led=1;}
              else if (inchar==’f’)
            {led=0;}
            }
            }
            else {led=0;Tx();delay_ms(10);inchar=UART1_Read();UART1_Write_Text(“AT+CMGD=1,4”);UART1_Write(0x0D); }
            }
     
    can anybody correct my code ????
    December 28, 2013 at 1:20 pm #10769
    AJISH ALFRED
    Participant

    Hi,

    Put that piece of code inside the infinite loop

     

    while (1)

    {

    /////// code /////

    }

    December 30, 2013 at 4:42 am #10786
    kittythakur
    Participant

    Thanks for reply 

     

    actaully i apllied this code in infinite loop …you can check this

     
     
     
    while(1)
    { UART1_Init(9600);
    delay_ms(500);
    UART1_Write_Text(“ATeo”);
    UART1_Write(0x0D);
    delay_ms(300);
    UART1_Write_Text(“AT+CMGF=1”);
    UART1_Write(0x0D);
    delay_ms(300);
    UART1_Write_Text(“AT+CNMI=2,2,0,0” );
    UART1_Write(0x0D);
    delay_ms(300) ;
    UART1_Write_Text(“AT+CMGR=1”) ;
    UART1_Write(0x0D);
    delay_ms(300);
     
    led1=1 ;
    if(UART1_Data_Ready()>0)
     {
     while (UART1_Read()==’’)
     {
    inchar=UART1_Read();
    i++;
    delay_ms(10);}
     
            if (inchar[0]==’#’)
            {i++;
            if(inchar[1]==’o’)
            {i++;
            if(inchar[2]==’n’)
     
                    {led=1;}
              else if (inchar[2]==’f’)
            {led=0;}
            }
            }
    else led=0;Tx();delay_ms(10);inchar=UART1_Read();UART1_Write_Text(“AT+CMGD=1,4”);UART1_Write(0x0D);
            }
            }

            }

     

     

     

    now tell me what to do ???

    it is not working ….can any body correct this??

    January 3, 2014 at 3:43 am #10812
    Rajesh K
    Participant

    yes… ur code hs a few prblems I cn see. U r using MikroC, yes?

     

    what is ur current state….? do u hv a deadline when this musst b fixed?

    January 3, 2014 at 6:48 am #10814
    kittythakur
    Participant

    rakesh thanx for reply

     

    yes m using micro c and i having problem in receiving data .can u plz tell me how to properly receive data,store in variable and compare with any string .you can see my code .

     plz its urgent

     

    January 3, 2014 at 2:54 pm #10815
    Rajesh K
    Participant

    many ways 2 debug this… some loops r wrong (or too complx  til bugs r fixd). ur code has no err chking so how can u find the problem???

     

    examples:

     

    add serial tap 2 chk io to sim900a (connect 2 pc via max232 or similr n thn use hyprterm)

     

    or add i2c lcd display n add code to out all recd data to lcd

     

    or add soft uart code in microc compiler n out all recd data to it

     

    or use microc sw simulatr

    January 3, 2014 at 11:38 pm #10817
    Rajesh K
    Participant

    when i do this proj in past,,, i use differnt algo to u ,,,,, eg init UART once, setup sim900 once, then loop waiting 4 chars to start, then loop reading chars into buffer or state machne testing 4 cmd start char eg #, then action on recd cmd (led, relay,,,), then back to loop waiting 4 chars. u shld not need delay_ms after UART1_Read!
     

    January 4, 2014 at 7:49 am #10818
    kittythakur
    Participant

    thnx rakesh 

     i tried as u said 

      Now i m checking my code in proteous with the help of  virtual terminal     i applied logic in which what i send to rx pin i should get in tx pin ,but when i send “#ON” to rx pin then i get “#NNN” or other garbage value

     

     

    case:2- sometimes if i send ‘#on’  ..i got #on on tx pin

    but if i send long string to rx pin then i only get 3 character accurate but after 3 character i get garbage value again

    January 4, 2014 at 4:11 pm #10820
    Rajesh K
    Participant

    i hv not used proteous in that way so unless u know it vry well, you can add more prblems instead of solve them!

     

    ur reslts cn happn eg due to ur exact new code :( this is y i wud use serial tap – no new code needed!

     

    remembr p18f877a uart rx fifo is very small – mayb u need to chk for rx over run, if u do to much than just rx chars

     

     

    January 6, 2014 at 8:44 am #10829
    kittythakur
    Participant

    thnx rakesh- 

     

    i only want toknow how i can store received string into a variable 

     

     

    problem is here “inchar=UART1_Read();”

     

    i cant suceesfully store data into “inchar” from UART1_Read  

     

    actaully i want to print received data on LCD 16*2 ,i tried many times but i get wrng result

    can u tell me how to correct this code.how can i print received string on lcd

    January 6, 2014 at 4:36 pm #10830
    Rajesh K
    Participant

    >problem is here “inchar=UART1_Read();”
    >i cant suceesfully store data into “inchar” from UART1_Read  

     

    1. how do u kno data fm UART1_Read() is gud?

    2. what exact prblem u get – compile err? run err? what?  same problem every time (with same SMS txt) or no?

    3. only when 2 points abve r clear, then we discuss how to stor gud data. OK bro?

     

    >actaully i want to print received data on LCD 16*2 ,i tried many times but i get wrng result
    >can u tell me how to correct this code.how can i print received string on lcd

     

    fix depnds on ur hw (pic+lcd+circuit) and sw (code+lib).

     

    January 7, 2014 at 4:22 am #10832
    kittythakur
    Participant

    1. how do u kno data fm UART1_Read() is gud?

    hello dear,   actaully m running my code in proteous bcoz my hyperterminal and com port is not wroking well.i m using virtual terminal with receiving and transmiting pin.,so when i give input on rx pin through virtual terminal ,it stores in  UART1_Read().after that i use UART1_Write(UART1_Read()); i get the same string on tx virtual terminal which i sent on rx pin.thats why i m saying UART1_Read is gud . but i want to store the string from UART1_Read() to  in a array,so that i can print data on lcd with the help of ” for loop. “

    2. what exact prblem u get – compile err? run err? what?  same problem every time (with same SMS txt) or no?

    i think, you got my problem now, . i m unable to store received data into a array

    here  inchar=UART1_Read();

     

     

     

    #define led1 PORTC.F1
    #define led PORTC.F0
    #define RS PORTC.F2
    #define RW PORTC.F3
    #define EN PORTC.F4
    unsigned char inchar;
    unsigned int i=0,j,k;
    char buffer[80] ;
    void Tx();
    void cmd( unsigned char x)
    {
    PORTD=x;
    RS=0;
    RW=0;
    EN=1;
    delay_ms(100);
    EN=0;
    }
    void dat ( unsigned char x )
    {
    PORTD=x;
    RS=1;
    RW=0;
    EN=1;
    delay_ms(100);
    EN=0;
    }
    void int_lcd()
    {
    cmd(0x38);
    cmd(0x0e);
     
    cmd(0x06);
    cmd(0x80);
    }
      void rcv ()
     {
    inchar=UART1_Read();   // i want to store received string in a buffer .and after that i want to print on lcd .i m having problem
    delay_ms(100);
    while(inchar!=’’)
    { 
     buffer=inchar;
    i++;
    }
     
    }
     
    void main()
    {
    TRISD=0x00;
    TRISC=0x80;
    led=0;
    led1=0;
    UART1_Init(9600);
    delay_ms(300);
    UART1_Write(0x0D);
    delay_ms(300);
    UART1_Write_Text(“AT+CMGF=1”);
    UART1_Write(0x0D);
    delay_ms(300);
    UART1_Write_Text(“AT+CNMI=2,2,0,0” );
    UART1_Write(0x0D);
    delay_ms(300) ;
        int_lcd();
    while(1)
    {
    led1=1 ;
    if(UART1_Data_Ready()>0)
      {
      rcv();
    for (j=0;j<=8;j++)
      {
      dat(buffer[j]);
      delay_ms(10);
     
      }
         cmd(0x01);
     
    }
           // UART1_Write_Text(“AT+CMGD=1,4”);
     
    }
    }

    firstly i want to controll led but now i want to  print data on lcd .

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

RSS Recent Posts

  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • Curved lines in PCB design June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 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