Swordfish Module - 7 Segment Display (Single)

This is a very limited example of segment displays. For full functionality and extended library support, please go to the multiple segment display tutorial.

 

7 segment displays are a cheap and effective way to display data. The only real downsides to them are;

  • Unable to retain data if more than one display is used (ie, need to continually refresh each segment display)
  • Require many Pins to interface (7 for one display, 16 for two and so on)

The data that they display can be manipulated so that the same 7 data lines can multiplex information onto other displays at the same time. This can be seen in the Multiple section. But for now, and future routines, this diagram illustrates how to connect a common cathode 7 segment display to a PIC micro.

 

18F7seg11

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.

single211single111


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.


The chances of creating an application that only need a single segment display are fairly limited, but none the less, I made a Swordfish User Library (Single Segment Display Library) to make it very easy to interface with. Here's an example of the library, take note that you can define which port is in use;

 

Device = 18F452                        // declare what pic is in use
Clock = 20 // clock speed
 
Dim Variable1 as Byte // declare a variable to use later
 
#option Segment_Port = PORTB // define what port the segment is on
Include "Single7Seg.bas" // include the segment display library
Include "utils.bas" // include the utils library for "digit"
// function
 
Variable1 = 0 // initialize settings
 
While True // create an infinite loop
Update(Digit(Variable1,1)) // display the 1st digit of the variable
DelaymS(1000) // wait of 1 second
Inc(Variable1) // increment the variable
Wend

 

The "Update" procedure will decode a single digit from 0-9 and display the relevant data on the segment display, easy.

Forum Activity

Member Access