Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

New!

Thinking MCU? Think TI
Visit the new
TI MCU resource center for the latest videos and documents to help support your design efforts.

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | Problem to display integer on LCD


Advertise Here

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

Problem to display integer on LCD - folg...@yahoo.com - Jan 3 14:10:51 2009

Hello, I have a problem to display an integer on a LCD. I convert the integer into a string. However, this apparently does not seem to work. The values are not displayed properly. Sometimes the value is shon rigt, sometimes any other characters are shown and sometimes the programm stops durig the conversion from int into a string.

The Integer takes values from 0 to 255.

Maybe somebody can help me and find the mistake(s).
Best regards
void LCDOutc(unsigned char str)
{
switch (str)
{
case 'ä':
str = 0xE1;
break;
case 'ö':
str = 0xEF;
break;
case 'ü':
str = 0xF5;
break;
case 'ß':
str = 0xE2;
break;
case '°':
str = 0xDF;
break;
case 'µ':
str = 0xE4;
break;
}
PORTA=str;
PORTK|=0x05;
PORTK&=~0x02;
LCDClock();
chars++;
if(chars==20)
{
if(row==1)
{
SecondLine();
}
if(row==2)
{
ThirdLine();
}
if(row==3)
{
FourthLine();
}
if(row==4)
{
LCDHome();
}
}/* if(chars==20) */
}/* void LCDOutc(char str) */

//++++++++++++

void LCDOuts(unsigned char* str)
{
while (*str != 0) {LCDOutc(*str++);}
}/* void LCDOuts(char* str) */

//++++++++++++

void IntToString(unsigned char* str, int value, char precomma, char aftercomma)
{
int k, i, digit, multiplier, j=0;
for (i=0;i {
multiplier=1;
for (k=0;k digit = value / multiplier;
value %= multiplier;
str[j++] = digit + 48;
}
if (aftercomma) str[j++] = '.';
for (i=0;i {
multiplier=1;
for (k=0;k digit = value / multiplier;
value %= multiplier;
str[j++] = digit + 48;
}
}

//++++++++++++

void LCDOut_PotiValue(int Value)
{
unsigned char* ausgstr;
LCDHome();
LCDOuts(" Wert: ");
IntToString(ausgstr, Value, 3, 0);
LCDOuts(ausgstr);
SpaceOut(4);
}/* void LCDOut_PotiValue(char value) */
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: Problem to display integer on LCD - vkke...@comcast.net - Jan 3 14:19:53 2009



I believe you're suppose to have a default in the case statement.=20

vkk=20
----- Original Message -----=20
From: f...@yahoo.com=20
To: 6...@yahoogroups.com=20
Sent: Saturday, January 3, 2009 2:10:42 PM GMT -05:00 US/Canada Eastern=20
Subject: [68HC12] Problem to display integer on LCD=20

Hello, I have a problem to display an integer on a LCD. I convert the integ=
er into a string. However, this apparently does not seem to work. The value=
s are not displayed properly. Sometimes the value is shon rigt, sometimes a=
ny other characters are shown and sometimes the programm stops durig the co=
nversion from int into a string.=20

The Integer takes values from 0 to 255.=20

Maybe somebody can help me and find the mistake(s).=20
Best regards=20
void LCDOutc(unsigned char str)=20
{=20
=C2=A0=C2=A0switch (str) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=20
=C2=A0=C2=A0{ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0case '=C3=A4':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xE1;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C3=B6':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xEF;=20
=C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A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0if(chars=3D=3D20)=20
=C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D1)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0SecondLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D2)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0ThirdLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D3)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0FourthLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D4)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0LCDHome(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0} =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0}/* if(chars=3D=3D20) */ =C2=A0=20
}/* void LCDOutc(char str) */=20

//++++++++++++=20

void LCDOuts(unsigned char* str)=20
{=20
=C2=A0=C2=A0while (*str !=3D 0) {LCDOutc(*str++);}=20
}/* void LCDOuts(char* str) */=20

//++++++++++++=20

void IntToString(unsigned char* str, int value, char precomma, char afterco=
mma)=20
{=20
=C2=A0=C2=A0int k, i, digit, multiplier, j=3D0;=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k 10;=20
=C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
=C2=A0=C2=A0if (aftercomma) str[j++] =3D '.';=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k =C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
}=20

//++++++++++++=20

