You are on page 1of 3

Prof.Manoj S.

Kavedia – 9860174297 – 9324258878 –


profmanojkavedia@gmail.com

Digital dice using 8051 microcontroller


(AT89C51)
// 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;
Prof.Manoj S. Kavedia – 9860174297 – 9324258878 –
profmanojkavedia@gmail.com

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;
}
Prof.Manoj S. Kavedia – 9860174297 – 9324258878 –
profmanojkavedia@gmail.com

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++;
}

You might also like