Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Microchip C18/30] What is LATB?

Status
Not open for further replies.

MathGeek

Member level 3
Joined
Aug 16, 2005
Messages
67
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,806
portb latb

What good is LATA, LATB, etc for PORTA, PORTB?

They seems to hold values for PORTA and B, etc, but what is the use?

Added after 1 minutes:

Also, I realized for my 30F4011 simulation in MPLAB, some how the value of PORTB never changes even if I write

PORTB = 0xFF;

Only the data latch changes, ie LATB becomes 0xFF.

Why is the PORTB not changing?
 

latb and portb

Hi!
The Microchip data sheet for the 18F452 data sheet says

Each port has three registers for its operation. These
registers are:
• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the
device)
• LAT register (output latch)
The data latch (LAT register) is useful for read-modifywrite
operations on the value that the I/O pins are
driving.

Now the question is that what are read-modify write operations?

These are those operations that first read the port make the necessary operations(e.g AND,OR) and then write back the port.

In the 16FXXX series there was no latch register which created a problem when using read-modify write operations. Suppose that you configured any pin of any port as an output and then used that pin to drive an LED. Now if the LED sinks too much current the it is possible that the volatage level on that pin will become less than 2V. In your code if you read the same pin to check wheather the LED is ON or OFF (1 or 0) it will show that the LED is off (0 logic). The reason for this is that the voltage level on that pin was below 2V because of excessive current drainage.

On the other hand in the 18FXX devices the LAT register holds the value written to the PORT irrespective of the voltage level on the port pins. The actual logic level on the port pins can be read through the PORT register.

Regards.
 

    MathGeek

    Points: 2
    Helpful Answer Positive Rating
portb vs latb

Thank you for your nice answer.

I also just figured out a new information that I didn't know before.

I have been familiar with 18F series. If I am correct, in C18, writing to PORTB is exactly the same as writing to LATB.

Hence,

PORTBbits.RB3 = 1;

is the same as

LATBbits.LATB3 = 1;

However, as I just figured out, these two operations are not the same in 30F. This revelation fixed my problem that I had for several days.

PORTBbits.RB3 = 1; in 30F makes the PORTB = 0x08 no matter what the previous value is. In other words, it clears all other bits besides RB3.

LATBbits.LATB3 = 1; just set that particular bit without messing with other pins.


Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top