Multiple LCDs on the SPI bus Print
Written by Jurij Mikeln   

Not long ago, I needed to drive multiple LCDs. There were several possibilities available. I could have used multiple microcontrollers – one for each LCD. Or I could choose a microcontroller with more output ports. Neither of the possibilities seemed economical or technically justified. My colleague Vlado showed to me a nice way to drive LCDs via the SPI bus [1]. Doing so also required a special library [1].

I was very pleased with that method, since it required only three microcontroller pins. A fourth pin was used to drive the LCD’s backlight. To test the concept, I fabricated a prototype PCB on our milling machine and the circuit immediately worked as expected. So, could this idea be extended to feeding multiple LCDs from a common SPI bus? Driving multiple LCDs via the SPI bus would seem to be ideal but, as we all know, nothing is as simple as it looks at the start. Specifically, the SPI LCD library was written for a single LCD only. That meant upgrading/changing the library file, which contains a lot of Assembly language. Upgrading the SPI LCD library file took some time, because I don’t routinely program in Assembly language. The focus of the library upgrade was to change one internal variable from a constant to a variable accessible by the Bascom program. I won’t elaborate on the details of the library file changes which I made: let’s focus on the schematic diagram shown in Figure 1.

I have used a common 16x2 LCD module. You will notice that a backlight module is used, driven by transistor Q1. The backlight can be permanently turned on by a means of jumper J1. In this circuit I have used a 74HC164D chip which is a serial to parallel converter. Connector Con1 should be connected to a development board (in my case, the MegaPin board). Using connector Con2 we can set the “address” of our module by connecting pin 6 of Con2 to one of the other pins. An example program, that demonstrates how to use the SPI LCD, follows:

Waitms 200
Cls
Lowerline                                 ‘all LCD commands work OK
Lcd “TEST LCD”
Waitms 300
#if Test = 0
En_lcd = 2 : Initlcd : Cls : Lcd “LCD”    ‘LCD display on PortA.2
#endif

The complete program and its associated library (multi_lcd-spi.lib) can be found on our web page. You must place the library file in the LIB directory or the program will not compile. Note that you must first set variable En_lcd correctly, before sending the data you wish to display on the LCD. For example if we want to display data on LCD1, then we set the value of to En_lcd = 1. It’s also important that each time we change the value of the En_lcd variable, we must use the Initlcd: Cls/statements. Note that if you change ports and En_lcd, you will also have to make suitable changes to the library file. Please contact the author for more information.

Multiple LCDs on the SPI bus

2012_AVR_UK_63

Continue reading


Shop area

Last Updated on Wednesday, 01 August 2012 14:47