18F Multiple 7 Segment Displays

    Pre-Notes:

  • LCD's don't require continual updates/multiplexing to display data, and require less Input/Output pins to interface with.
  • Using interrupts to multiplex will interfere with long delays and loops (eg, DelayMS(100) could take ~105ms to complete while multiplexing.

    For a brief overview on how a 7 segment display works, see the single 7 segment display example. Controlling multiple displays does add a new challenge to the situation, specifically the pin count required.

    If you were to wire up two displays to a PIC, each would require 7 pins, taking a whopping 14 pins all up to display two single digits of information. This is not a realistic option for most applications, and a better way to go about it is to multiplex the output pins.

    By controlling the common cathode, or common anode for each display, then you can control which display is actually "On or Enabled" and therefore display the data you want shown on that specific display. Do that at 25+ Hz and it will be nearly undetectable to the human eye that each display is turning on and off.

 

 

Note the PIC's power supply/oscillator are not shown

    The above diagram illustrates two displays being controlled via multiplexing. The ULN2003 is used as it is an excellent high power single chip solution for switching peripherals. You can't just use the PIC to control the common cathode, as each output (pin) can sink or source up to 25mA, if the number 8 was displayed then every segment would be illuminated and this would (in most cases) exceed the specification.

    The box that the 7 segment is in represents the common. There are two types of 7 segment displays, common cathode and common anode. In my projects, I use common cathode displays. i.e.

    As you can see, to control any of the segments, a +ve signal is required, as they all share the same earth. aka common cathode. Check the data sheet from the manufacturer to see what Pins are allocated to what segments.

    I've created a User Library with Swordfish to make things a little simpler. Its basically an interrupt driven program that uses the ISRTimer.bas system library to service the multiplexing and data encoding for the segment displays. Here's an example of how to use the display with two segments. See the end of this tutorial for use with 1-4 segments.

Device = 18F452
Clock = 20
#option Segments = 2
#option Segment_Port = PORTC
#option Segment_1 = PORTD.4
#option Segment_2 = PORTD.5
#option DisplayInterval = 15

Include "7Seg.bas"

Dim Variable As Word


Variable = 0

While True
    DelayMS(1000)
    Inc(Variable)
    SegDisplay.Update(Variable)
Wend

    It is very user customizable, and can be used with single and multiple (up to 4) segment displays. Even the interval (multiplexing) speed can be modified to compensate for brightness and flickering issues due to different clock speeds. That said, the default settings allow for normal operation between 10Mhz - 20Mhz without the need to change many settings at all.

    The available settings are (values added for example);

#option Segment_Port = PORTC           // Segment Output Data Pins
#option Segment_1 = PORTD.0            // Segment 1 Common Control Pin
#option Segment_2 = PORTD.1            // Segment 2 Common Control Pin
#option Segment_3 = PORTD.2            // Segment 3 Common Control Pin
#option Segment_4 = PORTD.3            // Segment 4 Common Control Pin
#option Segments = 4                   // Number of Segment Displays in use (1 to 4)
#option SingleDisplayRefreshTime = 500 // For use with single segment display
#option DisplayInterval = 10           // Time that each display remains on for

    It should be noted that  SingleDisplayRefreshTime is only for use when a single segment is used. It determines how long between update intervals for data to be displayed on the display, where as DisplayInterval is controls the time that each segment remains on while multiplexing with 2 or more displays.

     Video Tutorials:

    Download Spency's 7 Segment User Library Module

    Link: What is a Swordfish Library?

 

Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Collapse 18F PIC Examples18F PIC Examples
LED's
Switches
Expand 7 Segment Displays7 Segment Displays
LCD's
Collapse 7 Segment Displays7 Segment Displays
Single (User Library)
Multiple (User Library)
ADC
ADC (Another Example)
EEPROM's
DS1307
Expand RS232 and UARTRS232 and UART
DS18B20
External ADC
Hall Effect Sensor
Pulse Width Modulation (PWM)
Infrared UART
Swordfish Modules
Expand Code SnippetsCode Snippets
Expand Handy TipsHandy Tips