Reading a 8bit Binary word


Closed Thread
Results 1 to 6 of 6
  1. #1
    Moz's Avatar
    Moz Guest

    Question Reading a 8bit Binary word

    Hi All,

    After a little direction here if anyone can help.

    What I need to do is read a 8 bit binary word say on porta, look up a value and output this binary value on portb.

    But I would need to keep polling the trigger word on porta to see if it changes.

    eg 00110011 input

    lookup code 00110011 means an output of 11000011 is required.

    output 11000011 on portb

    keep the output constant until input changes (loop)

    In the good old days - i would use a eprom and program it to act as a simple data converter with a bit of discrete logic to track any address changes on the address lines.

    Any direction would be great

    Many Thanks


    Moz

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moz,


    Moz>>What I need to do is read a 8 bit binary word say on porta, look up a value and output this binary value on portb.<<

    How is the word going to be read??? Via Serial data? Via parallel data? (Many A ports that I know of, can't handle a 8 bit Parallel read). So what kind of chip are you talking about?

    Now about output... are you going to output as a parallel data output, and use the whole port B (like a 8 bit LCD)? Or are you going to serial output and use just a pin?(like a Backpack LCD)

    These are untested, but should work with little change in coding.


    a simple psuedo code parallel

    Loop:
    if Porta="00110011" then gosub Newdata
    goto Loop

    Newdata:
    Portb=Porta
    return.


    a simple psuedocode Series:

    Readdata var byte;
    trisa="11111111"
    trisb="00000000"
    PinIn var Porta.1
    PinOut var Portb.1

    Loop:
    Serin PinIn, T2400, Readdata
    if Readdata="00110011" then gosub Newdata
    goto Loop:

    Newdata:
    Portb=Readdata 'for parallel output
    Serout PinOut,T2400,Readdata 'for serial output
    return

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Moz's Avatar
    Moz Guest


    Did you find this post helpful? Yes | No

    Default Parallell Data Read

    Thanks Dwayne,

    The chips I am playing / have most of are the 16f627, but whichever can do the job is what I will purchase.

    The application is parallel read and parallel output, so what happens is I have a series of inputs which are in binary, I need to look up the read value and ouput a new value on the other port.

    Similar to an eprom used in this way - where you would set up an address toggle it and the 8 bit code (whatever was programmed) in the chip would appear on the D0-D7 data lines.

    It is going to be used as a "translator" from one test fixture to another to control some Automatic Test Equipment. The Original eprom that was used to do this has been damaged (always use ZIF sockets :-) ) and I thought a pic could be used instead.

    There is about 40 codes that would need to be translated.

    Many Thanks


    Moz

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moz,

    Ok, now we have parallel to Parallel with a dinner table as a translator.
    Here is a untested but probably very close working program you are looking for I think...

    Dwayne

    TRISA="11111111" 'set Porta to all input...8 bit
    TRISB="00000000" 'set Portb to all output...8 bit.
    ReadData var byte
    HoldData var byte
    TranslateData var byte
    Counter var byte


    MainLoop:
    ReadData=Porta
    If ReadData!=HoldData then Gosub TableLookup
    HoldData=ReadData
    Goto MainLoop

    TableLookup:
    Counter=0
    Loop2:
    Read Counter,Holddata 'read table
    if Holdata=$FF then Goto MainLoop 'bad data
    If Holddata=ReadData then goto TransmitPortb 'MATCH!!!
    Counter=Counter+2 'Must skip every other byte for table!
    GotoLoop2


    TransmitPortb:
    Read Counter+1, HoldData 'reads Translated value
    Portb=Holddata 'outputs to portb
    Return
    End
    Last edited by Dwayne; - 1st September 2004 at 21:40.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moz,

    I made just a few corrections in that psuedo code...


    TRISA="11111111" 'set Porta to all input...8 bit
    TRISB="00000000" 'set Portb to all output...8 bit.
    ReadData var byte
    HoldData var byte
    TranslateData var byte
    Counter var byte


    MainLoop:
    ReadData=Porta
    If ReadData!=HoldData then Gosub TableLookup
    HoldData=ReadData
    Goto MainLoop

    TableLookup:
    Counter=0
    Loop2:
    Read Counter,Holddata 'read table
    if Holdata=$FF then Goto Baddata 'bad data
    If Holddata=ReadData then goto TransmitPortb 'MATCH!!!
    Counter=Counter+2 'Must skip every other byte for table!
    Goto Loop2


    TransmitPortb:
    Read Counter+1, HoldData 'reads Translated value
    Portb=Holddata 'outputs to portb
    Baddata:
    Return
    End
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  6. #6
    Moz's Avatar
    Moz Guest


    Did you find this post helpful? Yes | No

    Default Reading an 8 bit binary word

    Hi Dwayne,

    Thanks for your help, sorry about the delay in responding I have just got back from London on business.

    OK I can follow most of this but dont understand 2 things, why have u declared the variable TranslateData when it does not appear to be used ?

    And the other one is
    Counter=Counter+2 'Must skip every other byte for table!

    On the lookup's this has got me confused.

    I did not know you could say read porta as a byte, so i was expecting the code to use a lookup table (if one can hold 38 values) as the input and output data has nothing in common and may in some circumstances be duplicated

    eg if input is 11011011 then output 00001100
    if input is 00011111 then output 00001100
    if input is 10101010 then output 01111111

    so i suppose a nasty and not efficient way would be something like this - psuedo code

    TRISA="11111111" 'set Porta to all input...8 bit
    TRISB="00000000" 'set Portb to all output...8 bit.
    ReadData var byte

    MainLoop:
    ReadData=Porta
    If ReadData=11001111 then Gosub SUB1
    If ReadData=11001111 then Gosub SUB2
    If ReadData=11001111 then Gosub SUB3
    Goto MainLoop

    SUB1:
    Portb=00110100 'outputs to portb
    return

    SUB2:
    Portb=10111000 'outputs to portb
    return


    SUB3:
    Portb=11111100 'outputs to portb
    return


    It is important to note that there is nothing common between the output and input data.

    Thanyou


    Moz

Similar Threads

  1. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 01:51
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23

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