How to convert HEX Value as formatted BIN String ?


+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44

    Default How to convert HEX Value as formatted BIN String ?

    Hello,
    thanks for all who helped me with my last prob. Very hot ways to realize that.
    Now i want to shrink my code because the limit is coming (4k).
    Is it possible to convert hex data read from eeprom or such like LOOKUP as a formatted 8-Bit String?

    for expamle: Eeprom Location, hex value01, hex 2,.....
    @$0 $23 = 00100011
    @$1 $01 = 00000001
    Now the string should be look like this : 0010001100000001 ...
    And this string should be send via a portpin i.e. PORTB.5
    Before i wrote like this and it works fine but really takes a lot of memory. One string can be 192 Bits long.
    Code:
    FOR lp = 0 TO 23 ' 24 BIT
    LOOKUP lp,[1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,0],PORTB.5
    pauseus 660
    next lp
    return
    Code:
    FOR lp = 0 TO 2
    LOOKUP lp,[$23,$01,$AE],BIN(PORTB.5) ' here should be send the binary string
    pauseus 660
    next lp
    return
    but how to realize that ?

    Robson

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    It seems odd to be sending data that way, but if you say it works, then ....
    Code:
    lp      VAR BYTE
    TempB   VAR BYTE
    BitLoop VAR BYTE
    
        FOR lp = 0 TO 2
            LOOKUP lp,[$23,$01,$AE],TempB
            FOR BitLoop = 0 to 7
                PORTB.5 = TempB.0[BitLoop]
                pauseus 660
            NEXT BitLoop
        next lp
    return
    DT

  3. #3
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44

    Default

    Darrel you are amazing ;-)
    Only one small bug is inside
    the first step will not recognize as show below i used AA 3 times = 1010101010101010
    my watching LED is blinking 1st time but no flashing on remote ?
    It seems that the PIC eats up the first bit. And at last the remote should be off but itīs always on. Looks like shifted one bit.
    I tried something but cannot find where the problem is.
    Code:
    lp var byte
    remote var PORTB.5
    TempB   VAR BYTE
    BitLoop VAR Byte
    ledstepper var PORTB.4 ' Control each step
    
    remote = 0
    LEDSTEPPER = 0
    
    
    FOR lp = 0 TO 2
    LOOKUP lp,[$AA,$AA,$AA],TempB
    FOR BitLoop = 0 to 7
    remote = TempB.0[BitLoop]
    Pulsout ledstepper,1000
    pause 500
    NEXT BitLoop
    next lp
    end
    Instead the sequence looks like that:
    ledstepper : 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
    remotepin : 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1
    Last edited by Robson; - 18th August 2007 at 23:09.

  4. #4
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44

    Default

    I got it.
    Code:
           FOR BitLoopH = 7 to 0 step -1
               Pulsout ledstepper,1000
               remote = tempb.0[bitloopH]
               pause 500
           NEXT BitLoopH
    Thanks Darrel, sometimes is it good to try some things by myself. That was really bad to use $AA as testbyte. ;-)
    The string comes from the last position.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Ah Ha! MSB first.

    I should have seen that.

    Great, glad you figured it out.

    regards,
    DT

  6. #6
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44

    Default

    @Darrel
    thatīs really fantastic. Iīve shrunked my data code about the strings from 2,7kB to :
    just listen 195 "BYTE" using the Eeprom now. Not the complete program but only the data space, which tooks a lot of memory. It was not possible before to store that whole data on the eeprom. But with this great snip of code, knowing now to realize for coming projects, can i save a hugh amount of space of my lovely PIC ;-)
    I just canīt believe it now.
    One complete string takes 31 byteīs of the eeprom space. I have 8 instructions to send by pressing a key.
    Only for demonstration :
    Code:
    volume-:
    a = 0
    gosub loop
    
    volume+:
    a = $20
    gosub loop
    
    undershort:
    a = $40
    gosub loop
    
    underlong:
    a = $60
    gosub loop
    
    sourceleft:
    a = $80
    gosub loop
    
    sourceright:
    a = $A0
    gosub loop
    
    scrollup:
    a = $C0
    gosub loop
    
    scrolldown:
    a = $E0
    gosub loop
    
    end
    
    loop:
    b = a + $1D
    FOR lp = a TO b
    read lp, tempb    
           FOR BitLoopH = 7 to 0 step -1
               remote = tempb.0[BitloopH]
               pauseus 660
           NEXT BitLoopH
    next lp
    PORTB.4 = 1 ' Control LED if sequence finished
    pause 1000
    PORTB.4 = 0
    return
    Maybe i forgot something ...
    But itīs still working... So i donīt forget something :-)
    Big thanks to YOU

Similar Threads

  1. How to convert a HSERIN string to a hex value?
    By ShortBus in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd October 2009, 04:41
  2. Converting Dec word to Hex string
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th August 2007, 05:44
  3. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  4. Convert dec/binary to Hex
    By SagemFree in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th May 2005, 18:00
  5. hex to bin converter
    By darkman in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th April 2005, 14:41

Posting Permissions

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