Need help converting a 4 bit binary number to 4 separate values


Results 1 to 4 of 4

Threaded View

  1. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need help converting a 4 bit binary number to 4 separate values

    This is working, not very elegant but, hey, its working.

    Now to figure out how to do it for 8 bits by dividing the "Counter" down to get the second upper 4 bits.

    Code:
    '=========================================================================
    '=======  SubRoutine to write to the 7 Seg Binary display   ==========
    '=========================================================================
    Binary:
    for z=0 to 3   'character position
        lookup z,[0,2,6,8],chrpos    ' value used to tell the I2C display which digit
        SELECT CASE counter
            case 0 :LOOKUP z, [$3f,$3f,$3f,$3f], chrdsp  '0000
            Case 1 :LOOKUP z, [$3f,$3f,$3f,$06], chrdsp  '0001
            Case 2 :LOOKUP z, [$3f,$3f,$06,$3f], chrdsp  '0010
            Case 3 :LOOKUP z, [$3f,$3f,$06,$06], chrdsp  '0011
            Case 4 :LOOKUP z, [$3f,$06,$3f,$3f], chrdsp  '0100
            Case 5 :LOOKUP z, [$3f,$06,$3f,$06], chrdsp  '0101
            Case 6 :LOOKUP z, [$3f,$06,$06,$3f], chrdsp  '0110
            Case 7 :LOOKUP z, [$3f,$06,$06,$06], chrdsp  '0111
            Case 8 :LOOKUP z, [$06,$3f,$3f,$3f], chrdsp  '1000
            Case 9 :LOOKUP z, [$06,$3f,$3f,$06], chrdsp  '1001
            Case 10 :LOOKUP z, [$06,$3f,$06,$3f], chrdsp '1010
            Case 11 :LOOKUP z, [$06,$3f,$06,$06], chrdsp '1011
            Case 12 :LOOKUP z, [$06,$06,$3f,$3f], chrdsp '1100
            Case 13 :LOOKUP z, [$06,$06,$3f,$06], chrdsp '1101
            Case 14 :LOOKUP z, [$06,$06,$06,$3f], chrdsp '1110
            Case 15 :LOOKUP z, [$06,$06,$06,$06], chrdsp '1111
        end select
        I2cwrite sda,scl,bin00,chrpos,[chrdsp]
    next z
    return
    The $3F represents a "0" and $06 is for a "1"

    What I am using is this 7-Segment 4-digit display from Adafruit.
    https://www.adafruit.com/product/880

    They have some sample code but it's for an Arduino.

    "No I will not give up my PICBasic!!!"
    Last edited by Heckler; - 22nd June 2015 at 04:51.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Similar Threads

  1. Replies: 10
    Last Post: - 8th March 2015, 19:26
  2. Changing output binary number sequence? is it possible?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2013, 00:47
  3. Replies: 7
    Last Post: - 11th September 2010, 00:32
  4. Convert long binary number to ASCII Decimal
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2009, 13:58
  5. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 22:18

Members who have read this thread : 0

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