
1 minute read
2.6.3 LATx Register
When the port is used as the OUTPUT. The PIC can send signals outside through PORT.
a. Write Logic 1 - PORTx registers will output 5V
Advertisement
b. Write Logic 0 - PORTx registers will output 0V
Example 2.2
Write a program statement to output 5V to RB6 pin, 0V to RC2 pin and 5V to all pins
of PortD.
Solution:
RB6 = 1; //5V to RB6 pin RC2=0; //0V to RC2 pin PORTD = 0b11111111; //5V to PortD.
2.6.3 LATx Register
LATx are the port latch registers. A write to a latch register is same as sending data to the port
register PORTx. A read from the latch register, however, reads the data present at the output
latch of the port pin, and this may not be same as the actual state of the port pin
The differences between the PORT and LAT registers can be summarized as follows:
A write to the PORTx register writes the data value to the port latch.
A write to the LATx register writes the data value to the port latch.
A read of the PORTx register reads the data value on the I/O pin.
A read of the LATx register reads the data value held in the port latch.
Example 2.3
Write a program code to output 0V to RB0-RB3 and 5V to RB4-RB7.
Solution:
LATB bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
Value 1 1 1 1 0 0 0 0
LATB = 0b11110000;