Shop OBEX P1 Docs P2 Docs Learn Events
Best way to write a Byte using PASM — Parallax Forums

Best way to write a Byte using PASM

Jim FouchJim Fouch Posts: 395
edited 2013-01-24 09:48 in Propeller 1
I'm working on a parallel LCD interface driver. I want to write a byte to 8 contiguous pins.

I also want the driver to have the first pin be definable.

I'm just not sure what is the most efficient way to update all 8 lines at the same time.

I've tried the following code, but did not see any outputs change on my Logic Analyzer.

Here I define my vars...
   DB0         Res   1
   DBMask      Res   1 ' Used for Masking the out port
   Byte2Write  Res   1

Here is where I pass the first pin at the start up of the driver...
                        Mov     Par_,Par                ' Grab Par pointer
                        RDLong  DB0, Par_
                        MOV     DBMask, #$FF            ' Create an 8 Bit Mask 
                        SHL     DBMask, DB0             ' Shift Left this many pins
                        OR      DIRA, DBMask            ' Define as an output

Then here is where I try to write a byte to the port...
WriteByte     ' This sub will write out 8 bits that are in Byte2Write
                        MOV     Temp4, Byte2Write      ' Place Byte to Write in
                        SHL     Temp4, DB0               ' Shift Left to Align with DB0
                        ANDN    OUTA, #DBMask           ' Set OUTA using DBMask (make all pins Low)
                        OR      OUTA, #TEMP4            ' Copy Byte2Write into Temp2
WriteByte_ret           RET

Not sure what I'm doing wrong. Or maybe there is some better way to do this.

Thanks,

Jim Fouch

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-24 08:26
    Throw out the #s. You should have:
                   SHL     Temp4, DB0
                   ANDN    OUTA, DBMask
                   OR      OUTA, Temp4
    
    Alternatively you could have:
                   SHL     Temp4, DB0
                   MOV     Temp5, Temp4
                   XOR     Temp5, DBMask   ' Make complement of data
                   ANDN    OUTA, Temp5   ' Turn off any zero bits
                   OR        OUTA, Temp4   ' Turn on any one bits
    
  • Jim FouchJim Fouch Posts: 395
    edited 2013-01-24 09:14
    Thanks Mike.

    I always seem to mess up on the #. Either forget it when I need it or put it there when I don't....lol

    I'm stuck in airports or on an airplane for the next 10 hours, so I'll have to try soon as I get back to my lab. :smile:
  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-24 09:34
    One other option:
                   SHL     Temp4, DB0
                   AND     OUTA, Temp4   ' Turn off any zero bits
                   OR      OUTA, Temp4   ' Turn on any one bits
    
    Note that the AND will turn off other bits in OUTA (outside of the 8-bit mask). If no other OUTA bits are used in this cog, that won't be an issue. This will also work if another OUTA bit is only used as a 0->1->0 strobe so forcing it to zero at this point won't cause problems.
  • Jim FouchJim Fouch Posts: 395
    edited 2013-01-24 09:48
    I have 3-4 other control lines that are output that I need to remain at their previous state. I think I have enough time to do the update in 2 commands. Way faster than the previous ShiftOut serial method I was using.
Sign In or Register to comment.