0% found this document useful (0 votes)
45 views2 pages

7 Segment Display C Code

Uploaded by

Junaid Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

7 Segment Display C Code

Uploaded by

Junaid Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <reg51.

h>

sbit SEGMENT = P2; // Define 7-segment display on Port 2

// Look-up table for numbers 0-9 on a 7-segment common cathode display

unsigned char code lookup[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

// Function to introduce a delay

void delay() {

int i, j;

for (i = 0; i < 250; i++)

for (j = 0; j < 250; j++);

void main() {

char count;

while (1) {

// Reverse counter from 9 to 0

for (count = 9; count >= 0; count--) {

SEGMENT = lookup[count]; // Display count on 7-segment

delay(); // Delay to control display speed

}
#include <8051.h>

unsigned char segment_table[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,
0x7F, 0x6F}; // Segment codes for 0-9

void delay() {
unsigned int i;
for(i = 0; i < 30000; i++); // Basic delay loop
}

void main() {
unsigned char count = 9; // Start count from 9
while (1) {
P1 = segment_table[count]; // Display current count on 7-segment
delay(); // Wait
if (count == 0) // If count reaches 0, restart
count = 9;
else
count--; // Decrement count
}
}

You might also like