Jump to content

C code for 2 line x 16 char LCD


Larry Bank

Recommended Posts

This may be useful to some of you. I wrote some C code to talk to those common 2x16 LCD displays that are available in various colors from various vendors. My purpose in writing the code was to learn about the device and help document it better for other people to have an easier time using it. In my search for info, I only found poorly documented Python and Arduino code, so I thought I would write a C version and make it easy to read. You can find the code here:

 

https://github.com/bitbank2/LCD1602

 

lcd1602.jpg

Link to comment
Share on other sites

2x16 I2C interface?  Interesting.  I was confused until I saw the picture, the HD44780 interface for those now has a kernel driver.  :D  I need to look at it and see if it can be run in 4-bit mode or if it has to go 8-bits wide.  I've been lazy, I have a drawer full of the parallel displays...  (good and cheap, and I'm usually using Cypress PSoC 5 controllers with tons of I/O)

Link to comment
Share on other sites

5 minutes ago, TonyMac32 said:

2x16 I2C interface?  Interesting.  I was confused until I saw the picture, the HD44780 interface for those now has a kernel driver.  :D  I need to look at it and see if it can be run in 4-bit mode or if it has to go 8-bits wide.  I've been lazy, I have a drawer full of the parallel displays...  (good and cheap, and I'm usually using Cypress PSoC 5 controllers with tons of I/O)

All of the ones I've been able to find on eBay and Aliexpress have the HD44780 paired with a simple I2C I/O expander. It just acts as a shift register and passes every write straight through to 8 data pins. The LCD can operate in 4-bit mode by sending a command of 2Xh - bit 4 sets the data bus width (see here https://learningmsp430.wordpress.com/2013/11/16/16x2-lcd-interfacing-in-4-bit-mode/). It allows having just the upper 4 data bits connected and the lower 4 bits from the I/O expander are used as control lines.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines