Reading ADR register in Motorola HC08 processor

Hi,

I am new to programming MCUs and am trying to program my MC68HC098QY4 using CodeWarrior.

In my program I am incorporating the analog-digital convertor and I have a question regarding the nature of its output in the ADR register.

Currently what I am doing is assigning the value of the ADR to an integer as such:

int adrval; adrval = ADR;

from the datasheets, I see that if the input to the ADC (analog digital convertor) is equal to Vss of the MCU, then the output is $00 and if it's equal to Vdd then the output is $FF so using my integer approach, does that mean that the output will be a linear distribution between 0 and 255 (decimal equivalent of hex FF) with no offsets?

I was browsing through the Freescale documentations and found one for program the ADC at

formatting link
Now in this document, on page 5, it puts the result of the ADR into a char variable as such:

unsigned char result; result = ADR;

so is the result now put into a character array with 8 elements (0 to

7)? If so, do I now have to manually convert the 8 elements (each being either 0 or 1) to an integer?

I am a little confused between which approach to take. Can you please clarify my questions.

Thanks in advance, Aria Kashefi

Reply to
Aria
Loading thread data ...

A char is nothing more than an *integer* expressed on 8 bits so the range is 0 .. 255 or 0 .. FF in hexadecimal.

Since the output of the ADC is 0 .. FF it can fit in a char. You can do arithmetic with a char in the same way as with an integer. It is unsigned since the value is always positive.

Reply to
Lanarcam

... snip ...

Whether a char is signed or unsigned depends on the implementation. Since it can be either, you must specifically cast (or define) the incoming data as being unsigned char if that is what you want.

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
     USE worldnet address!
Reply to
CBFalconer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.