Continue to Site

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.

  • 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.

ports

Status
Not open for further replies.

xjackal

New Member
in the start of the code most of the projects make TRISA OR TRISB INPUT/OUTPUT.but what can we do if we want to make some ports of the A AND B ports as input.i mean not using them like porta are input portb are output .for example using rb0,rb1,ra0,ra1 are input and the others are output? :shock:
 
When you set the TRIS registers you write a value to it. 1 is an input a 0 is an output. So if you want to set RB0-RB3 to input and RB4-RB7 as output, write a 0xF0 to TRISB. and it's that easy
 
To me is easier to see if you set your TRIS register with binary numbers to see what is what.

Say you want RB7-RB4 all Outputs and RB3-RB0 inputs you can define the like:
Code:
TRISB = %00001111

As they told you before a 0 is an output a 1 is an input. Same thing goes with any other register. You must take into account that some PIC that have analog pins come configured from factory to use those pins as analogs and not as your normal digital I/O.... for those it is always good to set them for digital use before hand. Use:
Code:
ADCON1 = 7

To change it from analog mode.

Good Luck

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top