Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

LCD to I2C assembly code for board with PCF8574

I saw many posts looking for this code in assembly


but did not find even one example. So I am uploading it
for those like me who are "C" challenged.

Boards available on ebay for under $1 (see photo in zip file)


this code works with the default address (no mods to board)
i.e. A0, A1, A2 all high or untouched.

In this zip file you will find two versions of I2C,


A hardware version using the TWI and a software version using
bit bang I2C routines from avr300.asm

There is a version of each using avrasm2 or


if you prefer, an avrstudio project.

I don't have an LCD with a backlight so I didn't include this.


You can just uncomment the lines (see the source code)

There is no error checking in this version.

This code doesn't read I2C or LCD, just writes.


So the delays implemented can be shortened. The way it is now
it is very reliable.

Keep it simple, it works for me and is about 5 times


smaller than the "C" code just to do the same thing!

Works on any atmega328p with 16MHz crystal.


Tested in arduino UNO R3 and Arduino NANO.

You can include the bootloader.inc file if you want to program


using the bootloader.
(just uncomment the lines at the bottom of the main code)
before you assemble the code.

I included my batch file for avrdude using usbasp.

Be sure to program fuses:


FuseL: 0xFF
FuseH: 0xDE
FuseExt: 0xFD

Arduino UNO R3 pins or


Arduino NANO pins
connect SDA to A4
connect SCL to A5
connect 5V and GND

on atmega328p
SCL = Pin 28 (PC5)
SDA = Pin 27 (PC4)

There are probably a million better (more efficient) ways to do


some of the bit manipulation, but this works for me.

I did this while I was recovering from surgery, forbidden by my doctor


to go to work or to the gym.
Any advice or questions feel free to
msg me if @ avrfreaks.

newbie123

You might also like