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.

Reading address counter from char LCD in 4 bit mod

Status
Not open for further replies.

sairfan1

Full Member level 1
Joined
Jun 12, 2010
Messages
97
Helped
4
Reputation
8
Reaction score
7
Trophy points
1,288
Location
Regina, Canada
Activity points
2,370
Hi
I am stuck in a situation where I'm using Char LCD (40x4 HD44780) and i want to ready current cursor position. it could be achieved by setting pin RS = 0 and RW = 1 data should be present at pin DB0 to DB6. As in 4 bit mode we use pins DB4 to DB7 how can i read address counter.

Thanking you.
 

Like for the 4-bit character write you have to use the nybble-read twice. The first readed nybble contains DB6-DB4 (and the busy flag in DB7) while the second nybble gives DB3-DB0 of the DDRAM address. Then left shift 4 times the first and add the second nybble. ...
 

Like for the 4-bit character write you have to use the nybble-read twice. The first readed nybble contains DB6-DB4 (and the busy flag in DB7) while the second nybble gives DB3-DB0 of the DDRAM address. Then left shift 4 times the first and add the second nybble. ...

you mean i should execute Read command twice?? like below
Code:
// read high nibble.
RS = 0;
RW = 1;
tmp = PORTD >> 4;
RS = 0;
RW = 0;
// read lower nibble
RS = 0;
RW = 1;
tmp = (tmp << 4 ) | (PORTD >> 4);
RS = 0;
RW = 0;

right??
 

you mean i should execute Read command twice?? like below
Code:
// read high nibble.
RS = 0;
RW = 1;
tmp = PORTD >> 4;
RS = 0;
RW = 0;
// read lower nibble
RS = 0;
RW = 1;
tmp = (tmp << 4 ) | (PORTD >> 4);
RS = 0;
RW = 0;
right??
Not exactly. And do not forget the two E-pulses (Hi-Lo):
Code:
// if LCD D7..D4 pins are connected to DB7...DB4

RS = 0; // command mode
RW = 1; // read mode
TRISD |= 0xF0; // DB7...DB4 are inputs now

// read high nibble.
E = 1;
Delay_1us();
tmp = PORTD & 0x70; // LCD D6..D4
E = 0;
Delay_1us();
// read lower nibble
E = 1;
Delay_1us();
tmp  |= (PORTD >> 4);
E = 0;
//back to char-out mode
RS = 1;
RW = 0;
TRISD &= 0x0F;
 
I tried it but not worked, looks like Im doing something wrong, will work on it and give you feedback. thanks.
 

I tested the code its working but I'm not getting results what I wanted. May be there is some mistake in my understanding, my idea was to get cursor location, so that i can know if i print on currently location which row and col is cursor located. can it be done by Address Counter?
 

Well, this is really not an easy task.
First, there are two address counter: one for the DDRAM and the other for CGRAM. The above code reads that was written (modified) before.
Other problem is that the first line end address and the second line start address are not consecutive (an so on). For example (16x2 LCD) the first line adresses are 00...0F and the second line's first address is not 0x10 but 0x40 (40 ...4F).
Study the datasheets for the HD44780 and your LCD.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top