I2C to LCD Backpack

I was planning a small project that would require output to a four line, character LCD.  Normally, I would have used my SPI to LCD backpack board but the SPI on the micro was also been used by port pins that I needed, however the IIC interface pins were available.  Since I had already written the I2C software for the DS1307 and serial EEPROMs I decided to get a I2C LCD backpack.  I developed the code on a 9S08JM60 version of the Firebird32 but it will be ported to a smaller board eventually.  
Click for larger view

Hardware

I purchased the I2C to LCD backpack from Adafruit.  The backpack is described in great detail here.  There is a similar unit from ElectroDragon except it also has 2x8 header along the side for LCDs that use that connection.

Actually, by soldering a jumper it can be converted to a SPI backpack.  But because the output pins on the 74HC595 are connected to different LCD pins the software from my SPI to LCD project would have to be modified somewhat.

Click for larger view

Software

The software is written for the 9S08JM60 but is easily ported to most 9S08 or MC68HC08 chips (except those where IIC registers are in high-page memory like the 9S08SV16; email me if you need code for those).

Most of my software has been written with the P&E assembler but this time I used the CW absolute assembler.  Here is the code.

Click for larger view I needed a LCD for a project I was designing but had limited space; I thought I would have to make do with a one or two line display.  But I found this 4 line by 20 character display that is smaller than most 4 line LCDs.  The CFAH2004D-YYH-ET from Crystalfontz is 77 mm x 47 mm.  After I got it I was pleasantly surprised to find that its character ROM had mostly Latin characters in it upper half unlike most that have Japanese characters.  My software maps out several dozen of these characters.
Click for larger view

Benchmarks

I tested the speed of the Firebird32  9S08JM60 vs. an Arduino.  My program is in assembly but it does a lot of formatting that is not used in this simple benchmark.  The display is cleared then four lines are written to the LCD.  This is looped 100 times and timed.  The Arduino code is to the left.

The 9S08JM60 took 31 seconds; the Arduino took 127 seconds.

/*
 Demonstration sketch for Adafruit i2c/SPI LCD backpack
 using MCP23008 I2C expander
 ( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )

  The circuit:
 * 5V to Arduino 5V pin
 * GND to Arduino GND pin
 * CLK to Analog #5
 * DAT to Analog #4
*/

// include the library code:
#include <Wire.h>
#include <LiquidCrystal.h>

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);

void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(20, 4);
  lcd.setBacklight(HIGH); 
}

void loop() {
  for (int i = 0; i<100; i++){
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ABCDEFGHIJKLMNOP");
    lcd.setCursor(0, 1);
    lcd.print("0123456789012345");
    lcd.setCursor(0, 2);
    lcd.print("ABCDEFGHIJKLMNOP");
    lcd.setCursor(0, 3);
    lcd.print("0123456789012345");
    }
  lcd.setBacklight(LOW);
  while(1);
  }
 

For BDM's

  Lowest cost.

The 9S08 family is programmed using a Background Debug Module and Code Warrior.  CW can be downloaded from the Freescale website.

 

Roger's Embedded Microcontrollers Home Page     


This page written by Roger Schaefer. Last updated August 20, 2012