Reading ADR register in Motorola HC08 processor

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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
(http://www.freescale.com/files/microcontrollers/doc/app_note/AN2984.pdf).
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


Re: Reading ADR register in Motorola HC08 processor

Quoted text here. Click to load it

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.


Re: Reading ADR register in Motorola HC08 processor
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

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 ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline