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 / 8051 keeps executing

8051 keeps executing

|

Microcontroller › 8051 › 8051 keeps executing

  • This topic has 13 replies, 3 voices, and was last updated 12 years, 8 months ago by Anonymous.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • July 25, 2013 at 3:00 pm #2554
    Sandeep
    Participant

    I am using 89V51RD2 . any program i dump in it for example a HELLO WORLD display on LCD. there is no while(1) in my program for infinite execution , but it keeps displaying it again and again . As i am doing a interface with SIM900 , i need to send a command only once , but because of this i am not able to proceed . for information : when i check dis in keil simulation it executes once and stops . but why is my hardware behaving like this ?

     

    Someone pls help me know what is happening .

     

    Thanks in advance 

     

    Sandeep

    July 26, 2013 at 4:32 am #10204
    AJISH ALFRED
    Participant

    Hi Sandeep,

    It happens just because of the absence of while(1) loop in your code.

    Once your code done all the steps it simply won’t stop anmd remain idle, rather it redo executing from the first step. To avoid such situation people use while(1) or infinite loop at the end of their code. It helps in such a way that once the entire code is finished executing the controller enters into the infinite loop and remains there idle.

     

    Just add

     

    while(1);

     

    at the end of your code and i hope it will solve the proble.

     

    Also connect the Rx pin of the MCU to the Tx pin of the SIM300 only when it is necessary.

    July 26, 2013 at 6:58 am #10208
    Sandeep
    Participant

    Thanks a lot for the suggestion . Now its executing only once . But if in case i have to send a data , i use a function

     

     

    send_data(args);

    while(1);

     

     

    now my intention is to wait for another data to come from the other end . and now that there is a while(1); do you think it is possible.

     

     

    I send AT only once

    I have to wait for OK

     

     

    in the waiting period how do stop my 8051 from re-executing

     

    I hope u understood my problem 

     

    and thanks a lot in advance

    July 31, 2013 at 5:10 am #10248
    AJISH ALFRED
    Participant

    Hi Sandeep,

    Nice question.

    You can use the while loop itself to wait till something happens.

     

    For example you want to turn on an LED after the voltage at a pin say ‘P’ goes high. It can be done like the following;

     

    //


    //

    while ( P = = 0 );       // the code will continue looping here until the condition fails,  

                                      // means when the pin value becomes 1

     

    led_on ();

    //


    //

     

    Hope you got the idea.

     

    July 31, 2013 at 5:42 am #10249
    Sandeep
    Participant

    Thanks  alot for the reply

     

    I am stuck up in dis problem pls help me out with dis

     

    the problem is :

     

    TO SIM900:

     

    PC-> Hyperterminal -> ATD9738XXXX18;<enter>  : i get a call

     

    8051 -> same command : not getting a call

     

    have sent a carriage return after the command (0x0D)

     

    used realterm to check if the data coming out of 8051 is right . it is perfect when i compared wat i manually send and the command coming out of the 8051.

     

    SIM900 sends OK to the hyperterminal after the command 

     

    but it exactly sends <CR><LF>OK<CR><LF>

     

    i didnt write a routine to recieve data in 8051. will that be a problem?

     

    Next i did write a code to recieve and parallely as i recieve data i have to display it on the LCD(16×2)

    but i get garbage values.

     

    is my SIM900 not responding because i m  ot accepting the OK or is there something else . I am seriously not able to understand where the problem

     

    can u pls help me out with dis

     

    Thanks in advance

     

     

    Sandeep

    August 1, 2013 at 5:02 am #10251
    AJISH ALFRED
    Participant

    Hi Sandeep,

    I guess the max232 IC circuit between the 8051 and the SIM900 is working perfectly.

     

    I also had the same problem, it was due to some power supply connection issue when connecting with the microcontroller board, the SIM900 will respond with AT commands but not able to make a call or send message.

     

    Please post here the exact circuit you are using right now.

     

    First try to fix this issue and then we will look into the LCD problem.

    August 1, 2013 at 6:27 am #10252
    Sandeep
    Participant

    Thanks Ajish

     

    There is no custom ciruitary i have buit

     

    using 8051 development board 

     

    RS232 connection b/w 8051 board and sim900 board

     

    data getting out of RS232 is perfectly fine as checked it in realterm.

     

    now i am writing a small code to display data sent from hyperterminal on the LCD -> troubleshooting

     

    how do u think power supply will be a problem?, 8051 and SIM900 working perfectly fine when used independently and the data sent to sim900 using 8051 and PC are exactly the same .

     

    What do you think can be d problem?

     

     

    Thanks

     

    Sandeep

     

    August 2, 2013 at 4:30 am #10260
    AJISH ALFRED
    Participant

    Hi Sandeep,

    I’ve used a SIM900 based module, and by mistake I was using a 3.3V power adaptor. Still it was giving me response when I send AT comands !

    But not able to make a call or send messages. 

    Since you are using two seperate power supply, the ground should be properly shorted together and the two power supply should not in anyway affect each other. Just make sure using a multimeter that you are getting 5V at the output of the regulator ICs in both your development board and the GSM module.

     

    Post your LCD code, I’ll try to figure out if there is any bug in it.

    August 2, 2013 at 4:35 am #10261
    Sandeep
    Participant

    Hi Ajish ,

     

    U suspected that there may be a power supply problem 

     

    so I soldered two wires btw the module and now there is single power supply 

     

    and i also chkd with the multimeter ,its perfetly fine

     

    i can send u the code :

     

    send a dummy mail to my id sunny2791@gmail 

     

    i will immediately send the code to ur id

    August 2, 2013 at 9:42 am #10262
    AJISH ALFRED
    Participant

    Hi Sandeep,

    That’s good. Now you don’t have to worry about the hardware right!!

    You can simply copy paste your code with your next post. I guess that would be far more better as you can get help or advise from other people in this forum.

    August 8, 2013 at 10:32 am #10303
    Sandeep
    Participant

    Hi ajish thanks a lot for all ur replies 

     

    I found the bug

     

    the Tx of 8051 was getting connected to Tx of SIM900 and same with Rx , it happened because i was using a male to male connector.

     

    now that is resolved

     

    data recieved was seen on LCD when i used

     

             ch= SBUF;

             str[count++]=ch;    // used to store the data

             lcd_data(str[count-1]);   // directly showing wat ever i recieved

     

    Now wrote a code to display the stored data in str[] , which is not happening

     

    code is:

     

    char str[20];

     

    void lcd_data(char data1)
    {
    P0=data1;
    RS=1;
    RW=0;
    E=1;
    delay(10);
    E=0;
    }  
     
     
    void serial_rx() interrupt 4 
    {
     
    char ch;
     
     
      if(RI==1)
    {
                  ch= SBUF;
                  if(ch==0X0D)
                  {
                      carr=1;
                   }
     
                   if(ch==0X0A)
                   {
                           linefd=1;
                     }
                   if(ch!=0x0D && ch!= 0x0A)
                   {
                           str[count++]=ch;
                           lcd_data(str[count-1]);
                       }
                   if(ch==0X0D && carr==1 )
                   {
                           str[count]=’’;
                           carr=0;
                           linefd=0;
                           count=0;
                     }
     
              }
     
           RI = 0;
     
    void main()
    {
    …
    …
    …
     
    for(i=0;i!=’’;i++)
    {
    lcd_data(str);
    delay(20);
    }
    …
    …
    …
     
    }

     

    August 9, 2013 at 4:48 am #10306
    AJISH ALFRED
    Participant
     
    Try increasing the delay inside this function.
     
    void lcd_data(char data1)
    {
         P0=data1;
         RS=1;
         RW=0;
         E=1;
         delay(10);
         E=0;
    }  
     
    Have you tried any simple program to display a character or a sting in the LCD?
    One more thing is that directly writing the serial data received to an LCD is not a good method, since the LCD writing may consume significant time and there is a chance chance of missing the serial data. 
    August 9, 2013 at 9:14 am #10309
    Sandeep
    Participant

    Hi ajish 

     

    I have tried a simple LCD program also , its working fine

     

    my problem is 

     

    serial data i/p has to put on to string say str[20] a global array

     

    den serially display it on the LCD

     

    so now , displaying the string on  the LCD is working fine ,but storing the serial input characters in an array is giving the problem i guess

     

    and next,

     

     

    in my main function think i am firsst displaying “hello world ”  on my LCD and then my program enters a while(1); loop

     

    now incase i get a recieve interrupt -> it jumps to ISR gets the character and stores in th array 

     

    and den i need to print the string but after the ISR but it goes into the while(1);

     

    what to do ?

     

    den i thought i will use polling method to get the data, but that seems to be a bad practice.

     

    wat do i do now ?

     

    Thank you

     

    Sandeep

     

     

    August 13, 2013 at 6:15 am #10321
    Anonymous
    Guest

    Hi Sandeep,

    Sorry for the delayed response.

    I found this from your ISR;

     

                   if(ch!=0x0D && ch!= 0x0A)
                   {
                           str[count++]=ch;
                           lcd_data(str[count-1]);

                   }

     

    ISR should always be very light, less time consuming and free of any function calls. Hence I suggest you to avoid the statement;

     
                           lcd_data(str[count-1]); 
     
    from your ISR and try.
     
    The function will still be executing even if the next interrupt happens and I guess that could be the reason.
  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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