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
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

 | Site Tutorial Index |
|  | 16F PIC Examples |
| |  | Motors |
| |  | Thermometers |
| |  | Code Snippets |
|  | 18F PIC Examples |
|  | Handy Tips |