- PIC has five ports.
- Port A, Port B, Port C, Port D, Port E.
- PIC is an 8bit.
- Port pins can be accessed by.
- Bit instruction.
- Byte instruction.
Bit Instruction
- In bit instruction each port pins value assigned individually.
- Example
In port0 3rd pin should keep high and 4th pin should keep low, it can be done in this way.- P0_3=1; (High) // Port 0-3rd pin
- P0_4=0; (Low) // Port 0-4th pin
Byte Instruction
- In byte instruction we have to access entire port pins.
- Example
In port 0 all pin should keep low.- P0 = 0x00;
0x0000|0000;
0x 0 | 0 ; = 0x00. - In port 0 MSB should keep high and LSB should keep low.
- P0=0xF0;
0x1111|0000;
0x F | 0 ; = 0xF0.
Binary Table
Byte Instruction
Example
- To access the port pin as an input and output we need to config microcontroller registers.
- We need to set the direction for pins by using the TRIS register.
- Port A Pins is accessed as output then TRISA=0x00.
- Port A Pins is accessed as input then TRISA=0xFF.