for Microchip PICs

Home - About- Consulting* - Articles - FAQs - Contact
Tour - Application Example - Sub circuits - Projects - Download
Projects: I2C slave Multiplexed Display
This QuickBuilder project can be downloaded here. The hex code can be downloaded here.

I2C slave Multiplexed Display (Turnkey project)

This project demonstrates a multiplexed display with I2C interface.

The sub-circuits used in this project are:
- 'I2C slave RAM'
- 'Display 4-dig 7-seg (com anode)
- '3-bit port'

The target device is a PIC16F872 with crystal clock running at 4.0MHz.

The industry standard I2C bus opens the way for modular design offering cross-platform support and re-usable design. This project can be used as a framework for other I2C slave devices and can also be a sub-circuit in its own right, an example of which is the 'I2C 4-dig mux display' sub-circuit.

Looking from the outside the I2C interface appears as a 2-byte RAM device. The 4-digit multiplexed display is updated by simply writing data to location 0 of the I2C RAM. When the RAM is written to, it sets a flag indicating that new data has arrived, the foreground programme (main programme loop) detects this event and carries out the required task, in this case, updating the display.

The following operations can be carried out when writing to the 'I2C slave RAM' device:

Address / Data / Operation
0 / 0 / Clear display
0 / 1 / Home cursor
0 / n / Print character to display i.e. '0123456789.-Er<space><CR>'

A read may be made from address 0 over the I2C bus as confirmation of a successful write.

The 'I2C slave RAM' can be configured to have more memory at design time and can have any family address and any device address. The '3-bit port' effectively overwrites the device address at run time and this facilitates hardwired addressing of the I2C. See 'ADD_' on the design sheet.

Application code
Below is the application code for this project. To use it, select and copy (ctr-insert) the code below and past it into a text editor and save as a 'C' file in your working directory. You may also need to change the build output path using 'Project | Options'

////                           AI2CMUXD.C                          ////
////                                                               ////
////  Demo application of simple 4-digit multiplex 7-segment       ////
////  display with i2c interface.                                  ////
////                                                               ////
////  Use the i2c interface to write digits to the display.        ////
////  The i2c interface behaves as a 2 byte i2c slave RAM.         ////
////  Writing data to address 0 will write a digit to the display. ////
////  See also sub-circuit 'I2C 4-Digit mux display'               ////
////                                                               ////
////  This program is an example of how your application code is   ////
////  is organised. Note the #include "i2cmuxd.c", this include    ////
////  file was generated by QuickBuilder and contains all          ////
////  dirver code.                                                 ////
////                                                               ////
////  This demo is intended for  a PIC16F872                       ////
////  Compile using CCS 'C'  visit www.quickbuilder.co.uk/qb/ccs   ////
#include <16f872.H>

#fuses hs,wdt,noprotect,put,nowrt,nolvp


#define PORTA 5 
#define PORTB 6
#define PORTC 7
#define TRISA 0x85 
#define TRISB 0x86
#define TRISC 0x87


#include "i2cmuxd.c"

void RTCC_ISR()
    MUXD_1DO();    // refresh display

main() {
    byte b;
    bit_clear(*trisc,7); // test output

    // initialise sub-circuits and rtcc interrupts

    // I2C set device address

    // power up test display
    // ---------------------
    printf(muxd_1putc,"");   // all on for 1/2sec
    for ( b=250; b!=0 ; b--) {delay_ms(2); restart_wdt();}
    muxd_1clear();                  // all off for 1/2sec
    for ( b=250; b!=0 ; b--) {delay_ms(2); restart_wdt();}        
	// main loop
    while(1) {

        // monitor i2c for updates
        if (  I2CSLRAM_1UPDATE == 2) {
            I2CSLRAM_1UPDATE = 0;   // clear i2c update flag
            if ( I2CSLRAM_1ADDR == 0 ) {
                b = I2CSLRAM_1DATA[0];
                if (b == 0 )
                else if (b == 1 )
        // poll i2c ram
Copyright 2002-2009 Summit Electronics Ltd