7-Segment Common Cathode LED Display Counter using 8051 MUC

To use this code of 7-Segment Common Cathode LED Display Counter using 8051 MUC, fix a Common Cathode type 7-segment LED display on a breadboard and connect its pins to PORT2 in following sequence:
P2^1 – a, P2^2 – b, P2^3 – c, P2^4 – d, P2^5 – e, P2^6 – f, P2^7 – g, and then connect the GROUND terminal of the display to -ve terminal of your dev. board. Remember that P2^0 should be left open.

#include <reg51.h> // reg52 header file included
#include "delay.c" // customised delay file included
#define Display P2 // PORT2 is assigned to 'Display'

	void main()	// main function started
	{ // opening brace of main function

	int i; // variable for counting 10 cases
	Display=0xFF; // display shows '8' initially
	delay(200);

	while(1)
	{
	for(i=0;i<11;i++)
	{
	delay(500);	

	switch(i)
	{
		case 0: 
		Display=0x3F; // '0' is dispalyed
		break;

		case 1:
		Display=0x06; // '1' is dispalyed
		break;

		case 2:
		Display=0x5B; // '2' is dispalyed
		break;

		case 3:
		Display=0x4F; // '3' is dispalyed
		break;

		case 4:
		Display=0x66; // '4' is dispalyed
		break;

		case 5:
		Display=0x6D; // '5' is dispalyed
		break;

		case 6:
		Display=0x7D; // '6' is dispalyed
		break;

		case 7:
		Display=0x07; // '7' is dispalyed
		break;

		case 8:
		Display=0x7F; // '8' is dispalyed
		break;

		case 9:
		Display=0x6F; // '9' is dispalyed
		break;
	} // switch closed
	} // 'for' loop closed

	} // while closed
	} // main function closed

Note: Download the file of delay.c mentioned in the above program, from following link and copy it in your project folder.

[download id=”2″]

Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *