programing 8051 for GDM2004D LCD

Discussion in 'Embedded Systems and Microcontrollers' started by shadowwolf, Jan 14, 2013.

  1. shadowwolf

    Thread Starter New Member

    Jan 14, 2013
    3
    0
    I am using an 8051 to run a program to do 4 calculations and then display them. The program is in C and the LCD is a 20x4 GDM2004D. My questions is, if I say a number is to be stored as a word (example: speed = n*x) how do I display that number instead of the word speed. In the main program I have defined that speed is an unsigned int and the calculations are done in subroutines. I think I have a good understanding how to do the program for the LCD just not how to display the number values of the words.
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
  3. shadowwolf

    Thread Starter New Member

    Jan 14, 2013
    3
    0
    thank you for the reply, I got that part but before I can do that I need to get the number value that is being stored as a character, from the example; what is the number value of speed so that I can send that to the LCD instead of sending the word speed.
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I'm not quite sure what you mean... Are you saying you don't want to use a 16-bit representation? Or perhaps, you want the values stored in memory?

    Or is it that you are trying to use a 8-bit number to store the speed, despite the fact that you have it declared as an int...
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    First, see if your compiler package has a function named itoa() and seek it's details. It converts an integer to ASCII, or ItoA, get it? While it's not explicitly a part of the C standard oft times it is included as part of stdlib.h as it complements atoi() which *is* part of the standard.

    If you don't have it Google will be your friend and give you several code examples to follow.

    You also need to create a char buffer long enough to hold the number. When using LCD displays I make a global 21 character buffer to hold a custom line.

    Microchip's C18 has this function:
    Code ( (Unknown Language)):
    1. char * itoa( int value, char * string );
    So to call you just do this:

    Code ( (Unknown Language)):
    1. char LineBuffer[21];  // makes a place holder for a 20 character string (plus trailing zero)
    2.  
    3. void main(void)
    4. {
    5.     int MyInt = 1234;
    6.     ...
    7.     itoa(MyInt, &LineBuffer);
    8.     {call your print to LCD function with &LineBuffer here};
    9. }
    BTW, the printf() function will also do this, and it is standard, but it is a HUGE bit of code and should be avoided.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    I will assume that your question relates to a basic understanding of how computer programming, compilers and computers in general work.

    When you use a word such as "speed" in a computer program, "speed" is called a label or variable name, or simply a container for holding different kinds of objects.

    In your program you have defined "speed" to be unsigned int. In many computer languages this can mean a 16-bit value but this is not a rule. Sixteen bits can represent 65536 things, for example, 65536 different colors. It can also represent 65536 numeric values from 0 to 65535.

    What you are asking is how do you display 65536 numeric values as numerals from 0 to 65535?
    The answer is usually in a subroutine called "integer to ASCII" which is a standard programming exercise in an introductory level computer programming course.

    Let us take an example. Suppose we have a numeric value of 1234 stored as 16-bit unsigned int. We need an algorithm that converts a 16-bit value into four numerals "1", "2", "3" and "4".

    See if you can figure out the algorithm on your own.

    As Ernie says, you need to write your own itoa( ) function and not to rely on some prewritten library function that can be very inefficient.
     
  7. shadowwolf

    Thread Starter New Member

    Jan 14, 2013
    3
    0
    thank you everyone, the itoa() sounds like what i need and there was a lot of good answers for me.
     
Loading...