Jose Pino's projects & tidbits
"Great stuff from someone with an inquisitive mind"

Charlieplexing 7-segment LED display.

Also known as "Multiplexing", here is a method how to control eight 7-segment displays using only 9 microcontroller ports. (August 20, 2009)


Source: http://www.josepino.com/?charlieplex-7segment-display   Tags: microcontroller howto

Charlieplexing is a technique proposed in early 1995 by Charlie Allen at Maxim Integrated Products for driving a multiplexed display in which relatively few I/O pins on a microcontroller.1 I saw for the first time the Maxim application notes back in 2005 but I was not able to create a software to use a 'Charlieplexed' display. Today, I did finish an algorithm to be able to control eight 7-segment LED display using 8 pins from a microcontroller, 9 pins if decimal point required.

Let's see the schematic:
Taken from http://www.josepino.com

Charlieplexed 7-segment display

Each pin, from B0 to B7 is connected directly to the common anode or common cathode of the 7-segment LED dsplay, the others pins are connected to control the segments of each display.

Each display is connected as follows:
First: B0-CC/CA, B1-A, B2-B, B3-C, B4-D, B5-E, B6-F, B7-G, A0-DP
Second: B0-A, B1-CC/CA, B2-B, B3-C, B4-D, B5-E, B6-F, B7-G, A0-DP
Third: B0-A, B1-B, B2-CC/CA, B3-C, B4-D, B5-E, B6-F, B7-G, A0-DP
Fourth: B0-A, B1-B, B2-C, B3-CC/CA, B4-D, B5-E, B6-F, B7-G, A0-DP
Fifth: B0-A, B1-B, B2-C, B3-D, B4-CC/CA, B5-E, B6-F, B7-G, A0-DP
Sixth: B0-A, B1-B, B2-C, B3-D, B4-E, B5-CC/CA, B6-F, B7-G, A0-DP
Seventh: B0-A, B1-B, B2-C, B3-D, B4-E, B5-F, B6-CC/CA, B7-G, A0-DP
Eighth: B0-A, B1-B, B2-C, B3-D, B4-E, B5-F, B6-G, B7-CC/CA, A0-DP

To display some data, we need to define the position and the data. Let's assume the first display is the left one and the last one is located at the right position. Here is the procedure to control this Charlieplexed display:

Define variable DATA
Define variable POSITION

if POSITION = 1
   port A0 = DATA BIT 7 ; shift all bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   DATA BIT 4 = DATA BIT 3
   DATA BIT 3 = DATA BIT 2
   DATA BIT 2 = DATA BIT 1
   DATA BIT 1 = DATA BIT 0
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B0 as output
   PORT B = DATA
   PORT B0 = 0 ; 0 for Common cathode
end if
if POSITION = 2
   port A0 = DATA BIT 7 ; shift 7 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   DATA BIT 4 = DATA BIT 3
   DATA BIT 3 = DATA BIT 2
   DATA BIT 2 = DATA BIT 1
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B1 as output
   PORT B = DATA
   PORT B1 = 0 ; 0 for Common cathode
end if
if POSITION = 3
   port A0 = DATA BIT 7 ; shift 6 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   DATA BIT 4 = DATA BIT 3
   DATA BIT 3 = DATA BIT 2
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B2 as output
   PORT B = DATA
   PORT B2 = 0 ; 0 for Common cathode
end if
if POSITION = 4
   port A0 = DATA BIT 7 ; shift 5 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   DATA BIT 4 = DATA BIT 3
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B3 as output
   PORT B = DATA
   PORT B3 = 0 ; 0 for Common cathode
end if
if POSITION = 5
   port A0 = DATA BIT 7 ; shift 4 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B4 as output
   PORT B = DATA
   PORT B4 = 0 ; 0 for Common cathode
end if
if POSITION = 6
   port A0 = DATA BIT 7 ; shift 3 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B5 as output
   PORT B = DATA
   PORT B5 = 0 ; 0 for Common cathode
end if
if POSITION = 7
   port A0 = DATA BIT 7 ; shift 2 bits
   DATA BIT 7 = DATA BIT 6
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B6 as output
   PORT B = DATA
   PORT B6 = 0 ; 0 for Common cathode
end if
if POSITION = 8
   port A0 = DATA BIT 7 ; shift 1 bit
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   set PORT B7 as output
   PORT B = DATA
   PORT B7 = 0 ; 0 for Common cathode
end if
Please be aware the above listing IS NOT A PROGRAM or written in any specific programming language. It's only an explanations of the steps needed to control a Multiplexed 7-segment LED display.

Let's see how it works:

Five with 7 segment display If we are going to display the number 5 at the fifth display, we need to set the DATA variable as 01101101 [binary] because each segment gets the binary value as: A=1, B=0, C=1, D=1, E=0, F=1, G=1, DP=0

Then, we need to process the variable DATA as indicated when the POSITION = 5:

   port A0 = DATA BIT 7 ; shift 4 bits
   DATA BIT 7 = DATA BIT 6
   DATA BIT 6 = DATA BIT 5
   DATA BIT 5 = DATA BIT 4
   set PORT B as input where data bit = 0
   set PORT B as output where data bit = 1
   PORT B = DATA
   PORT B4 = 0 ; 0 for Common cathode

Result of charlieplexing

So, we get the variable DATA as 11001101 after shifting 4 bits, then it is sent to the port B and the bit 4 is set as 0. The PORT B will be 11x011x1 were x = Input port or Hi-Z.

The left picture shows the result of the process.

The main advantage, and the only one, of Charlieplexing is that only 9 IO ports are used for eight displays. The problems that can be presented are:

  • The refresh rate for each LED must be greater than 50Hz. This is to avoid flickering.
  • The port used for charlieplexing should be tri-state.
  • The forward voltages of the LEDs should be the same on each one. This will avoid other LEDs to lit when it's not intended.
  • The reverse voltage of the LED should be greater than the voltage used for the display. If a single LED fails, either by becoming an open circuit, by becoming a short-circuit, the impact will be catastrophic for the display.

  • For more information about Charlieplexing or multiplexing multiple LEDs, here is an article that I wrote back in 2006.

    References:
    1 Wikipedia

    < Cat Carrier Complaint.   Home   Cheap products are expensive.>

    Share your comments and experience:
    Keep it short, Comments with bad words, spam and non-related will be deleted.

    Name:   Location:
    Captcha:   <-- This is the Captcha
    Your Comments:

    Bookmark or Bookmark and Share Suscribe to RSS Feeds

    10 most viewed pages:

    - How To Make a Speaker
    - Hi-fidelity Homemade Loudspeaker.
    - Tachometer/RPM II.
    - Homemade WiFi Lid Antenna.
    - Super Simple Sun Tracker.
    - Led Clock
    - USB LED Light.
    - How To Repair Sony PSP
    - Knowing Everything.
    - Matrix Led Display.

    Articles related:

    - Getting Started with PICs.
    - ADC without ADC.
    - Charlieplexing 7-segment LED display.
    - How To Control Multiple Leds
    - How to get 1 Second with Microcontrollers.
    - ON/OFF with Microcontrollers.

    All categories:

    - about
    - advertisement
    - audio
    - automobile
    - bad_ones
    - best
    - circuits
    - computer
    - discover
    - diy
    - electronics
    - fail
    - food
    - from_readers
    - funny
    - furniture
    - hacks
    - homemade
    - how_it_works
    - howto
    - humor
    - interesting
    - lego
    - light
    - microcontroller
    - mysql
    - opinion
    - php
    - projects
    - readings
    - realmeal
    - religion
    - robots
    - science
    - scripts
    - trips
    - videos
    - websites
    - woodworking


    Mr. Counter says: 1685 views.

    Search Article

    Additional Links:

    - Mary's Creations.
    - Publicidad Gráfica.
    - Todito Yucatán
    - Lucina Castillo's Art
    - Conoce Amigos en Dalnet
    - Narciso González' Alebrijes

    Need to contact me?
    e-mail address
    Please get a good reason before sending me an e-mail.

    IE, Firefox, SeaMonkey & Opera tested OK, Some features may not work with Google Chrome. © 2006 - 2009 José Pino - JPC-PHP V5.0
    If any information, data, picture or design infringes a copyright material, please send me an e-mail asking to remove it along with the supporting data.