I need to convert 6-digit BCD to binary PICmicro

Discussion in 'Programmer's Corner' started by atferrari, Oct 5, 2004.

  1. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    All what I could find was conversion from 5-digits BCD to binary.

    My maximum value (decimal) is 500000 (5E5) that is 6 digits.

    No PIC list seems to have code for that.

    Any help, anyone?

    Gracias

    Agustín Tomás
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Hi,

    Sounds like a number too large to fit the register length on a PIC. With 16 bits, the maximum value is 32768.

    See if you can find a floating-point conversion routine for the PIC. That will let you compress the 6-digit decimal number into something the PIC can handle. Or so I hope - the number may still not go because it exceeds any register length that can do the floating-point conversion.
     
  3. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    6-digit BCD to three 8-bit bytes that is 24 bits. That's my intention. Don't worry if solution looks too much. If it works, it's OK for me.

    Thanks for replying!!

    Agustín Tomás
     
  4. cyberhehe

    Well-Known Member

    Oct 6, 2004
    61
    0

    Will you tell me how you want your 6-digit BCD Data organized, i.e. each digit is placed into an 8-bit variable (which then consist of 6 Variables) where the LSByte points to the lower address, and MSB to the higher address). Also tell me how your result variables will be organized.
     
  5. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    Every BCD digit in one separate byte.

    CMIL >> MSD
    DMIL
    UMIL
    CENT
    DECE
    UNIT >> LSD

    In three bytes, that is a 24-bits binary:

    NROBIN_H
    NROBIN_M
    NROBIN_L

    For these three, order is not relevant at all.

    Thanks for your time and your help.

    Agustín Tomás
     
Loading...