We are going to implement the same circuit (of seven segment interfacing)
with the exception that we are going to use four extra pins of the
microcontroller as input pins for stopping a dice at one position
(pause), starting it again from the same position (start) and starting
it from the beginning (reset) enabling the seven segment(enable).
The three pins i.e. P3^3 , P1^1and P3^2 of the microcontrollers are
made the input pins and assigned to variable reset, start and pause
respectively. The pin P1^0 is made output and assigned to variable
‘enable’. Whenever, there is a high given from the Vcc on the pause pin,
the seven segment displays the number and keep showing that number. As
soon as you give high on the reset pin, the seven segment starts
displaying the numbers from the beginning i.e. it starts again from
displaying numbers from one (1). As soon as you give high on the start
pin, the seven segment begins displaying the numbers starting from the
next number at it was paused. The seven segment displays the data
assigned to only and only when there is a high on its enable pin.
Circuit Diagram
Circuit Diagram
Source Code
// Program to make a digital dice
#include<reg51.h>
sbit reset=P3^3;
sbit start=P1^1;
sbit pause=P3^2;
sbit enable=P1^0;
int current=0;
char num[]={0xF9,0x24,0x30,0x19,0x12,0x02}; // Hex values corresponding to1to6
void delay(int time) // Function to generate time delay
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void pausefn()interrupt 0 //Pause function using external interrupt 0
{
IE=0x84;
P2=num[current];
while(1)
{
if( start==0 )
break;
if(reset==0)
{
enable=1;
current=0;
P2=num[current];
while(start==1);
return;
}
enable=1;
delay(25);
if( start==0)
break;
if(reset==0)
{
enable=1;
current=0;
P2=num[current];
while(start==1);
return;
}
enable=0;
delay(25);
}
enable=1;
}
void resetfn()interrupt 2 // Reset function using timer interrupt 2
{
current=0;
P2=num[current];
while(start==1);
enable=1;
}
void main()
{
enable=1;
while(1)
{
IE=0x85;
if(current >5)
{
current=0;
}
P2=num[current];
delay(15);
current++;
}
}