PDA

View Full Version : TRISA, TRISB setting ?



iw2fvo
- 10th January 2011, 12:43
good day,
I am using the pic 18f452 to acquire some analog signals, to activate some discretes, to read and write ext memory, to interface wuith the serial link and read discretes ( pushbuttons ) and I did not use the TRISA nor TRISB . The system works well.
I will like to understand the real usage or when the TRISA TRISB need to be used in a picbasic pro programs.
Thanks for the assistance,
Regards,
Ambrogio

Acetronics2
- 10th January 2011, 13:02
Hi, Ambrogio

May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

Alain

iw2fvo
- 10th January 2011, 13:52
Hi,
you mean the PBP manual ?
tnks
Ambro

Hi, Ambrogio

May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

Alain

iw2fvo
- 10th January 2011, 13:59
Hi,
I found what you suggested to look_at.
When a PIC MCU powers-up, all of the pins are set to input. To use a
pin as an output, the pin or port must be set to an output or a command
must be used that automatically sets a pin to an output.
To set a pin or port to an output (or input), set its TRIS register. Setting a
TRIS bit to 0 makes its corresponding port pin an output. Setting a TRIS
bit to 1 makes its corresponding port pin an input.

So, it is not needed to use tris register !
Am I right ?

Ambrogio


Hi, Ambrogio

May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

Alain

mackrackit
- 10th January 2011, 14:08
Using many of the PBP commands as you are reading setting TRIS is not needed.
But
as time goes on and your code becomes more complex TRIS will need set. It will be good to get the habit of string TRIS now... or just wait until the code does not work and remember this.

One example would be reading/writing to the port.

iw2fvo
- 10th January 2011, 14:21
Hi,
Does the problem arise if I do : high LED, low LED ... or.. If PB=1 then... If PB=0 then...
Next: I2C requires a pin to be an output and an input for correct communication: what should I declare in the TRIS reg ?
Thanks
Ambrogio



Using many of the PBP commands as you are reading setting TRIS is not needed.
But
as time goes on and your code becomes more complex TRIS will need set. It will be good to get the habit of string TRIS now... or just wait until the code does not work and remember this.

One example would be reading/writing to the port.

Acetronics2
- 10th January 2011, 16:02
Hi, Ambrogio

I' ve taken the good habit ALWAYS to set ALL my Inputs/Outputs with TRIS statements AND aet their respective default level in the first lines of my programs.
of course, all SFR's and variables too ...

Whether PBP ( or any other high level language ) does it for me or not ... so, I'm REALLY sure of what will happen. Especially @ Power-up.

But you can do as you want ... there's no absolute rule !!!



If PB=1 then... If PB=0 then...



no automatic input setting here ... sooooo you could read an output state !!!

Alain

mackrackit
- 10th January 2011, 20:32
I2C requires a pin to be an output and an input for correct communication: what should I declare in the TRIS reg ?
I2C is one of those commands that will set the TRIS for you. But like Alain said, you will want to control things at start up. I would set them as an input.

If you have floating pins set them as out puts.