Link to home
Start Free TrialLog in
Avatar of lisa_mc
lisa_mcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Setting up ports for PIC16F877A

I have recently been given code which was written to program a PIC16F877A.  This code has been written in C.

I understand the different ports but I dont understand what TRISA is and what they are used for.

Also I have noticed in the code when each of the ports is setup the code is used:

TRISA = 0xFF    // sets to inputs
PORTA = 0x00 // sets to zero

TRISD = 0x4E // set bits (0,1,2,5) inputs, others outputs
PORTD = 0x00

What I dont understand is how does 0xFF sets this to an input, and also how does 0x4E set this to bit 0,1,2,5 as inputs and others outputs

I have tried searching the internet but I dont really understand so if anyone would have a simple way of explaining this would be greatly appreciated
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NovaDenizen
NovaDenizen

The PIC16F877A datasheet is at http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

See figure 2-3, which is the register file map for the 16F877A.  TRISA and TRISD correspond to 85h and 88h, respectively.

Table 2-1 explains a little about TRISA, and redirects you to pages 43 and 150.

Section 4.1, "PORTA and the TRISA Register" hopefully explains what you need to know about TRISA, and there is a similar section for TRISD at sectoin 4.4, "PORTD and the TRISD Register".