Skip to content

Matrix Orbital

Personal tools
You are here: Home » Application Notes » I2C » I2C using an 8051

I2C using an 8051

Document Actions
This is a very simple example of using I2C to talk to a Matrix Orbital Display, using a C8051F005. The code is written in Dunefield Micro C.
Communication Type: I2C
Display Used: Any Matrix Orbital display that supports I2C such as the MOI or LK/VK/PK series.

In this example we are talking to a display at address 50 hex over I2C communication protocol.


// 11/4/04 First test run of I2C bus.
// Display something on the LCD.

// Memory model = 3, use medium.lib, SDA = P0.0, SCL = P0.1

#include "config.h" //This library configures the I/O ports, interrupts, timers, etc.
#include <8051int.h>
//moves data to/from stack before/after interrupt service routines
#include "macros.h"
//Dunfield macro library - eg: clrbit() uses this

main()
{
configure();
setbit(P1.6);

clrbit(SMB0CN.4);
//stop flag
setbit(SMB0CN.5);
//Start condition
clrbit(SMB0CN.5);
//clear start flag to prevent false starts

while (!tstbit(SMB0CN,3)) {} //interrupt occured?
SMB0DAT = 0x50;
//address of LCD
clrbit(SMB0CN.3);
// clear the interrupt flag

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 254;
//command to LCD
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 88;
//Clear Display
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 'H';
//now send ASCII data
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 'e';
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 'l';
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 'l';
clrbit(SMB0CN.3);

while (!tstbit(SMB0CN,3)) {}
SMB0DAT = 'o';
clrbit(SMB0CN.3);

while (tstbit(SMB0CN,7)) {} //wait until the bus is free
setbit(SMB0CN.4);
//Stop condition
clrbit(SMB0CN.3);



A special thanks to Ben Lennard for this great example, please visit his website for more electronics examples. For technical discussions and questions, please visit our forums
Created by Henry
Last modified 2007-11-02 09:11 AM
 

Powered by Plone

This site conforms to the following standards: