Overview Of PIC16F877A Digital Input/Output
PIC16F877A comes with five digital I/O ports names from PortA to PortE. Since the device is 8-bit, the data bus of each port are 8-bit. From PortA to PortD the I/O are fully 8-bit wide, except PortE that uses only 3-bit of the 8-bit Port register.
Beside the digital I/O, there are some analog input output function multiplexed with any Port that we don't mention here. Any relevance's will be talk on next section.
PORT registers locate in the special function register (SFR). Each port has its corresponding name and address of the SFR.
- PORTA locates at 0x05
- PORTB locates at 0x06
- PORTC locates at 0x07
- PORTD locates at 0x08
- PORTE locates at 0x09
- PORTA=0xFF
- PORTD=0xAA
TRIS Registers
Tri-state (TRIS) register set the direction for its corresponding PORT register. As mention above, this device contains up to five PORT the TRIS register is also have up to five corresponding registers. TRIS are the member of the SFR. They have their own address in the SFR.
- TRISA locates at 0x85
- TRISB locates at 0x86
- TRISC locates at 0x87
- TRISD locates at 0x88
- TRISE locates at 0x89
- TRISC=0x0F - The lower nibble of PORTC is digital input while the higher nibble is a digital output.
- TRISA=0xF0 - The lower nibble of PORTA is digital output while the higher nibble is a digital input.
PORTB and PORTD
PORTB and TRISB
![]() |
| Registers relate to PORTB |
PORTD and TRISD
![]() |
| Registers relate to PORTD |
MikroC Digital I/O Port Programming
![]() |
| Schematic Diagram |
PORTB is internally wired to HIGH. PORTD wire to 8-bit LED output.
MikroC source code:
A simulation screen shot:
![]() |
| A Simulation Screen Shot |
Click here to download the complete example. I use my own development board to test this program.
![]() |
| Tested Program |
It also has a video of my experiment.






No comments:
Post a Comment