gauravkothari23
Advanced Member level 2
Hi all....
i am trying to interface 2 digit x 3 seven segment with 89s52. one to show secounds, one for minute and one for hour. it works proper... the only thing is i does not stay stable.... i mean the display blinks. please help me where i am wrong
code is....
i am trying to interface 2 digit x 3 seven segment with 89s52. one to show secounds, one for minute and one for hour. it works proper... the only thing is i does not stay stable.... i mean the display blinks. please help me where i am wrong
code is....
Code:
#include<stdio.h>
#include<reg51.h>
unsigned char SetDisplay(unsigned char);
void delay();
sbit sec0 = P3^7;
sbit sec1 = P3^6;
sbit min0 = P3^5;
sbit min1 = P3^4;
sbit hour0 = P3^3;
sbit hour1 = P3^2;
unsigned char d0,d1,d2,d3,d4,d5;
unsigned char SetDisplay(unsigned char value)
{
unsigned char segment[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
if(value<=10)
return segment[value];
else
return 0;
}
//--------------
//Delay Function
//--------------
void delay()
{
int i;
for(i=0; i<1250; i++)
i = i + 0;
}
//--------------
//Main Program
//--------------
void main(void)
{
unsigned char count = 0;
unsigned long timer = 0;
int turn = 1;
// P2 = 0xff;
while(1)
{
if(turn==1) //7-Seg Display 0
{
sec0=1;
sec1=0;
min0=0;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2) //7-Seg Display 1
{
sec0=0;
sec1=1;
min0=0;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3) //7-Seg Display 2
{
sec0=0;
sec1=0;
min0=1;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d2);
turn = 4;
delay();
}
else if(turn==4)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=1;
hour0=0;
hour1=0;
P2=SetDisplay(d3);
turn = 5;
delay();
}
else if(turn==5)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=0;
hour0=1;
hour1=0;
P2=SetDisplay(d4);
turn = 6;
delay();
}
else if(turn==6)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=0;
hour0=0;
hour1=1;
P2=SetDisplay(d5);
turn = 1;
delay();
}
if(timer == 100)
{
d0++;
timer=0;
if(d0>=10)
{
d0=0;
d1++;
if(d1>=10)
{
d1=0;
d2++;
if(d2>=10)
{
d2=0;
d3++;
if(d3>=10)
{
d3=0;
}
}
}
}
}
timer++;
}
}