Previous 2 / 2

24 Comments

  1. 0867532

    Hello,
    i hope you can help me.
    look i have 3 varibles & char:
    char time[12];
    int sec = 0;
    int min = 0;
    int hrs = 0;

    then

    while (1) {
    . . .
    lcd_clear();
    sprintf(time, ” %d : %d : %d”,hrs,min,sec);
    lcd_puts(time);
    }
    but controller just restarts every sec.
    if i print only sec – it works.:(
    as you so cleaver, help plz.

    Reply
    • Elecrom

      Looks like it could be buffer overflow problem. Increase the size of time[] array to 15 or more. If you consider the maximum number “12 : 59 : 59 ” It is 13 character string. One more extra will be needed for NULL termination. Total 14 characters. So your array size is not sufficient and thus it is causing overflow and screwing up the execution.

      Reply
  2. mani

    hi.. i want to display 2 or 3 digit nos. on LCD.
    I tried your method and it worked fine till i tested it in proteus as a simulation..
    but when i tested it on hardware comprising 8051 and 16×2 LCD it did not display anything.

    After long time i figured out that if if delete the function sprintf() from the code the LCD works fine.

    so the doubt i have is whether the function usage also depends on the LCD being used?

    I have also tried using itoa() function but the compiler shows error even if i include stdlib.h .

    all i want to do is when i press a key on keypad the the microcontroller should count up from 0 to 200 and display it on LCD. As we can send data as characters only to display on LCD and dont know how to display 2 or 3 digit nos. easily.

    Kindly help.

    Reply
    • Elecrom

      Which compiler are you using ?

      The code should work on real LCD as well. Is your real LCD model and the proteus models are different ? Are you using standard 16×2 LCD in your project ?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *