PDA

View Full Version : 4 bit bus



Art
- 21st January 2010, 23:06
Hi Guys,
Is it possible to set the first four bits on a port in one line without
writing to the rest of the port? I was wondering how the LCD 4 bit bus mode works.

I could send %1111 to porta for example, but then porta bits 4-7 would be
written with zeros.

I'm looking for something better than setting the bits individually.
Cheers, Art.

aratti
- 21st January 2010, 23:15
Art, Tray:

PortA = PortA & %00001111

Al.

Bruce
- 21st January 2010, 23:28
PortA = PortA & %00001111 would only work if the lower 4-bits were already set,
and would guarantee the higher 4-bits would be 0.

You want to OR the port with %00001111 to leave the higher 4-bits unaffected.

PortA = PortA | %00001111 would set the lower 4-bits, leaving the higher 4-bits
as-is.

Art
- 22nd January 2010, 00:07
PortA = PortA & %00001111 would only work if the lower 4-bits were already set,
and would guarantee the higher 4-bits would be 0.

You want to OR the port with %00001111 to leave the higher 4-bits unaffected.

PortA = PortA | %00001111 would set the lower 4-bits, leaving the higher 4-bits
as-is.

Seems to be working thanks :)

Saves two words on setting the four bits one at a time.