PIC16f877- 16 bit hex to bcd converter

Discussion in 'Embedded Systems and Microcontrollers' started by amitesh, Mar 1, 2009.

  1. amitesh

    Thread Starter New Member

    Mar 1, 2009
    Hi all,
    im a newbie here, so please excuse me if this question's already been asked.

    As part of my current project, im trying to display a 16 bit counter value on to the LCD. It has to be converted from hex to BCD , n then to ascii (obviously) before sending to LCD. I know there are two ways to write it- using Embedded C or ASM. my questions are:
    1) could anyone tell me if there is going to be a huge difference in the code length between the two methods?
    2) I have just started working on a ASM approach which seems to be quite lengthy. But i don't mind doing it, as long as it'll reduce my end HEX-file's (the one to burn on chip) size. Anyone know about this?
    3) If any of you have already done this, could you please help me out with the principle or pass me your code?

    NOTE: I have taken care of the ascii part. I have also written a program to convert from 16 bit hex to unpacked BCD. This isn't what i want. Im looking to convert 16bit hex to packed BCD(so that i can send it to the ascii routine to display on the LCD).

    Cheerio! :)
  2. russ_hensel

    Distinguished Member

    Jan 11, 2009
    Every thing is shorter in C.

    You do not need to convert to hex, the data in the pic is in binary.

    You probably do not need to convert to BCD ( at least you have not said why )

    So you need to convert from binary to ascii.

    Many c compilers have built in functions for this, else google should easliy find you an algorithm.