Byte to ASCII Conversion

Thread Starter

farcane

Joined Mar 7, 2017
3
Hello,

I am working on a project, it consists of transfering an 8-bit ADC converter "AD9057" digital output data to an ATmega16 microcontroller using normal wires " outputs of ADC to inputs (PortA from PA0 to PA7) of Atmega16 ", and I want to get my data from the Atmega 16 in ASCII form on the Terminal " Termite Terminal", since I don t have much experience with programming microcontrollers, I just need a global idea or a sample C language code of what should I initialize, and how can this be done.



regards
farcane
 

MrChips

Joined Oct 2, 2009
30,824
This is fundamental to all computer systems and requires a basic knowledge of the meaning of binary vs ASCII.
Why this presents a stumbling block to so many, I do not know. However it is well worth your time and effort to fully understand this.

All computer data is binary. ASCII is binary. Text is binary. Hex is binary. Decimal numbers are binary numbers.

Your 8-bit ADC produces an 8-bit value, i.e. one byte.
The most efficient way to transmit the data is to send it as is, un-encoded. You don't have to do anything.

Ok, if you prefer, you may want to display the data on a text screen.

You choose how you want the data displayed.
For example, suppose the 8-bit data is 10011010.
Which of the following do you want to see on the screen?

10011010
9A
154
-102

or an infinite number of ways of showing the same data.

Once you decide how you wish the data to be represented, you create an algorithm to go from the 8-bit binary data to a sequence of ASCII characters which is simply a sequence of 8-bit binary values.

Where you do the encoding is up to you. You can encode the data before transmitting or you can encode the data after it has been received.
 

spinnaker

Joined Oct 29, 2009
7,830
I would think your compiler has an sprintf function that would be the easiest way to go

char buffer[25];
int x = 12345;

sprintf(buffer, "X=%d",x);

// Output buffer to the terminal.

Your compiler might even have a printf function that sends direct to the terminal.


Check your compiler's documentation.
 

joeyd999

Joined Jun 6, 2011
5,287
The easy way (unfortunately, expands to a lot of code):

sprintf(buffer,"%d",code); //decimal representation

sprintf(buffer,"%X",code); //hex representation

spinnaker beat me to it.
 
Top