Displaying 8051 counter on LCD

Discussion in 'Embedded Systems and Microcontrollers' started by Dritech, Apr 18, 2015.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi all,

    I am using timer 1 as a counter in mode 2. After reading the value in TL1 , I need to do same calculations which will be stored in an integer.
    After the calculation is done, I am trying to display the result on an LCD. Now my problem is that I cannot display the result using the integer variable directly since the LCD function accepts strings.
    Is there a way to convert the value stored in the integer to a string please?

    Any kind of help would be appreciated.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,429
    3,360
    This is a classic early exercise in any introductory course on microcontroller programming.
    Are you coding in ASM or C?

    Be informed that the LCD itself does not accept strings. The input to the LCD is single 8-bit characters encoded in ASCII.
     
  3. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    I am using C as the programming language.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,429
    3,360
    So you can either do it the easy way by using a library function such as sprintf( )

    or you can do it the easier way by writing your own function to take a binary integer and stripping it down to its coefficients of power's of ten (which is dead easy to do).
     
Loading...