Varible to String conversion....

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok... I've have a great few days...

I've written code to

read My SPI 12bit ADC
output to me 12bit DAC
Write and draw on my GLCD
Write to me LCD
and generaly doing the background work for my projects...

Now i've hit a wall... I can diplay a string on the LCD's but how to i convert a Number varible to a String..

:oops:

any ideas....

Thanx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In what language?

In 'c' you can try printf/sprintf,itoa........

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Opps ..

I'm using AVR-Studio 4 in C code.. WinAVR-20080610.

Are any of these commands part of GCC?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

after searching my HD for all files with itoa in then, i think i've found a new favorate libary 8-)

now how do i use it right....

	long string;
	itoa(i,string,10);
	GLCD_WriteString(string);

I think i'm missing how to define a string varible... this code gives me the right values upto 9 then it goes funny 8-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Patchlead wrote:
after searching my HD for all files with itoa in then, i think i've found a new favorate libary 8-)

now how do i use it right....

	long string;
	itoa(i,string,10);
	GLCD_WriteString(string);

I think i'm missing how to define a string varible... this code gives me the right values upto 9 then it goes funny 8-)


1st: use Help | avr-libc Reference manual in Winavr,
2nd:

uint8_t string[MAX_DIGITS+1];


And please pay attention to all the compiler warnings you must have got with your code.

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thankyou Martin, i do watch the warnings in the compiler..

Quote:

../main.c:25: warning: passing argument 2 of 'itoa' makes pointer from integer without a cast

but, at this stage in my C coding levels, it is not real helpfull for me...
Quote:
uint8_t string[10];
GLCD_WriteString(itoa(i,string,10));

that works great 8-)

What syntex coloring does AVR Studio 4 use?? i normaly get a blue color for varible types.. int long char etc... but uint8_t does not stike up anything (but will compile)

Is uint8_t part of C or is that branching into C++.. i only ask due to my frustration in tring to get a kind of coding that works for me.. There seems to be endless syntex that works with this compiler .. and working out one from another is interesting

Is there a varible declare for a 10 charactor string that Studio will showup as blue? Or we on our own 8-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try:

char string[10];

This is more idiomatic C code, and will show up with your syntax highlighter.

Incidentally, if you plan to continue with AVR stuff, I would highly recommend picking up a book on C. The questions you're asking here would be covered in the first few chapters of any C book.

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Are any of these commands part of GCC?

You really need to get a good C textbook or two. One should probably be written by Kernighan & Ritchie.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
One should probably be written by Kernighan & Ritchie.
...3rd edition as 2nd edition does not cover the best addition to the C language, specific variable size. :?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is uint8_t part of C or is that branching into C++.. i only ask due to my frustration in tring to get a kind of coding that works for me.. There seems to be endless syntex that works with this compiler .. and working out one from another is interesting

uint8_t is a typedef and not a C variable type so the IDE will not 'color' it. A lot of IDE's let you add your own keywords though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all... yes i do need work .. i've been tinkering for a while now.. and i've decided to get real with my efforts..

I'll track down that Book.. and read better through the help file... - is there a copy of that file that i can search? The help is great if you know what command you wand but it requires you to look at every commanf if do not have a name...

is it too much to ask whats the difference between a Typedef and a varible type? On the surface they seem to do the same thing ... Are they the same just a different naming format?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The C language has built in variable types (char, int, float, etc). The 'typedef' term allows you to define your own variable types. C++ goes one step further and allows you to define operator behavior so that your defined types can use them (e.g. so you can write C = A + B; where A, B and C are of a type that you defined).

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

is there a copy of that file that i can search?

If we're talking about the avr-libc documantation then there is a PDF available.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]