How we can program port

There are 3 pin Registers.

  • TRIS REGISTER: – It tells about the direction of ports. 0 means  output and 1 means input (by Default output is set).
  • LAT REGISTER:-It shows the status of ports.
  • PORT REGISTER: – By this register we give value to the ports.

PIC18F458 registers are divided into 5 parts, which are A, B, C, D, E.

A has three register TRISA, LATA, PORTA.

TRISA tells the direction of PORTA REGISTER ,LATA tells the status of PORTA REGISTER and by PORTA we will give the value to pins of A.

TRISA, LATA and PORTA is of 7 bit register.

B  has three register TRISB, LATB, and PORTB.

TRISB tells the direction of PORTB REGISTER, LATB tells the status of PORTB REGISTER and by PORTB we will give the value to pins of B.

TRISB, LATB, and PORTB is of 8 bit register.

has three register TRISC, LATC, and PORTC.

TRISC tells the direction of PORTC REGISTER, LATC tells the status of PORTC REGISTER and by PORTC we will give the value to pins of C.

TRISC, LATC, and PORTC is of 8 bit register.

has three register TRISD, LATD, and PORTD.

TRISD tells the direction of PORTD REGISTER, LATD tells the status of PORTD REGISTER and by PORTD we will give the value to pins of D.

TRISD, LATD, and PORTD is of 8 bit register.

has three register TRISE, LATE, and PORTE.

TRISE tells the direction of PORTE REGISTER, LATE tells the status of PORTE REGISTER and by PORTE we will give the value to pins of E.

TRISE, LATE, and PORTE is of 3 bit register.

e.g.

1.  if we want to take PORTA and PORTB as input   and we want PORTC and PORTD as output.

 then TRISA=TRISB=0X00H;  //  all bits of TRISA and TRISB become 0.

        TRISC=TRISD=0XFFH;  // all bits of TRISC and TRISD become 1.

2. If we want to check the status of PORTC, if all bits of PORTC become 1 then put 0x55h to the PORTD.

   if(LATC==0Xffh )  // check the status of PORTA

   PORTD=OX55H;   // pins of PORTD become 0x55h