Shop OBEX P1 Docs P2 Docs Learn Events
Port Data Direction Register — Parallax Forums

Port Data Direction Register

sxmansxman Posts: 7
edited 2012-07-18 20:52 in General Discussion
Good morning-

Could any of you learned people out there tell me if it is possible to change the DDR for a specific pin?

ie I'd like to be able to (say) change the direction of rc.7 without having to write a complete new byte to the !rc register

eg setb !rc.7 (which I know doesn't work)

rather than

mov !rc, temp ( where temp.7 contains the value I want to write to !rc.7)

Thanks

Comments

  • 4x5n4x5n Posts: 745
    edited 2012-07-18 09:54
    Have you tried putting the proper mask int 'w' and than using xor to toggle the bit based on the mask.
  • sxmansxman Posts: 7
    edited 2012-07-18 10:07
    Thanks for the suggestion-
    I assume you mean something like this:

    mov w,!rc
    xor w,#%10000000
    mov !rc,w

    Unfortunately, the mov w,!rc instruction is thrown out by the assembler.
  • 4x5n4x5n Posts: 745
    edited 2012-07-18 12:15
    sxman wrote: »
    Thanks for the suggestion-
    I assume you mean something like this:

    mov w,!rc
    xor w,#000000
    mov !rc,w

    Unfortunately, the mov w,!rc instruction is thrown out by the assembler.

    I was actually thinking of something like:

    mv w, #%10000000
    xor !rb, w

    Unfortunately that isn't allowed by the assembler either. :innocent:

    I did a bit of checking around with google and it doesn't look like it's possible to do anything but write to the register with the "mov" command. You may need to use a register to save a copy of the port dir register make your changes to it and than move that into the !rx register.
  • sxmansxman Posts: 7
    edited 2012-07-18 13:11
    Thanks for coming back again.
    Yup, that was my conclusion earlier today- and it works OK. But (strange how there's always a but) I was trying to avoid using a dedicated register for this action as, due to the position of the routine using this command, it would really need to be a page $00 register and I've used them all up. Anyway, thanks again for your suggestions.
  • 4x5n4x5n Posts: 745
    edited 2012-07-18 15:18
    I've always hated ports that I could only write to. So much easier to be able read back the status than have to keep track of it.
  • wasswass Posts: 151
    edited 2012-07-18 20:52
    Yeah, this is a week point with the SX. In fact SX/B reserves the last few bytes of RAM to keep copies of the TRIS registers for this purpose.
Sign In or Register to comment.