void LCDOut_PotiValue(int Value)=20
{=20
=C2=A0=C2=A0 =C2=A0unsigned char* ausgstr;=20
=C2=A0=C2=A0 =C2=A0LCDHome(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0LCDOuts(" =C2=A0 Wert: "); =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0IntToString(ausgstr, Value, 3, 0);=20
=C2=A0=C2=A0 =C2=A0LCDOuts(ausgstr); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0SpaceOut(4); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
}/* void LCDOut_PotiValue(char value) */=20
------------------------------------=20



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Problem to display integer on LCD - Lennart Lindell - Jan 3 14:46:16 2009

Hi,
I can see two things that are wrong.
1. At end in IntToString (add termination of string):
str[j] = 0;
2. Change declaration of ausgstr in LCDOut_PotiValue to (declare a memory area instead of a pointer):
unsigned char ausgstr[8];
f...@yahoo.com wrote:
> Hello, I have a problem to display an integer on a LCD. I convert the integer into a string. However, this apparently does not seem to work. The values are not displayed properly. Sometimes the value is shon rigt, sometimes any other characters are shown and sometimes the programm stops durig the conversion from int into a string.
>
> The Integer takes values from 0 to 255.
>
> Maybe somebody can help me and find the mistake(s).
> Best regards
> void LCDOutc(unsigned char str)
> {
> switch (str)
> {
> case 'ä':
> str = 0xE1;
> break;
> case 'ö':
> str = 0xEF;
> break;
> case 'ü':
> str = 0xF5;
> break;
> case 'ß':
> str = 0xE2;
> break;
> case '°':
> str = 0xDF;
> break;
> case 'µ':
> str = 0xE4;
> break;
> }
> PORTA=str;
> PORTK|=0x05;
> PORTK&=~0x02;
> LCDClock();
> chars++;
> if(chars==20)
> {
> if(row==1)
> {
> SecondLine();
> }
> if(row==2)
> {
> ThirdLine();
> }
> if(row==3)
> {
> FourthLine();
> }
> if(row==4)
> {
> LCDHome();
> }
> }/* if(chars==20) */
> }/* void LCDOutc(char str) */
>
> //++++++++++++
>
> void LCDOuts(unsigned char* str)
> {
> while (*str != 0) {LCDOutc(*str++);}
> }/* void LCDOuts(char* str) */
>
> //++++++++++++
>
> void IntToString(unsigned char* str, int value, char precomma, char aftercomma)
> {
> int k, i, digit, multiplier, j=0;
> for (i=0;i > {
> multiplier=1;
> for (k=0;k > digit = value / multiplier;
> value %= multiplier;
> str[j++] = digit + 48;
> }
> if (aftercomma) str[j++] = '.';
> for (i=0;i > {
> multiplier=1;
> for (k=0;k > digit = value / multiplier;
> value %= multiplier;
> str[j++] = digit + 48;
> }
> }
>
> //++++++++++++
>
> void LCDOut_PotiValue(int Value)
> {
> unsigned char* ausgstr;
> LCDHome();
> LCDOuts(" Wert: ");
> IntToString(ausgstr, Value, 3, 0);
> LCDOuts(ausgstr);
> SpaceOut(4);
> }/* void LCDOut_PotiValue(char value) */
> ------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Problem to display integer on LCD - vkke...@comcast.net - Jan 3 14:57:59 2009



Your 'for' loop is messed up, you need a ')' closing parenthesis.=20

=C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k =C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
----- Original Message -----=20
From: f...@yahoo.com=20
To: 6...@yahoogroups.com=20
Sent: Saturday, January 3, 2009 2:10:42 PM GMT -05:00 US/Canada Eastern=20
Subject: [68HC12] Problem to display integer on LCD=20

Hello, I have a problem to display an integer on a LCD. I convert the integ=
er into a string. However, this apparently does not seem to work. The value=
s are not displayed properly. Sometimes the value is shon rigt, sometimes a=
ny other characters are shown and sometimes the programm stops durig the co=
nversion from int into a string.=20

The Integer takes values from 0 to 255.=20

Maybe somebody can help me and find the mistake(s).=20
Best regards=20
void LCDOutc(unsigned char str)=20
{=20
=C2=A0=C2=A0switch (str) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=20
=C2=A0=C2=A0{ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0case '=C3=A4':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xE1;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C3=B6':=20
=C2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=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0if(chars=3D=3D20)=20
=C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D1)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0SecondLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D2)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0ThirdLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D3)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0FourthLine(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=20
=C2=A0=C2=A0 =C2=A0}=20
=C2=A0=C2=A0 =C2=A0if(row=3D=3D4)=20
=C2=A0=C2=A0 =C2=A0{=20
=C2=A0=C2=A0 =C2=A0 =C2=A0LCDHome(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0} =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0}/* if(chars=3D=3D20) */ =C2=A0=20
}/* void LCDOutc(char str) */=20

//++++++++++++=20

void LCDOuts(unsigned char* str)=20
{=20
=C2=A0=C2=A0while (*str !=3D 0) {LCDOutc(*str++);}=20
}/* void LCDOuts(char* str) */=20

//++++++++++++=20

void IntToString(unsigned char* str, int value, char precomma, char afterco=
mma)=20
{=20
=C2=A0=C2=A0int k, i, digit, multiplier, j=3D0;=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k 10;=20
=C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
=C2=A0=C2=A0if (aftercomma) str[j++] =3D '.';=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k =C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
}=20

//++++++++++++=20

void LCDOut_PotiValue(int Value)=20
{=20
=C2=A0=C2=A0 =C2=A0unsigned char* ausgstr;=20
=C2=A0=C2=A0 =C2=A0LCDHome(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0LCDOuts(" =C2=A0 Wert: "); =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0IntToString(ausgstr, Value, 3, 0);=20
=C2=A0=C2=A0 =C2=A0LCDOuts(ausgstr); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0SpaceOut(4); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
}/* void LCDOut_PotiValue(char value) */=20
------------------------------------=20

______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Problem to display integer on LCD - folg...@yahoo.com - Jan 3 14:58:52 2009

Hello, I am using this code on an MSP430 (Texas Instruments). On the MSP430 it works fine. I am able to display integers an a LCD. The Same code. I carried the code from the MSP to the HCS12. I wonder why the code on the HCS12 does not work.

------------------------------------

______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Problem to display integer on LCD - vkke...@comcast.net - Jan 3 14:59:41 2009



Your 'for' loop is messed up and when you add the closing parenthesis, ')',=
get rid of the ';' semicolon=20

=C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k =C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
----- Original Message -----=20
From: f...@yahoo.com=20
To: 6...@yahoogroups.com=20
Sent: Saturday, January 3, 2009 2:10:42 PM GMT -05:00 US/Canada Eastern=20
Subject: [68HC12] Problem to display integer on LCD=20

Hello, I have a problem to display an integer on a LCD. I convert the integ=
er into a string. However, this apparently does not seem to work. The value=
s are not displayed properly. Sometimes the value is shon rigt, sometimes a=
ny other characters are shown and sometimes the programm stops durig the co=
nversion from int into a string.=20

The Integer takes values from 0 to 255.=20

Maybe somebody can help me and find the mistake(s).=20
Best regards=20
void LCDOutc(unsigned char str)=20
{=20
=C2=A0=C2=A0switch (str) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=20
=C2=A0=C2=A0{ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0case '=C3=A4':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xE1;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C3=B6':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xEF;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C3=BC':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xF5;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C3=9F':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xE2;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C2=B0':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xDF;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0 =C2=A0case '=C2=B5':=20
=C2=A0=C2=A0 =C2=A0 =C2=A0str =3D 0xE4;=20
=C2=A0=C2=A0 =C2=A0 =C2=A0break;=20
=C2=A0=C2=A0} =C2=A0=20
=C2=A0=C2=A0PORTA=3Dstr; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0PORTK|=3D0x05; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0PORTK&=3D~0x02; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C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=A0=C2=A0}/* if(chars=3D=3D20) */ =C2=A0=20
}/* void LCDOutc(char str) */=20

//++++++++++++=20

void LCDOuts(unsigned char* str)=20
{=20
=C2=A0=C2=A0while (*str !=3D 0) {LCDOutc(*str++);}=20
}/* void LCDOuts(char* str) */=20

//++++++++++++=20

void IntToString(unsigned char* str, int value, char precomma, char afterco=
mma)=20
{=20
=C2=A0=C2=A0int k, i, digit, multiplier, j=3D0;=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k 10;=20
=C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
=C2=A0=C2=A0if (aftercomma) str[j++] =3D '.';=20
=C2=A0=C2=A0for (i=3D0;i =C2=A0=C2=A0{=20
=C2=A0=C2=A0 =C2=A0multiplier=3D1;=20
=C2=A0=C2=A0 =C2=A0for (k=3D0;k =C2=A0=C2=A0 =C2=A0digit =3D value / multiplier;=20
=C2=A0=C2=A0 =C2=A0value %=3D multiplier;=20
=C2=A0=C2=A0 =C2=A0str[j++] =3D digit + 48;=20
=C2=A0=C2=A0}=20
}=20

//++++++++++++=20

void LCDOut_PotiValue(int Value)=20
{=20
=C2=A0=C2=A0 =C2=A0unsigned char* ausgstr;=20
=C2=A0=C2=A0 =C2=A0LCDHome(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0LCDOuts(" =C2=A0 Wert: "); =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0IntToString(ausgstr, Value, 3, 0);=20
=C2=A0=C2=A0 =C2=A0LCDOuts(ausgstr); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0=20
=C2=A0=C2=A0 =C2=A0SpaceOut(4); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20
}/* void LCDOut_PotiValue(char value) */=20
------------------------------------=20

______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Problem to display integer on LCD - folg...@yahoo.com - Jan 4 7:52:18 2009

Hello,

thank you very much for your help. It works fine now. I had to add termination of string and I declared a memory area instead of a pointer.

Best regards

>Hi,
>I can see two things that are wrong.
>1. At end in IntToString (add termination of string):
>str[j] = 0;
>2. Change declaration of ausgstr in LCDOut_PotiValue to (declare a memory >area instead of a pointer):
>unsigned char ausgstr[8];

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )