1. 0867532

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


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

    • Omkar

      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.

  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.

    • Omkar

      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 ?

  3. dh

    how to print custom characters on the lcd using code vision avr ?

  4. Maryam

    any idea why my LCD comes on but does not show any character? Am I missing anything?

  5. sigit

    how to clear line lcd.?

  6. santy

    PLZZZ help me to display float number on LCD is there is %f for that ???
    plz tell me..

    • Omkar

      u can use %f in codevisionavr. See its help.

    • nishantdawn

      inlude this heder file

      declare a float
      float f

      declare a char
      char c[10]

      there is an inbuilt commend in cvavr ftoa u can se it like this

      now ur float is converted into a variable string c

      now print it

      • nishantdawn

        inlude this heder file

        declare a float
        float f

        declare a char
        char c[10]

        there is an inbuilt commend in cvavr ftoa u can se it like this

        now ur float is converted into a variable string c

        now print it

  7. Kuthsav

    Hi sir,
    Can u please send me the code for finding temperature using ATmega32L and LM35.
    AM using codevisionAVR C compiler.

  8. acceph

    Hi all, especially to Omkar, Nice article!!

    I am developing a graphic LCD system now, and I use many sprintf() function.
    the format is like this :
    I use this line inside an interupt to update the time periodically.
    I think there is no mistake on syntax or any other thing. BUT, some of my global variable are truncated!! I don’t know the reason, Have you ever meet this kind of problem?

    Because I have check that truncated variable before and after the bold sprintf() line.
    Before is no problem, but after those line, the global variable already truncated, and untill now I still couldn’t fix it, I hope I will find answer here..

    anyway, thank’s for your kindly help

    • Omkar

      Which compiler you are using ? If you are getting unexpected global variable truncation/overwriting then you should increase the program’s data stack size. Generally compiler uses some default data stack size (e.g. CVAVR uses 256 bytes). If your global variables exceed this space, then they will be overwritten by some other activity in your program. Try increasing data stack size. You will have to refer your compiler’s manuals.

  9. roozbeh

    hi i need to program lcd for stylize 8 bit with codevision
    because in codevision we only program lcd for stylize 4
    do i must write separate library for that?

    • Omkar


      • Roozbeh

        I did not find any library, can you help me find that? or write that? i founded something in c++, but i’m working by codevision. Tnx

        • Omkar

          there is no library for 8 bit access. You will have to write one.

  10. jatin

    hello, its jatin.
    I have done LCD interfacing on Code vision AVR on PORT B.
    Now I want to interface another LCD on the same atmega micro-controller. So how to address both the LCD.? Or if I want to end particular data on ONE LCD and some other data on Second LCD.?

    • Omkar

      You can employ following scheme :
      PB0 -RS of both LCDs
      PB1 -RD of both LCDs
      PB2 – A input of EXOR gate
      PB3 – B input of EXOR gate, EN of LCD2
      PB4 -D0 of both LCDs
      PB5 -D1 of both LCDs
      PB6 -D2 of both LCDs
      PB7 -D3 of both LCDs

      output of EXOR gate – Connect to EN of LCD1.

      Idea is like this : cvavr controlls the PB2 to enable the LCD when u call LCD functions. Now at this time you keep PB3 ZERO. So that output of EXOR gate follows the PB2 and LCD1 operates in normal fashion. Now whenever you want to write text on LCD2, simply make PB3 high and call usual LCD functions. These functions will make PB2 high, but since PB3 is also HIGH it will force result in ZERO at the output of EXOR gate and hence will disable the LCD1. Once you are done with displaying text on LCD2, again make PB3 ZERO to resume writing on LCD1.

      EXOR : 74HC86 > Quad two input EXOR gate.

      This is just a concept, I have not tested it. But I think it should work without any problem.

  11. nikhil

    found urs article intresting but can we use it in AVR studio,,,…….if not how it can b done in AVR using AVR studio software..

  12. pranav

    for the next article can u write about the the encoder-decoder circuit for micro-mouse …… which will help to calculate the turning of the bot…

    • m.mobini

      encoder.h for codvision