Maker Pro
Maker Pro

get value instead of ascii symbols

burassu

Jul 1, 2011
36
Joined
Jul 1, 2011
Messages
36
hi iam getting a value from the adc of the 8051 and i am trying to display it on the lcd , but the only thing displayed ,are symbols. How can I display that number since I have to compare it with other values .???


The following is what I am doing :

void Tsel(unsigned int value1) //Alg function.

{
unsigned int y; //character y.
unsigned int dec1,dec2,dec3; //character for decimal.


y=value1*100;
Delay(100); //Small delay.
LCD_Data(y); //Send data to LCD.

}
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,730
Joined
Nov 17, 2011
Messages
12,730
You have to convert the ADC data to the data format of the LCD.
The ADC most likely gives you binary data either as unsigned integer or as signed integer (two's complement). The LCD, on the other hand, either needs plain ASCII or an index to the internal character ROM (which one depends on the Type of LCD you use).

So in pseudocode what you should do is:

Y = get_ADC_data
Z= convert_to_LCD_data (Y)
Send_LCD_data(Z)

Note that a single ADC word will generally require more than one LCD datum.
E.g. if you have an ADC delivering unsigned 8 bit data, the equivalent decimal range is 0...255. Therefore you convert 8 ADC bits to 3 decimal digits. So you not only have to convert the binary to decimal but for displaying the decimal data you have to take care of the position of the characters, too (unless the LCD has an auto cursor increment feature). Otherwise you would write the decimal characters on top of each other, thereby erasing the previosuly written character.

Harald
 

burassu

Jul 1, 2011
36
Joined
Jul 1, 2011
Messages
36
data from the adc is already collected

I modified my code , when I displayed seltempdec[0] and selecttempdec[1] the respective values were seen on the lcd , but when I am adding the values to get a whole number the ascii are being displayed . the data is already being collected from the adc .


void Tsel(unsigned int value1) //Alg function.

{ //
unsigned int y; //character x.
unsigned int dec1,dec2,dec3; //character for decimal.

//
y=value1/10; //divide value by 10.
dec1=value1%10; //place value for decimal 1.
dec2=y%10; //
dec3=y/10; //
seltempdec[0]=dec1|0x30; //OR units.
seltempdec[1]=dec2|0x30; //OR tens.

temperatureselect= ((seltempdec[0])+(seltempdec[1]*10)+(seltempdec[2]*100)) ;
LCD_Data(temperatureselect);
}
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,730
Joined
Nov 17, 2011
Messages
12,730
This is not what I meant to express. You should send each digit separately to the LCD, like this:

Y=get_ADC_value
dec1=...
dec2=...
dec3=...
LCD_position_cursor(pos100) //place text cursor at the leftmost position of displaytext //
LCD_Data(dec1)
LCD_position_cursor(pos10) // place text cursor at middle position of displaytext //
LCD_Data(dec2)
LCD_position_cursor(pos1) // place text cursor at the rightmost position of displaytext //
LCD_Data(dec3)

Just as you would jot down a 3 digit number manually...


Harald
 

burassu

Jul 1, 2011
36
Joined
Jul 1, 2011
Messages
36
I dont think we are understanding each other , sry if I am not explaining my self well . I did that already but , now I need to make that number as awhole number for example if dec1 3 and dec 2 is 4 I need a result to be equal to 34. so thats why i added this line ----> temperatureselect= ((seltempdec[0])+(seltempdec[1]*10)+(seltempdec[2]*100)) ;

but the problem is that when i am displaying temperaturselect the answer is in ascii .
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,730
Joined
Nov 17, 2011
Messages
12,730
Let me try to explain it another way:
LCDs, as far as i know them, display data according to what is stored in an internal display memory. Usually each digit of an LCD corresponds to a unique memory address in the LCD's memory.
If, for example, you have a 2*8 LCD, the memory layout might be:
address character-row character-column
00 1 1 //top left
01 1 2
02 1 3
03 1 4
04 1 5
05 1 6
06 1 7
07 1 8 // top right
08 2 1 // bottom left
etc...
(the exact memory layout depends on the size of the LCD and the type of controller -> datasheet.)

So in order to display a 3 digit decimal number, you need to address 3 memory addresses (also called cursor positions) within the LCD. Assume you want to write the 3 digit number to the top right position, then the memory addresses (in above memory layout) are:
address 04 = digit 1 (100s)
address 05 = digit 2 (10s)
address 06 = digit 3 (1s)
At any time you can write only 1 digit. Adding or Oring digits into one word doesn't help.
Before you write a digit you may need to convert it to the LCDs coding. If, for example, the LCD uses ASCII code, then a decimal "0" becomes ASCII 30, "1" becomes "31" and so on. So adding 30 to the decimal value results in the correct ASCII value. Again, the datasheet of the LCD should tell you which code to use.

Harald
 

burassu

Jul 1, 2011
36
Joined
Jul 1, 2011
Messages
36
so

ohhh so I never can display whole number all at ones. but i can continue using that adition to compare its value to another one , but still i need to send the result one by one . Right ??

Let me try to explain it another way:
LCDs, as far as i know them, display data according to what is stored in an internal display memory. Usually each digit of an LCD corresponds to a unique memory address in the LCD's memory.
If, for example, you have a 2*8 LCD, the memory layout might be:
address character-row character-column
00 1 1 //top left
01 1 2
02 1 3
03 1 4
04 1 5
05 1 6
06 1 7
07 1 8 // top right
08 2 1 // bottom left
etc...
(the exact memory layout depends on the size of the LCD and the type of controller -> datasheet.)

So in order to display a 3 digit decimal number, you need to address 3 memory addresses (also called cursor positions) within the LCD. Assume you want to write the 3 digit number to the top right position, then the memory addresses (in above memory layout) are:
address 04 = digit 1 (100s)
address 05 = digit 2 (10s)
address 06 = digit 3 (1s)
At any time you can write only 1 digit. Adding or Oring digits into one word doesn't help.
Before you write a digit you may need to convert it to the LCDs coding. If, for example, the LCD uses ASCII code, then a decimal "0" becomes ASCII 30, "1" becomes "31" and so on. So adding 30 to the decimal value results in the correct ASCII value. Again, the datasheet of the LCD should tell you which code to use.

Harald
 
Top