Support for LCD display (HD44780 2x16)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Support for LCD display (HD44780 2x16)

Jump to solution
4,136 Views
steve9
Contributor III

Please can anybody provide some example C code for connecting a common 3.3v LCD display (HD44780 2x16) to the FRDM-KW41Z development board? I have to use the KW41Z SDK (which is written in C) because I am modifying some of the example projects, but I only have limited knowledge of C. I am happy to modify C code if I have an example to work from but don't know how to start writing C code for this display. I don't mind if the examples are for 8 or 4-bit parallel mode, or I2C, or even UART (I have different displays I could use).

Thanks

Steve

Tags (4)
1 Solution
3,295 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

I ordered a board from Mouser and it arrived yesterday :-).

I have now a working driver available for you on GitHub:

mcuoneclipse/Examples/MCUXpresso/FRDM-KW41Z/FRDM-KW41Z_CharacterLCD at master · ErichStyger/mcuonecl... 

pastedImage_2.png

It still will need some tweaking and for sure is not perfect. But I hope this is something useful for you?

If time permits, I'll write an article in the blog about it.

I hope this helps,

Erich

View solution in original post

24 Replies
3,205 Views
steve9
Contributor III

Hi Erich

I have successfully used your excellent driver on several projects now, but I am getting build problems with a particular NXP example project that combines BLE pairing NTAG I2C plus functionality. It is a rather large and complicated project (to my inexperienced eyes anyway).The NXP example code that causes the problem is #1 in the list of Available Resources at the bottom of this web page ("BLE pairing with NFC on KW41 and NTAG I2C plus source code"). The NXP example code works OK before I add your driver to it.

The problem arises when I add "sim" in the Manage SDK Components dialogue. After I do this, a large number of files gets updated and another large tranche gets deleted. This then stops the project from building successfully.

I am very keen to get the LCD working with this project and any help you could provide would be much appreciated.

Thanks

Steve

0 Kudos
3,205 Views
steve9
Contributor III

I tried just copying the fsl_sim.c and fsl_sim.h files from a working (with LCD) project but that didn't build either. I am getting lots of build errors starting ../McuLib/TraceRecorder/, such as:

../McuLib/TraceRecorder/config/trcConfig.h:102:28: error: missing binary operator before token "("

../McuLib/TraceRecorder/include/trcHardwarePort.h:483:3: error: #error "TRC_HWTC_TYPE is not set!"

../McuLib/TraceRecorder/include/trcHardwarePort.h:487:3: error: #error "TRC_HWTC_COUNT is not set!"

etc.

I think I'm stuck now!

0 Kudos
3,205 Views
BlackNight
NXP Employee
NXP Employee

In case this might be helpful for everyone else: I have posted a tutorial here:

Tutorial: HD44780 Display Driver with NXP MCUXpresso SDK | MCU on Eclipse 

Erich

0 Kudos
3,205 Views
steve9
Contributor III

That's really helpful. Now I have a working setup, I want to integrate your driver into an existing project that needs an LCD, rather than starting an empty project as per your tutorial. I'm guessing that I just follow approximately the same steps?

0 Kudos
3,205 Views
BlackNight
NXP Employee
NXP Employee

yes, the steps would be the same. I just started with an empty project for that one.

3,207 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

one way would be to use the code of this project: HD44780 2×16 Character Display for Kinetis and Freedom Board | MCU on Eclipse 

It is using Processor Expert, but if you don't want to use PEx, then you could copy that C code too (you would need to map it to your pins driver).

I hope this helps,

Erich

0 Kudos
3,207 Views
steve9
Contributor III

Hi Erich

Thanks for responding.

I am the "Steve" that left a question on your blog post about PEx, but I didn't get anywhere trying to get that to work with MCUX10.3 and KW41Z. When you say "if you don't want to use PEx, then you could copy that C code too", what code do you mean? I looked here and on GitHub and Sourceforge but I couldn't find the C code that is referenced in your example (e.g.  LCD1_GotoXY(2,1);). I am a complete newbie to MCUX and C (although not to programming and IDEs generally) so forgive my ignorance - I am trying to learn!

Steve

0 Kudos
3,207 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

I see if I can find a FRDM-KW41Z and create an example project for you.

Erich

3,207 Views
BlackNight
NXP Employee
NXP Employee

After a quick check, I have no KW41Z at hand.

