PIC Programming

  • PIC has five ports.
  • Port A, Port B, Port C, Port D, Port E.
  • PIC is an 8bit.
  • Port pins can be accessed by.
    1. Bit instruction.
    2. 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.
    1. P0_3=1; (High) // Port 0-3rd pin
    2. 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.
    1. P0 = 0x00;
      0x 0 | 0 ; = 0x00.
    2. In port 0 MSB should keep high and LSB should keep low.
    3. P0=0xF0;
      0x F | 0 ; = 0xF0.

Binary Table

Byte Instruction


  • 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.