Can´t interface PIC18F4520 to LCD HD44780

Thread Starter

LewisMF

Joined Nov 15, 2014
100
And how many times have I said this only to find my mistake when I finally decided to do point to point troubleshooting. ;)
Hi Spinnaker,

I hadn´t of tried point to point troubleshooting already I wouldn´t be asking for help on this forum...

I have tried everything I can think of and still can´t get it working...
 

JohnInTX

Joined Jun 26, 2012
4,709
Should the contrast pin be grounded? What does ISIS mean when it says disconnected? That would indicate a problem in the sim skiz?

On the software side, I took your code and built it with XC8 and found many versions of the xlcd library on disk (who knew?) but picked one, built it OK then stepped it while watching the ports in a window. I found that OpenXLD issued the WRONG setup codes for a 4 bit interface. That's disturbing but since I found several different versions of xlcd on disk (doubtless from various demo kits etc) I looked at the source in C18. It looked better but I didn't update my test project (busy). If it were me, I'd try this:

Explicitly include the .h file and a copy of the xlcd library source files in your code as part of the project. Don't use the compiled library. Using real source gives you control over what's going on AND you can see it execute line by line in the MPLAB simulator.
Resolve any build errors including specifying delays etc.
Step the code in MPLABX simulator, watch the port values and compare them with the Hitachi 44780 datasheet. Step OVER the delays to avoid wearing out your mouse buttons but put the stopwatch up to verify the time.
I prefer MPLABX for this kind of thing because the editor window grays out code excluded by #defines. When there are a lot of them, its much easier to see what code was actually generated.

I found the xlcd source in C:\Program Files (x86)\Microchip\mplabc18\v3.40\src\pmc_common\XLCD and the .h in C:\Program Files (x86)\Microchip\mplabc18\v3.40\h on my system. YMMV

Include each file as part of your project and build for debug. Keep in mind that you would not be the first person to find bugs or questionable code in a library. In particular, I didn't like the r-m-w on PORTx (instead of LATx) but I'm fussy that way.

I don't know what your experience level is but this is one reason I (like many of our *ahem* more experienced members) write my own libraries, sometimes using published source as a guide. Your problem, and ours too, is that you don't really know the particulars of the code you are using when you use a compiled library.

Good luck.
 

Attachments

Last edited:

spinnaker

Joined Oct 29, 2009
7,835
Typically contrast is tied to the wiper of a 10K pot with one end of the pot tied to +5V and the other tied to ground. Not sure what you would get tying it right to ground.

I have always found the microchip libraries to be overly complicated to setup properly. The basic peripheral libraries are not too bad but past that they can be pretty horrendous.
 

Thread Starter

LewisMF

Joined Nov 15, 2014
100
Should the contrast pin be grounded? What does ISIS mean when it says disconnected? That would indicate a problem in the sim skiz?

On the software side, I took your code and built it with XC8 and found many versions of the xlcd library on disk (who knew?) but picked one, built it OK then stepped it while watching the ports in a window. I found that OpenXLD issued the WRONG setup codes for a 4 bit interface. That's disturbing but since I found several different versions of xlcd on disk (doubtless from various demo kits etc) I looked at the source in C18. It looked better but I didn't update my test project (busy). If it were me, I'd try this:

Explicitly include the .h file and a copy of the xlcd library source files in your code as part of the project. Don't use the compiled library. Using real source gives you control over what's going on AND you can see it execute line by line in the MPLAB simulator.
Resolve any build errors including specifying delays etc.
Step the code in MPLABX simulator, watch the port values and compare them with the Hitachi 44780 datasheet. Step OVER the delays to avoid wearing out your mouse buttons but put the stopwatch up to verify the time.
I prefer MPLABX for this kind of thing because the editor window grays out code excluded by #defines. When there are a lot of them, its much easier to see what code was actually generated.

I found the xlcd source in C:\Program Files (x86)\Microchip\mplabc18\v3.40\src\pmc_common\XLCD and the .h in C:\Program Files (x86)\Microchip\mplabc18\v3.40\h on my system. YMMV

Include each file as part of your project and build for debug. Keep in mind that you would not be the first person to find bugs or questionable code in a library. In particular, I didn't like the r-m-w on PORTx (instead of LATx) but I'm fussy that way.

I don't know what your experience level is but this is one reason I (like many of our *ahem* more experienced members) write my own libraries, sometimes using published source as a guide. Your problem, and ours too, is that you don't really know the particulars of the code you are using when you use a compiled library.

Good luck.
Hi JohnInTX,

Playing around a bit last night I finally found the error, the problem was with the "putrsXLCD" function. I was not calling it properly. I tried after with "putcXLCD" instead and worked with no problems at all in ISIS and on a breadboard.

I´d like to thank you all for your help. :)
 
Top