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.

[SOLVED] LCD 16x2 4 bit interfacing problem

Status
Not open for further replies.
Hi,

the port register doesn´t know about the OR-ing.

So it still accesses 4 data bits, 2 control bits, one PWM bit and one unsued bit.
With the OR you definitely clear 4 bits. But this is not what the OP wants. He wants the bits to be unchanged.
A 1 should be unchanged and a 0 should be unchanged.

When i send data to port C. It will make PORTC lower nibble 0000. But i don't want to make these pins 0. i want to leave these pins in previous status.
The OP is correct on this.

As said before: a read-modify-write (RMW) is the way to go.
Read the previous port status, modify just the (4) bits you need to change (leave the other bits unchanged), write data to the port.

Klaus
 
PORTC |= xx does a read-modify-write...

The complete operation can be also written in one line, probably avoiding double RMW with a simplistic µC compiler.
Code:
PORTC  = (PORTC & 0x0F) | (data<<4);
 

I'm going to confuse things even further. The line should be:
Code:
LATC  = (PORTC & 0x0F) | (data<<4);
otherwise there is a danger of reading residual charge on the port pins into the equation.

Brian.
 

I'm going to confuse things even further.
Can't be avoided, thanks for mentioning the point.

Reading the previous code examples, I was assuming a PIC16 which has not LATx registers. But I see it's actually PIC18. In this case, you'll better read back LATC for the RMW sequence. Writing PORTC or LATC does the same, but you'll write to LATC for clarity.

So I presume, we should write
Code:
LATC  = (LATC & 0x0F) | (data<<4);
 

No, read the PORT, write the LAT.

The LAT holds the last data written to the output latches which may not be the same as actually on the pins. In the case where the low bits are to be written back unchanged the values on those pins are the ones that should be read in directly from the port pins then written back out again. In this particular application it may be that the lower bits are configured for special purposes, in which case it may not matter but the general rule is to read whatever is on the pin then restore it by writing it back.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top