This is a rough copy of something that I will, maybe, if I get the chance... (excuses, excuses)... make more "reader friendly" one day. In the meantime, there is useful information here!
In some lines of microcontroller work, you need to work with the individual binary digits, ("bits"... get it?.... binay digits)) of some of the numbers stored in your machine.
Don't get hung up on the "is it in binary? decimal? ASCII?" thing... every number is all three. "Dozen" and "twelve" are still 12.
In my tutorials, I take a very crude, but, I hope, transparent approach.
Bill O'Neill, of Aztec MCU Prototyping kindly wrote in, giving some more elegant answers. I reproduce his email below. Aztec have a number of useful modules, and, for a fee, can do design consulting.
Hi Tom, In your code (in several places I think) you do something like this: //The code is CRUDE... but it works! //I won't be offended if someone writes me // to tell me the right way to do this, // as long as the right way is transparent // for newbies. temp_string[0]=32; temp_string[1]=32; temp_string[2]=32; temp_string[3]=32; temp_string[4]=48; temp_string[5]=0; if (iClicks>9999) {iTmp=(iClicks / 10000) % 10; temp_string[0]=48+iTmp;}; if (iClicks>999) {iTmp=(iClicks / 1000) % 10; temp_string[1]=48+iTmp;}; if (iClicks>99) {iTmp=(iClicks / 100) % 10; temp_string[2]=48+iTmp;}; if (iClicks>9) {iTmp=(iClicks / 10) % 10; temp_string[3]=48+iTmp;}; if (iClicks>0) {iTmp=iClicks % 10; temp_string[4]=48+iTmp;}; //End of "put a number in the output buffer" i=0; while (temp_string[i]) { buf[TCP_CHECKSUM_L_P+3+plen]=temp_string[i++]; plen++; } === All of that can be replaced with the following two lines.... itoa(iClicks, temp_string, 10); //This is C's standard integer to ASCII conversion function plen=es.ES_fill_tcp_data(buf,plen,temp_string); //No need to iterate through the temp_string. // itoa will append a null which will be interpreted // correctly by the ES_fill_tcp_data function.
If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.
Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages.
Click here to visit the homepage of my biggest site.
Click here to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmAht" I added to that link causes your browser problems. Please let me know, if so?
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes. There were two "unknown attributes" in Google+ button code. Sigh.
....... P a g e . . . E n d s .....