PIC16F877 and a 7 segment display

In this example we will show you how to connect a 7 segment display to our PIC16F877. You can think of a 7 segment display as 7 individual LEDs in a configuration like the picture below.

Image 1 shows the layout and image 2 shows how the segments are arranged

7 seg Blank

So by lighting certain segments you can display numbers, so for example to display the number 1 you would light segments B and C. Here are more examples

7 segment

In this example we connect a HDSP-C3Y3 common anode display to our ATmega16, you can see the connections in the schematic below. We basically connect up segment A to PD0, segment B to PD1 and so on.

Schematic

PIC16F877 and seven segment

Code

The code was written in mikroC pro for PIC

 

[codesyntax lang=”c”]

int main(void)
{
TRISD = 0x00; // Configure port D as output
while(1)
{


PORTD = 0xC0; // Display Number 0
delay_ms(1000); // Wait for 1s
PORTD = 0xF9; // Display Number 1
delay_ms(1000); // Wait for 1s
PORTD = 0xA4; // Display Number 2
delay_ms(1000); // Wait for 1s
PORTD = 0xB0; // Display Number 3
delay_ms(1000); // Wait for 1s
PORTD = 0x99; // Display Letter 4
delay_ms(1000); // Wait for 1s
PORTD = 0x92; // Display Letter 5
delay_ms(1000); // Wait for 1s
PORTD = 0x82; // Display Letter 6
delay_ms(1000); // Wait for 1s
PORTD = 0xF8; // Display Letter 7
delay_ms(1000); // Wait for 1s
PORTD = 0x80; // Display Letter 8
delay_ms(1000); // Wait for 1s
PORTD = 0x90; // Display Letter 9
delay_ms(1000); // Wait for 1s
}
}

[/codesyntax]

 

Links

 

wholesale 50pcs/lot 1bit Common Cathode/Common Anode Digital Tube 0.56″ 0.56in Red LED Digit 7 Segment

20 PCS LD-3161BG 1 Digit 0.36″ GREEN 7 SEGMENT LED DISPLAY COMMON ANODE

Related posts

DsPIC30F4011 Development Board OLED example

DsPIC30F4011 Development Board push button example

DsPIC30F4011 Development Board flashing LED example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More