BCD conversion


Closed Thread
Results 1 to 10 of 10

Thread: BCD conversion

  1. #1
    Macgman2000's Avatar
    Macgman2000 Guest

    Question BCD conversion

    Hello All,

    I have 3 bytes that represent a value 122880 . The problem is that the 3bytes are backwards in bit order.......

    regular binary 122880 = (msb) 00000001 11100000 00000000

    My buffer reads 122880 = (lsb) 00000000 00000111 10000000

    How do I take the 3bytes that are backwards in bit order and convert it to BCD or to something I can throw up on an LCD.

    Best Regards,
    Nick

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's sounds familiar...
    http://www.picbasic.co.uk/forum/show...=reverse+order

    regular binary 122880 = (msb) 00000001 11100000 00000000

    My buffer reads 122880 = (lsb) 00000000 00000111 10000000
    How do you get those bytes??? let's say by serial com... why not... it's possible
    Code:
    b0 var byte
    b1 var byte
    b2 var byte
    w1 var byte
    w0 var word
    
    hserin [b0,b1,b2]
    w1=b2 rev 8
    w0.highbyte=b1 rev 8
    w0.lowbyte=b0 rev 8
    hserout [bin8 w1,bin16 w0]
    now i leave you with the pleasure of doing some math and use modifiers like DEC, DIG and all the others.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Just curious. If you're shifting in data LSB first, and this results in your data
    being backwards, what happens if you shift in your data MSB first?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i had this idea... but since we don't know how and where it come from...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Bruce & Steve,

    I guess Nick is receiving the bits from an external Master talking:
    "Chinese Protocol"

    See here for reference
    Last edited by NavMicroSystems; - 1st August 2005 at 22:06.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Nick,

    how are you getting on with the project?
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  7. #7
    Macgman2000's Avatar
    Macgman2000 Guest


    Did you find this post helpful? Yes | No

    Smile

    Hello All,

    I have the hardware set up using an LM393 (0v to -1.55v) to shift to standard TTL/CMOS. I am able to see the data by setting the calipers to 1" and analyzing the waveform to get 20480 (which is the resolution per inch) . It is being clocked out LSB to MSB. I have the PIC packing 3bytes but like I said it is backwards.

    I have most of the supporting readout code done and tested with dummy variables. The only thing holding me up is flipping the data around and scaling it (scaling factor already worked out). I will fiddle around with your suggestion.

    Thanks again!!!

    Best Regards,
    Nick

  8. #8
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Nick, here is a ready to run Code Snippet that does the conversion:

    Code:
    InBuffer VAR BYTE[3]
    CounterA VAR BYTE
    
    Main:
    
    ' Bits are shifted into an Array of Byte (InBuffer) here (LSB first)
    '  
    ' Place your Code to shift the bits in here...
    
    
     FOR CounterA = 0 TO 2
            
         'Revert the Bit order
         InBuffer[CounterA] = Inbuffer[CounterA] REV 8
    
         'Invert captured Data (if not required comment this line out)
         InBuffer[CounterA] = InBuffer[CounterA]^$FF
     
     NEXT CounterA
    
     'Output Raw Data to LCD (24 Bits, MSB first)
      LCDOUT BIN8 InBuffer[2],Bin8 InBuffer[1],Bin8 InBuffer[0]
     
    GOTO Main
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  9. #9
    Macgman2000's Avatar
    Macgman2000 Guest


    Did you find this post helpful? Yes | No

    Smile

    Thanks Ralph !!!! I will try it out this week.....geez, right now I have an urgent request for a speed controller FETs'n all ....hehehe.

    Best Regards,
    Nick

  10. #10
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Hi Nick,

    RE: your PM

    I haven't found time yet to work on this project.

    It certailny is possible in PBP,
    a 70-90 kHz clock is not that fast, so a tight loop could do.

    Another option is to use the MSSP Module.

    I'll have a look into it when I find time.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. Rotary BCD
    By Tobias in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 03:04
  4. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 01:35
  5. HEX to BCD conversion
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd February 2005, 14:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts