The mysterious D7

Status
Not open for further replies.

desijays

New Member
Hello everyone,

I am using a PIC 16f877a for interfacing with an LCD. Typically, an LCD spends some time occasionally to deal with its own internal processing and during that time, trying to send any commands or data to the LCD will be futile cos the LCD is busy.

So before I send any commands or data to the LCD, I would like to check if it is busy or not. Could someone please tell me how to do that?

In my book here, it says I should check the D7 data bit of the LCD. And that if D7 = 0, then LCD is not busy but otherwise it is busy.

This is where the problem arises. When Im initializing the LCD, whichever port is used for the D0-D7 bits is set as output. So the LCD will not be able to pull the D7 bit high even if it is busy since D7 is configured for output. If that is the case, how is it possible to check to see if the LCD is busy or not.

I am aware of other solutions like creating a constant delay. But I would like to know if the same, can be accomplished using the D7 pin as it is mentioned in my book.

Thank you.
 

hi,
When initialising the LCD, for the first 2 or 3 commands the BUSY is not read, its not active.

During normal operation, you set the PORT on the PIC to INPUT.
You then test BUSY [D7] to check the LCD is ready for a WRITE, when the D7 becomes ready,
the PIC PORT is set as OUTPUT and you write to the LCD.

You repeat this cycle whenever you need to WRITE a command or character to the LCD.

Do you plan to use 4 or 8 lines for the data connection from PIC to LCD.?

Do you follow.?
 
Last edited:
To add to what Eric said, as well as setting the data lines to input you have to set the RW line to 1 and the RS line to 0 before you take the Enable line high. It is permissible to leave the Enable line high until D7 goes low and you don't need to read the second nibble.

Mike.
 

Thank you very much for the information. Now I understand. And yes, I follow eric. Im using 8 lines for the data connection by the way.

On the same note, I tried what you mentioned on the MPLAD simulator and it didn't work. But none the less, Im going to try it out cos Im a little wary about the fact that the simulator will always be right.

Thank you
 
Last edited:

Actually, to read the value on the D7 bit, the enable pulse must be a low to high pulse.

For all other commands the pulse is high to low though.

Thank you
 
Actually, to read the value on the D7 bit, the enable pulse must be a low to high pulse.

For all other commands the pulse is high to low though.
Not true. Here's a typical (working) busy check routine in C:
Code:
void lcd_busy(void)
{
	RW_TrisBit = 1;		//make R/W input (read)
	D7_TrisBit = 1;		//make D7 input
	RS = 0;			//set RS low
	RW = 1;			//set R/W high
	E = 1;			//set E high
	while(busyflag);	//wait for busy flag to go low
	E = 0;			//set E low
	RW = 0;			//set R/W low
	TRISB = 0;		//make D7 output
	RW_TrisBit = 0;		//make R/W output (write)
}
 
Actually, to read the value on the D7 bit, the enable pulse must be a low to high pulse.

For all other commands the pulse is high to low though.

Thank you

No, the module is enabled when the enable pin is high. It is not edge sensitive.

Mike.
 
hi des,
If you say which PORT pins the LCD is connected too, we could post a code sample for that configuration.

If you use the 4 bit LCD option, this will free up 4 PIC pins for other jobs.
 

How does that work? If you make the R/W pin an input then you must have the weak pullups on or something!

I see you do the permissible things.

Mike.
 
How does that work?
I forget! It does work though.

If you make the R/W pin an input then you must have the weak pullups on or something!

I see you do the permissible things.
I'll look at it tonight and get it clear in my mind. Weak pullups are not on. Must go to work now.
 
How does that work? If you make the R/W pin an input then you must have the weak pullups on or something!
Oh! I see now what you're talking about! What on earth was I thinking? Changing R/W's TRIS bit is obviously incorrect. I obviously meant to make R/W high instead. Funny thing is, it works! And I've used that piece of code over and over in lots of PICs. Once I got it working I didn't look back.

Guess it's time to go fix all those pieces of code now...
 
hi des,
If you say which PORT pins the LCD is connected too, we could post a code sample for that configuration.

If you use the 4 bit LCD option, this will free up 4 PIC pins for other jobs.

Hello Eric,

Im using the PIC 16F877A microcontroller from microchip.

Port C,0 is connected to RS of LCD
Port C,1 is connected to R/W of LCD
Port C,2 is connected to Enable of LCD

Port D on the PIC is used to interface the D0-D7 pins on the LCD

But unfortunately, Im not even able to bring about a blip on the LCD.

I've attached a file containing the program I wrote. Maybe there is something in it, that I have overlooked.
If I have done something wrong with the formatting please let me know. I've tried to make it as neat as possible.


Thank you.
 

Attachments

  • LCD.zip
    1.1 KB · Views: 108
hi Des,
Sorry, there's no way that program is going to work the LCD.

Would you like me to post a working sample.? or do you prefer to have a go yourself.
 
hi Des,

Attached is a simple LCD program, displays "Hello Des!".

Its been tested and it works. [4MHz xtal]

Do you have an LCD contrast pot wired to the LCD, if yes, adjust it until you can just see the pixel blocks on the LCD.

The assembler program listing was derived from an Oshonsoft Basic program I wrote for the test, there are some comments in the listing that may help.

Do you follow.?
 
Last edited:
hi Des,
Sorry, there's no way that program is going to work the LCD.

Would you like me to post a working sample.? or do you prefer to have a go yourself.

Hello Eric,

Could you please tell why that program would not work? Obviously there is some error in it. It would help me learn if you could tell me in which part of the program I have erred!!

One other thing; what is the necessity to use portA in your program?

Thank you
 
Last edited:
Hi,
The main problem is the LCD initialise, you must follow the datasheet, else it will not init correctly.
If you get the HF44780 datasheet you will see the delays required and the codes for correct init of the LCD.

Look thru the listing I posted and study the init subroutines.

PORTA on that program can be ignored for your project.

Have you tried it yet, if you can prove your hardware/LCD is connected correctly, then when you test your programs you know its not the hardware.!

Try it..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…