16F 7 Segment Display Example

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

  • Unable to retain data
  • Require many Pins to interface

    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 18F section. But for now, and future routines, this diagram illustrates how to connect a 7 segment display to a PIC micro. This may not be the same wiring diagram that other people have used, but in my projects, it will always be the same with the exception of the common cathode pin on the display.

Schematic

Single 7 Segment Display 

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

    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.

The following example shows how to decode a value between 0-9 into 7 segment data and display it.

Device 16F877

Xtal = 4

Dim Number As Byte

Initialization:

	ALL_DIGITAL = True
	PORTB_PULLUPS = False

	TRISB = %00000000               ' Make PORTB all outputs
	
Main:
	 
	 Number = 0

	 Repeat                                    ' Create a loop
		  		 
		 GoSub Encode_Segment_Display      ' Convert to segment data and display it
		 
		 DelaymS 500                       ' Small delay to slow down counting
		 Inc Number                        ' Increment the Number register
		  
	 Until Number = 10                         ' Loop until number = 10, then reset

	 Goto Main                                 ' Loop forever
	 
Encode_Segment_Display:

	SELECT Number
	    CASE 0                                 ' Turn Number into segment display data
	   		 PORTB = %00111111
	    CASE 1			
	   		 PORTB = %00000110
	    CASE 2			
			 PORTB = %01011011
	    CASE 3			
	   		 PORTB = %01001111
	    CASE 4			
	   		 PORTB = %01100110
	    CASE 5			
	   		 PORTB = %01101101 
	    CASE 6			
   			 PORTB = %01111100
	    CASE 7			
 			 PORTB = %00000111
	    CASE 8			
			 PORTB = %01111111
	    CASE 9			
 			 PORTB = %01100111		 
	ENDSELECT
	
	Return

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Collapse 16F PIC Examples16F PIC Examples
LED's
Switches
Keypads
LCD's
7 Seg Displays
ADC
DAC
Expand MotorsMotors
Expand ThermometersThermometers
DS1307 RTC Chip
DS275
EEPROM's
RF Modules
RGB LED's
Code Snippets
Expand Code SnippetsCode Snippets
Expand 18F PIC Examples18F PIC Examples
Expand Handy TipsHandy Tips