Sunteți pe pagina 1din 2

Need for 4 bit mode

Well for interfacing anything with any processor we need system-bus (data-bus,
address-bus and control-bus). In our case for 8 bit mode the 8 data pins (D0-D7)
are the data and address bus while the 3 control pins(RS, R/W and E) are the
control bus. Thus using these we can control the peripheral that we are interfacing.
We are greedy so we want to interface as many peripherals as possible with the
same microcontroller. This requires either large number of ports or we need to be
smart and utilize what we have to the fullest. Thus first thing is we try to do is
reduce the number of pins required for controlling the peripheral. Here comes the
need for 4 bit mode. Thus we reduce the port pins required from 11 to 7. It might
not seem much, but for a small microcontroller like msp430g2553 with limited port
pins this is really a big amount. Now coming to the other method. Maybe we can
use demultiplexing , in this way we can use 'n' lines to share the system bus with
'2^n' devices. I got one tip that we can use SIPO shift register for sending data.
Now this will require only 5 port pins. Three control pins and two for serial data and
clock.

4 bit mode working

In 4 bit mode we send the data nibble by nibble, first upper nibble and then lower
nibble. For those of you who don't know what a nibble is: a nibble is a group of four
bits, so the lower four bits (D0-D3) of a byte form the lower nibble while the upper
four bits (D4-D7) of a byte form the higher nibble. This enables us to send 8 bit data
be it the ASCII code or the command code by using 4 pins instead of 8. The
connections remain identical. The only change is that the lower nibble pins of LCD
are unused.

Initializing the LCD in 4 bit mode

This is perhaps the most tricky part of this interfacing. When LCD is powered ON it
is by default in 8 bit mode.

reset(see pic)

This is the command code format for function set operation. Using this we form the
command code for 4 bit mode operation.

mode_set(see pic)

The function set bits are explained in the following section.

functions_mode_set_bits(see pic)

We need 4 bit mode so make DL '0'. Thus the upper nibble of the command code is
0010b which is 0x02. If we need 2 lines we set N and the normal font so F is 0 thus
lower nibble comes out to be 1000b i.e 0x08. Thus total command code is 0x28.

Before sending this 0x28 we need to perform a specific initialization.

initialization(see pic)

So we send 0x33 as the command code. This will do the initial 8 bit mode starting
of LCD. Now after this we need to send 0x32.(Note : We're using the nibble method
so what will go for 0x33 is 3 followed by 3 and for 0x32 is 3 followed by 2.)

So now we have initialized the LCD in 4 bit mode. All we need to learn is how to
send the value nibble by nibble in c and without affecting other port pins except the
ones that we use for sending data. (In assembly its just the rotate instruction.)

Nibble sending logic

P1OUT = (P1OUT & 0xF0)|((data>>4) & 0x0F); // send higher nibble

In this we make use of masking concept and logical shift operation in c. Now in my
program I'm using P1.0 - P1.3 pins as the data pins. Thus I'll explain the logic
accordingly. Here data is the parameter that is passed in the function. I shift the
data right by four bits, thus bringing the higher nibble in the lower nibble location.
Mask the upper part. Then I make the P1OUT lower nibble 0 so that 'or'ing with
nibble data will give nibble data on P1OUT pin. (x and 0 is 0 ; x and 1 is x; x or 1 is
1 and x or 0 is x----> (x&0)|(data_bit)= 0|data_bit= data_bit. Thus we get data bit on
the port pin without affecting P1.4-P1.7) This takes care of upper nibble.

P1OUT = (P1OUT & 0xF0)|(data & 0x0F); // send lower nibble

Now lower nibble involves the same operations except the shifting operation.

S-ar putea să vă placă și