Shop OBEX P1 Docs P2 Docs Learn Events
Mode no mode or what.... :) — Parallax Forums

Mode no mode or what.... :)

BebopALotBebopALot Posts: 79
edited 2006-02-04 02:07 in General Discussion
Hello forum persons...

If I want to set RA ports bit 0 to 'Hi' and 1-3 to "Lo" this is one way by setting the mode for TRIS:

Mov M, #$0f
Mov !ra, #$0f

Yet I often see no mode access and see other variations:

Mov w, #%1110
Mov !ra, w

or

compound

Mov, !ra, #%1110

When is it necessary to access Mode?

Thanks,

BBAP

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-03 15:43
    Hello,

    ·· MODE (register change) is only needed if you want to change other properties of the port, such as internal pull-ups, schmidt triggers, etc.· If you happen to change the MODE and want to affect the direction registers again, you need to make sure they're reset to $0F again.· They stay in the last state until reset or power off.

    BTW, you did mean to set the directions of the I/O pins, not the their HIGH/LOW state, correct?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • BebopALotBebopALot Posts: 79
    edited 2006-02-03 17:21
    I guess I really don't understand the relationship between the port bit direction setting (0 - output, 1 - input) and the associated logic level. I thought if you changed the direction register for a bit to "output", for example, the assocaited pin would go LOW (Logic 0) and if you set the port configuration direction register to "input" its associated PIN would go "HIGH" (logic 1). So it seems you can change the logic level of a PIN indirectly by changing its port direction.

    I guess I am confused about TRIS setting in the register and logic level on the output pin, you know, how one is related to the other.


    Thank you,

    BBAL
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-03 17:27
    That is incorrect.· When the pin is an INPUT it is floating (high-impedance).· In order to make the pin high or low you first make it an output by setting the direction register to 0, then you write the appropriate values to the appropriate port, for example RA, RB or RC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-03 17:31
    Let me try to clarify...By default the MODE register contains $0F so setting the TRIS_A or TRIS_B affects the direction registers.· The are set to INPUT by default, so setting them to $00 would make them all outputs (Which they would be LOW by default).· At this point if you want to make the outputs all high on port B you could do something like RB = $FF.· Individual bits could be accessed by doing something like RB.0 = 1, RB.1 = 0 and RB.7 = 1.· Do you understand how this works?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 2/3/2006 6:10:56 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-03 18:00
    Chris Savage (Parallax) said...
    · So setting them to $00 would make them all outputs (Which they would be by default anyway).·

    Hey Chris, I found this comment a little suspicious, and looking in the User Manual, a port direction is input by default:

    (Table 4-1, page·139)
    Register···························· Power-On|Wakeup|Brown-out|Watchdog Timeout|MCLR
    RA through RE Direction····· FFh········· FFh········· ·FFh····················FFh············· FFh

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-03 18:06
    Paul,

    ·· I edited my post...I meant to say they were low by default when made an output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-03 18:07
    Gotcha

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • BebopALotBebopALot Posts: 79
    edited 2006-02-03 21:43
    Ok, I see. So you can set the HI or LOW of a pin only when the mode $0f TRIS register is set to output. Since it is set to output by default, there is no need to access TRIS for typical logic state settings of the pins. You can set the PINS with MOV commands. If the PIN changes I/O status to input (for whatever reason) and you wanted it back to output then you would access TRIS mode if you wanted to directly set the logic level yourself in an output state. So it seems that there are (3) states of the pins, input, output and the high impendeance setting. Is this why the register configuration port for this option is referred to as "TRIState" or TRIS?
  • pjvpjv Posts: 1,903
    edited 2006-02-04 02:07
    Hi Bebop;

    You don't have it quite right.

    A pin can be made to be an input, or an output; at power-up and on RESET all pins default to input type.

    When its an input, the external circuitry connected to the pin determines the Hi or LO level.

    A pin is made an output by changing the pin's TRIS (direction) value. A TRIS value of 1 (this is the default value) means an input, and making the pin's TRIS value 0 makes it an output. To access this TRIS register you must first set the MODE register to $0F (this is also the default mode value on power-up and RESET), to be able to write to the port TRIS register. The MODE register must contain various values, one each for configuring the pin pull-up resistors, switching levels, etc.

    When its an output, it can have a HI (5V) or LO (0V) output level. This level is stored in the port output register; this is NOT the same as the TRIS register.

    I believe the content of the output register (not the pin; THAT becomes an input) at power-up is indeterminate, and on RESET it is "no change" from the levels prior to the RESET. So after configuration, any pins made to be outputs will show the value already in it's corresponding output register bit. Hence on power-up its important to set the port output register to the desired levels prior to making them outputs.

    Hope this helps.

    Cheers,

    Peter (pjv)
Sign In or Register to comment.