What I have attached is a CodeWarrior for MCU 10.x/11 project for the KL25Z which uses such a HC44780 2x16 LCD.

You can have a look at the driver in

Generated_Code\LCD1.c and LCD1.h

It should be fairly simply to use that with any project or SDK.

Or I see if I can make a port for the MCUXpresso SDK 2.5.0, but I would have to use something different than the KW41Z.

I hope this helps,

Erich

3,207 Views
steve9
Contributor III

I would really appreciate that, Erich!

0 Kudos
3,296 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

I ordered a board from Mouser and it arrived yesterday :-).

I have now a working driver available for you on GitHub:

mcuoneclipse/Examples/MCUXpresso/FRDM-KW41Z/FRDM-KW41Z_CharacterLCD at master · ErichStyger/mcuonecl... 

pastedImage_2.png

It still will need some tweaking and for sure is not perfect. But I hope this is something useful for you?

If time permits, I'll write an article in the blog about it.

I hope this helps,

Erich

3,207 Views
steve9
Contributor III

Thanks Erich. That's very kind of you!

The project built OK and downloaded to my board with no errors and the RGB LED is flashing on/off green. I haven't quite worked out all the connections between the KW41Z and the LCD, though. The way the code was generated doesn't make it clear which pins are mapped onto RS, E, D4-7. The photo helps but not quite enough! Any chance you could provide the pinout?

Hopefully you'll find another use for the board anyway. With best wishes.

Steve

0 Kudos
3,207 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

I have extended the driver to support both 4bit and 8bit GPIO data bus connections.

All the new files and example for it are on GitHub: mcuoneclipse/Examples/MCUXpresso/FRDM-KW41Z/FRDM-KW41Z_CharacterLCD at master · ErichStyger/mcuonecl... 

My LCD uses/has a the RW signal, so you need to check what you have on your hardware.

The display settings (number of lines, signals, ...) are configured in McuLib/config/McuHD44780config.h. There are dedicated configuration files in that folder for each pin (depending on which pins you are using.

I hope this helps,

Erich

3,207 Views
BlackNight
NXP Employee
NXP Employee

Hi Steve,

I used the MCUXpresso Pins tool to configure the pins, so you see all the pin assignment in the pins tool (see Tutorial: Muxing with the New NXP Pins Tool | MCU on Eclipse  if you are not familiar with it).

On top of that: the pins are configured in the *.config.h header files. You find them in the McuLib\HD44780 folder (they will be moved to the McuLib/config folder in a next version I'm working on ).

For example I have the RS pin on GPIOC, pin 5:

pastedImage_2.png

I hope this helps,

Erich

3,207 Views
steve9
Contributor III

My error with the Pins tool was not realising that by default, it had opened the Pins configuration for a different project (from the last time I had used Pins). On my laptop, the little drop-down menu at the top (to choose which Eclipse project to configure) was almost hidden and only the first few characters of the project name were visible.

0 Kudos
3,207 Views
BlackNight
NXP Employee
NXP Employee

It sounds like you did not use the version integrated in the MCUXpresso IDE? Because this one really makes it easy as it knows the project I'm working on.

0 Kudos
3,207 Views
steve9
Contributor III

I'm using MCUX 10.3 with the integrated Pins tool. I open the Pins tool and select Project A, and make some settings for Project A. Then I decide to work on Project B so I go back to the Develop perspective and click on Project B and open some files. Then I decide to look at the Pins settings for Project B so I click on the Quick Access button to open the Pins perspective again but the Pins perspective still shows the Pins settings for Project A. There is a little drop-down near the top left of the screen to select the project for the Pins tool, but I didn't notice this at first. My mistake but, on my laptop, the little dropdown is small and if the project names are similar, it's easy to miss.

0 Kudos
3,207 Views
BlackNight
NXP Employee
NXP Employee

Ok, I see now what you mean.

I did not had that because I usually use the small drop down in the Project Explorer view:

pastedImage_1.png

0 Kudos
3,207 Views
steve9
Contributor III

Hi Erich

It's very nearly working. Just missing the first 9 characters of Line 1. Any ideas?

Thanks

SteveIMG_4472.JPG

0 Kudos
3,207 Views
BlackNight
NXP Employee
NXP Employee

Are you sending the "LCD Line 1", but only get "1"? It might be that there is an extra delay needed. Does it work if you step over it with the debugger?

0 Kudos