lisa_mc
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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".