You are on page 1of 3

# // This Program will display 0 - 9 simultaniously # include <reg51.

h> // THE pin a OF seven 8051 // THE pin b OF seven 8051 // THE pin c OF seven 8051 // THE pin d OF seven 8051 // THE pin e OF seven 8051 // THE pin f OF seven 8051 // THE pin g OF seven 8051 // Connect the common // This seven segment configuration // for common cathode // Header for AT89C51 you must use it segment display is connected to pin P2^0 of segment display is connected to pin P2^1 of segment display is connected to pin P2^2 of segment display is connected to pin P2^3 of segment display is connected to pin P2^4 of segment display is connected to pin P2^5 of segment display is connected to pin P2^6 of pin of seven segment to +5 V. function will only work for common anode calculate the hex valuse by your own

void seven_segment(int); // Seven Segment Function Declaration void delay(); // Delay Function Declaration void delay(int a) // Delay Function Defining { int i; for(i=0;i<a;i++); } void seven_segment(int x) function { P2=0xff; switch(x) { case 0: // { P2=0xC0; break; } case 1: // { P2=0xF9; break; } case 2: // { P2=0xA4; // Declaration Of seven segment

Case for 0

Case for 1

Case for 2

} }

break; } case 3: { P2=0xB0; break; } case 4: { P2=0x99; break; } case 5: { P2=0x92; break; } case 6: { P2=0x82; break; } case 7: { P2=0xF8; break; } case 8: { P2=0x00; break; } case 9: { P2=0x90; break; }

//

Case for 3

//

Case for 4

// Case for 5

// Case for 6

//

Case for 7

//

Case for 8

// Case for 9

main () { int i=0; while(1) { seven_segment(i); // call seven segment function and pass the BCD value to display delay(10000); // delay i++; if(i==10)

} }

i=0;