• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Very confused about setting TRIS to output or input

arlin

New Member
Hi, Newbie here.
I am just starting with PIC programming and have come across something very confusing with PicBasic. From my reading it appears that by assigning 0 to a pin's Dir you make it an input and by assigning 1 you make it an output. (page 22 of the PicBasic manual)

But then there is this code:
Symbol TrisA = $85
Poke TrisA,255 'make all portA pins inputs
- aren't we assigning ones to the TrisA bit of each pin and shouldn't that make them outputs?
Am I missing something here?
This is really going to bug me; your input will really be appreciated.
 

kinjalgp

Active Member
TrisA and TrisB are Port A & B direction registers which decide the direction of individual port pins depending upon the value in these registers.

Unlike other microcontrollers, PICs port are a bit different. You need to set the direction in Tris register before doing any manipulations with the port pins.

I think Tris activates/deactivates internal pull-up's or pull-downs on the port pins.
 

arlin

New Member
Thanks for the input, Kinjalp. What is really confusing me is an apparent contradiction in my PicBasic manual regarding the particular values assigned to the Tris register that determine whether pins are inputs or outputs.
.... and I just figured it out - the manual has it backwards. After looking at the 16f84 datasheet it appears that a value of one in the Tris bit makes it a input.

How annoying! I'm sure you old pro's can spot a typo instantly, but as a newcomer to electronics I have spent hours scratching my head over something in a book or manual only to find that it is a typo or outright error.
 

arlin

New Member
Thanks for the confirmation Kinjalgp. The error is in the area where they discuss the 'Dirs' variable.
 

Latest threads

EE World Online Articles

Loading

 
Top