Mode no mode or what.... :)
BebopALot
Posts: 79
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
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
·· 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
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 Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 2/3/2006 6:10:56 PM GMT
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
·· 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
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)