1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Reading ADR register in Motorola HC08 processor

Discussion in 'Embedded' started by Aria, Aug 10, 2005.

  1. Aria

    Aria Guest

    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
     
    Aria, Aug 10, 2005
    #1
    1. Advertisements

  2. Aria

    Lanarcam Guest

    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.
     
    Lanarcam, Aug 10, 2005
    #2
    1. Advertisements

  3. Aria

    CBFalconer Guest

    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.
     
    CBFalconer, Aug 10, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.