A 7segment display is just a set of seven LED bars contained
A 7-segment display is just a set of seven LED bars contained in a convenient package, as shown below. They are generally provided in two different packages: common cathode (CC) and common anode (CA). The common-cathode package ties both the COM terminals together, which then needs to be connected to GND; each LED segment can be illuminated by applying positive voltage to the individual anodes (i.e. write a \'1\' to a port pin connected to that LED segment. The common-anode package ties both the COM terminals together, which then needs to be connected to Vcc; each LED segment can be illuminated by applying GND to the individual cathodes (i.e. write a \'0\' to a port pin connected to that LED segment. Your task is to write a complete C program that will continuously display numbers 0 to 9 on the 7-segment LED with a delay of 1 second between each display. You will use the following pin configurations: You should be able to find the 7-segment from your EGR106 toolkit. Make sure your program works on the hardware.
Solution
#include\"REGx52.h\"
#define seg_data P2
intnum=0;
void display_digit(int);
void delay(int);
void main()
{
while(1)
{
for(num=0;num<10 br=\"\" num=\"\"> {
display_digit(num);
delay(20000);
}
}
}
void delay(int x)
{
int i;
for(i=0;i}
voiddisplay_digit(int digit)
{
switch(digit)
{
case 0:
seg_data=0x3f;
break;
case 1:
seg_data=0x06;
break;
case 2:
seg_data=0x5b;
break;
case 3:
seg_data=0x4f;
break;
case 4:
seg_data=0x66;
break;
case 5:
seg_data=0x6d;
break;
case 6:
seg_data=0x7d;
break;
case 7:
seg_data=0x07;
break;
case 8:
seg_data=0x7f;
break;
case 9:
seg_data=0x6f;
break;
}
}

