2 Digit 7-Segment Up Down Counter Project using 8051 Microcontroller

· 8051 MICROCONTROLLER

DESCRIPTION

In this circuit 2 seven segment are used to show the value of count using 8051 microcontroller. The maximum value of count is 99 because 2 seven segments are used. In this circuit we are using 8051-microcontroller, 2 common cathode seven segments, 2 switches for up counting button & down counting button.

7-Segments are connected to P2 & P3 ports of the 8051 microcontroller. UP counter button is connected with P1.6 and down counter button is connected with P1.7.Whenever the UP counter button is pressed the counter increments by one and when the down counter button is pressed it gets reduced by one.

CODE

#include< reg51.h >
sbit h=P1^6; //up counter button
sbit g=P1^7; //down counter button
int m=0;
int n=0;
int a,b;
int arr[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0xFF,0x67};
void main()
{
P2=0x3F;
P3=0x3F;
while(1)
{
P1=0xFF;
if(h==0)
{
if(n==99&&m==99)
{
P2=0x67;
P3=0x67;
}
else
{
m=m+1;
n=n+1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(h==0);
}
}
if(g==0)
{
if(n==0&&m==0)
{
P2=0x3F;
P3=0x3F;
}
else
{
m=m-1;
n=n-1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(g==0);
}
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 346 other followers

%d bloggers like this: