How to send a binary string on an output?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    44

    Default How to send a binary string on an output?

    Hello,
    i have now a problem how to send a binary string (150-200 bits long!) over an output pin eg. RB.0 without parity and stop bits.
    I´m using a 16F628A and my osc is working on 4MHz. It´s also possible to change with 8MHz if the freq is to slow.
    1 state is 1ms long that means if the string is "11010110001111100101" then takes this sending operation 20ms.
    I want to realize a communication between my steering wheel control and a JVC headunit. The connection is working over a 2way headphone plug. Normal level is set to HIGH.
    Here an example for Vol+ "0000000001111101101101101101010101101010110101010 10110111111111111111111101101101101101010101101010 11010101010110111111111111111111101101101101101010 10110101011010101010110"
    Is it possible to send such a string over an output pin or is it necessary to split the string?

    Thanks
    Robson

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    First thoughts are

    1. declare a bit array of the appropriate size

    2. declare your output pin

    3. set the bits of the array to the desired state

    Then transmit it something like this.....
    Code:
    For x = 0 to {number_of_bits-1)
        If bitarray[x] = 1 then
            outputpin=1
        else
            outputpin=0
        endif
        pause 1 ' wait for 1ms - might need changing for pauseus 990 or similar
    Next
    I might have the state of the pin wrong for your application but you should get the idea
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keithdoxey View Post
    First thoughts are

    1. declare a bit array of the appropriate size

    2. declare your output pin

    3. set the bits of the array to the desired state

    Then transmit it something like this.....
    Code:
    For x = 0 to {number_of_bits-1)
        If bitarray[x] = 1 then
            outputpin=1
        else
            outputpin=0
        endif
        pause 1 ' wait for 1ms - might need changing for pauseus 990 or similar
    Next
    I might have the state of the pin wrong for your application but you should get the idea
    ok but how to define or declare an array like this?

    bitarray VAR BIT[200]
    bitarray = %1000000000111110110110110110101010110101011010101 01011011111111111111111110110110110110101010110101 01101010101011011111111111111111110110110110110101 0101101010110101010101101

    The compiler returns with "Numeric overflow, value truncated."

  4. #4
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    How do you arrive at the values you want to send ?

    Are there a series of bytes that you are converting into the binary array ?

    If so declare an array of a suitable number of bytes and set each byte

    eg

    bytearray VAR BYTE[25]

    bytearray[0] = {whatever the value is}
    bytearray[1] = {whatever the next value is}
    etc


    Then transmit those bytes

    Code:
    For MyByte = 0 to 24
      ThisByte=bytearray[MyByte]
      For MyBit = 0 to 7 ' or 7 to 0 depending on the order !!!!
         If ThisByte.0[MyBit] = 1 then
             OutputPin=1
         Else
             OutputPin=0
         End if
         Pause 1
       Next
    Next
    Without knowing the protocol it is difficult to decide how to set the values.

    Havent tried the code above so offer no guarantee that it would work !!!

    Your question was how to transmit a binary string, not how to create it in the first place

    Dont suppose you have any info on the protocol SONY use for stalk controllers do you ?

    Just wish I could stop my Sony head unit from resetting the iPod EVERY time you turn it on. SWMBOs JVC doesnt.
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keithdoxey View Post
    How do you arrive at the values you want to send ?
    I have scanned the signal with a digital scope.

    The output is LOW active. I have split the array to different blocks. Each button if pressed begins with the first string. Look below

    1000000000111110 ' Init sequence (every button)

    110110110110101010110 ' sequence 01

    101011010101010110 ' Instruction for Vol+

    11111111111111111110 ' preparing for 2nd block

    110110110110101010110 ' sequence 01

    101011010101010110 ' Instruction for Vol+

    11111111111111111110 ' preparing for 3rd block

    110110110110101010110 ' sequence 01

    101011010101010110 ' Instruction for Vol+

    and now the signal stay at HIGH till another button is pressed.
    Many blocks like Init sequence, sequence 01, preparing for next block are in all instruction of each button. Only a few bits are different in the instruction line.
    But this String must be sent as one data without interrupts or delays. Exactly from every bit 1ms.
    Every instruction will be sent 3 times.
    When you will paint same blocks in different colours you will better see, how it works. But it´s not possible to mark with colours
    Last edited by Robson; - 25th July 2007 at 22:30.

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


    Did you find this post helpful? Yes | No

    Default

    Here's a super easy way to do this. Create command tables
    and simply GOSUB to one & output your command bit-stream.

    This looks-up X directly onto PORTB.0, pauses, then gets the
    next bit.
    Code:
    X VAR BYTE
    
    PORTB.0=0 ' set low on boot (change as required here)
    TRISB.0=0 ' RB0 = output
    
    Main:
        GOSUB Command1
        GOTO Main
    
    Command1:
        FOR X = 0 TO 171 ' 172 bits total
        LOOKUP X,[0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,_
                  0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,_
                  1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,_
                  1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,_
                  1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,1,_
                  0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0],PORTB.0
         PAUSE 1   ' Note: If this is too long, use PAUSEUS  
        NEXT X
        RETURN
        
        END
    You can have up to 255 entries 'or bits' per table with a 14-bit core device.

    It does eat-up a boat-load of program memory, but it's ultra simple to use.
    Last edited by Bruce; - 25th July 2007 at 23:01. Reason: Changed GOTO Main to RETURN in Command1.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    255 Bytes are almost enough.
    Thanks a lot Bruce.
    How´s about the underscores "_" in the array? Need to use them?

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


    Did you find this post helpful? Yes | No

    Default

    This isn't actually an array. Lookup creates a table, and uses the
    index pointer var (in this case the X) as the offset into the table.

    The underscores are optional. It just looks a lot better than having
    your constant table scrolling WAY off to the right side.
    Regards,

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

  9. #9
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Robson View Post
    I have scanned the signal with a digital scope.

    Many blocks like Init sequence, sequence 01, preparing for next block are in all instruction of each button.
    In that case create separate arrays for

    InitSeq
    Seq01
    NextBlock

    Only a few bits are different in the instruction line.
    Create separate arrays for each command or one large array with all commands and just point to a segment of it eg bits 34-57 (havent worked out the numbers!)

    But this String must be sent as one data without interrupts or delays. Exactly from every bit 1ms.
    When you need to send a command just call the component parts as required eg

    SendInitSeq
    SendSeq01
    SendCommand
    SendNextBlock
    SendSeq01
    SendCommand
    SendNextBlock
    SendSeq01
    SendCommand

    The PIC should be able to read and process the values quickly enough not to cause problems, if you see that your output pulses are taking slightly too long then change the pause to pauseus and shorten slightly

    Every instruction will be sent 3 times.
    Just add a loop and go round it 3 times. Presumabley there must be some idle time between the 3 instructions so dont forget to add that as a pause

    When you will paint same blocks in different colours you will better see, how it works. But it´s not possible to mark with colours
    I pasted it into a text editor and broke it into 4 bit chunks and you can see the patterns you refer to.

    I have built a universal remote control that reads different values from different variables on the fly and that works just fine so I doubt you will have too many problems.

    I seem to remember seeing something by either Darryl or Melanie that showed how you can access individual bits of a byte or word array as well but cant remember where it was eg byte0 was bits 0-7 byte1 was bits 8-15 but I could be wrong.
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04: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