Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to initialize port?

Status
Not open for further replies.

cyteh

Newbie level 6
Joined
Jun 17, 2010
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,379
I'm a beginner in programming.
These is how i initialize portA as output...
LATA= 0x00;
TRISA=0x00;

however, may i noe how to initialize portA where only RA<4:1> are analog input and the rest of RA are not using?
 

This looks like PIC 18F code.

Each bit in the TRIS register corresponds to one bit in the port. If the bit is '0' the matching bit in the port is an output, if it is a '1' the bit is an input. You have to think in binary to work out which bits are inputs and outputs and then which bits are 0 or 1.

For example:
TRISA = 0x00; //all bits are '0' so all pins are outputs
TRISA = 0x01; // this is 0000 0001 in binary so bit zero is an input
TRISA = 0x0F; // this is 0000 1111 in binary so bits 0, 1, 2 and 3 are inputs.

If your PIC has less than 8 bits on the PORTA, the extra ones are ignored.
If you have pins which you are not using in your design, the best strategy is to make them outputs but leave them disconnected, this will ensure they can not 'float' or be damaged by static build-up.

Also note that on many PICs the pins are shared with other functions so you may for example have to disable the comparators or analog inputs to use the pins as digital inputs or outputs.

Brian.
 

    cyteh

    Points: 2
    Helpful Answer Positive Rating
thx Brian :)
now i know how to initialize the port dy...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top