Shop OBEX P1 Docs P2 Docs Learn Events
Need help with PASM code — Parallax Forums

Need help with PASM code

SiriSiri Posts: 220
edited 2008-09-18 17:58 in Propeller 1
Please help me with this code.I have a hard time to figure out what what is being done here and what are we trying to accomplish with this code.
I am lost at - test DataPinMask,INA wc.The use of Z & C flags are confusing.


SHIFTIN       mov    DataBitMask,#1            'Create BitMask  i.e - 00000001
              shl    DataBitMask,DataBits      'Set number of Bits i.e - 10000000
              mov    Data,#0                   'Clear Data
_ReadNextBit  or     outa,ClockPinMask         'Set Clock pin HIGH  - Start Clock
              test   DataPinMask,ina     wc    'Load "C" with DataPin value
              muxc   Data,DataBitMask       'Move "C" into Data via DataBitMask position
              andn   outa,ClockPinMask      'Set Clock pin LOW   - End Clock
              shr    DataBitMask,#1      wz 'Move BitMask position right by 1           '     
        if_nz jmp   #_ReadNextBit          'Jump to '_ReadNextBit' if there are more bits



A good explaination with details - apppreciated.

Thanks

Siri


Post Edited (Siri) : 9/18/2008 3:35:32 AM GMT

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-18 03:32
    Hi Siri,
    Can you edit you post and put the code in a code box, or attach the spin file? Your code has lost all its formatting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-18 04:40

    SHIFTIN       mov    DataBitMask,#1            'Create BitMask  i.e - 00000001
                  shl    DataBitMask,DataBits      'Set number of Bits i.e - 10000000
                  mov    Data,#0                   'Clear Data
    _ReadNextBit  or     outa,ClockPinMask         'Set Clock pin HIGH  - Start Clock
                  test   DataPinMask,ina     wc    'Load "C" with DataPin value
                  muxc   Data,DataBitMask       'Move "C" into Data via DataBitMask position
                  andn   outa,ClockPinMask      'Set Clock pin LOW   - End Clock
                  shr    DataBitMask,#1      wz 'Move BitMask position right by 1           '     
            if_nz jmp   #_ReadNextBit          'Jump to '_ReadNextBit' if there are more bits
    


    Generally it looks like its reading 8 bits from an I/O port and converting it into a byte, the most significant but of the byte is read first.
    Each bit needs to be clocked. The data pin is DataPinMask and the Clock pin is ClockPinMask
    The device outputs new data on the clock rising edge.
    The first 2 instrcutions are setting up where the data in is going in the byte, its reading the most significant bit first.
    instruction3 is clearing the output byte
    4 is setting the clock high, the device must output a bit on the rising edge of the clock
    5 - test is reading the io ports, and setting the carry bit depeding in DataPinMask i/o port. It will have been set with a 1 in the bit psoition for the port, ie for pin 1 it will have a 1 in bit 1.
    6 - muxc is setting a bit in the output byte, selected by DataBitMask if the carry is set. So if the io port was 1, the bit is set.
    7 - andn takes the clock low - getting ready for the next bit
    8 - shr moves the 1 bit in databitmask right 1, i.e. it starts in bit position 7 for hte first test, then 6, etc. and if the 1 has moved out of position 0, then DataBitMask will be zero, so the zero flag will be set
    9 - if the zero flag is not set i.e. DataBitMask still has a 1 somewhere, then jump to get the next bit from the io port.

    
    
  • SiriSiri Posts: 220
    edited 2008-09-18 15:15
    Tim,
    Now if I understand correctly after the " MOV Data,#0 " instruction the Data bit is "00000000" - cleared to zero
    The clock is started and begin reading each byte - then the 'Data input pin' state is read via " INA = 0 or 1 " then the "C" flag is set if parity is odd in other words if " INA=1/high"
    Then " muxc Data,DataBitMask " sets the MSB of the Data byte to "1" i.e 10000000
    Then sets the clock pin low - to start the next reading by making the clock high -
    Then " shr DataBitMask,#1 " - moves the bit position Rt - 7th position and sets " Z " flag to "0 - zero" only if NO position to move- Byte is complete
    Then " if_nz jmp #_ReadNextBit " if " z " flag is not set - go and get the next bit

    This cycle of events continue untill all 8 bits are received and placed in the "Data byte"

    I hope this is correct if not steer me in the right direction.

    Thanks for the patience and time to teach a rookie beginner.

    Siri
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-18 17:58
    Correct, only correction "The clock is started and begin reading each byte" should be reading each bit
Sign In or Register to comment.