Shop OBEX P1 Docs P2 Docs Learn Events
Operations on Port Registers — Parallax Forums

Operations on Port Registers

JoeAJoeA Posts: 33
edited 2007-10-03 22:02 in General Discussion
Is it the case that operations on the SX28 port registers (RA, RB, RC) only apply to positions set as·output (0)·in the direction register?
I tried the following program:
  mov W, #%0000_1111 ;put direction  0=OUT
  mov !RC,  W        ;in port direction register !RC
  mov W, #%0101_0101 ;put intital data pattern 
  mov RC, W          ;in port data register RC
  not RC             ;Toggle data bits
  mov RC, W          ;Restore RC

On the SX simulator,
after the first mov rc,w, The· contents of RC was %0101_0101 as I expected,
but after the not, the contents was %1010_1111; I was expecting %1010_1010.
after the second mov, the contents was $0101_1111; I expected %0101_0101.
The actual chip appears to behave the same way.
If the port registers are masked by the direction register, then why did wasn't the first mov result the same as the second?
I'm using SXkey 3.2.3 Assembler/Simulator, and SX Tech board·with LED cathodes connected to port pins (0=on).
JoeA

Comments

  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-10-01 20:30
    Joe,

    when you define port pins as inputs, they are read-only, i.e. no matter what you "write" to those bits, it should not change their states. When you read them, they return what they "see" on the input pins. On a "real" SX, when you define port pins as inputs, and leave them floating, i.e. internal weak pull-up not activated, and no external components connected pulling the pins either to high, or low, the states they return are un-predictable. I noticed myself such input pins changing their state when the state of an output pin was changed. Obviously, a state change on an output pin can cause enough static electricity to change the state of on an open input pin.

    Therefore, try to either activate the internal weak pull-ups for the RC.3...0 pins, or connect external pull-up, or pull-down resistors, and then retry your experiment with a "real" SX.

    BTW: The not RC instruction causes a so-called read-modify-write. IOW, when the instruction is executed, the port C pins are first read into an internal buffer, then the buffer contents is inverted, and finally, the buffer contents is written back to the port output register. For those pins that are defined as inputs, the current states are read from the inputs, inverted, and written to the corresponding bits in the port output register but the states of the input pins are not affected, provided that they are not floating.

    In general, it is a good idea to never leave input pins floating - at least activate the internal weak pull-up resistors. As an alternative, you may configure un-used port pins as outputs, and clear them once in the startup code of your program.

    SXSim does not simulate floating inputs, so it may handle this situation differently. I will need to look at the source code before I can give you the correct answer about how SXSim handles this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • JoeAJoeA Posts: 33
    edited 2007-10-03 22:02
    Thanks.
    I have all the RB and RC pins connected to LED cathodes,
    with the anodes connected thru 470 ohm resistors to Vdd.
    I'm a programmer, not an engineer, but I'm assuming that would "pull up" the input pins to +5v.
    Or, does the LED block the voltage to the pin?
    In any case, the RC bit value for the input pins on the actual chip is 1.
    Of course, the circuit doesn't really "make sense"; I was just·experimenting with·the instructions.
    My next step would be to connect the 4 RA pins to pushbuttons and use those for input.·
    JoeA
Sign In or Register to comment.