Current location - Education and Training Encyclopedia - Graduation thesis - 5 1 Single Chip Microcomputer Stopwatch Design
5 1 Single Chip Microcomputer Stopwatch Design
// 5 1 single-chip stopwatch, showing time 0000-9999 seconds, starting and stopping (starting and resetting again after stopping)

# include & ltreg52.h & gt

# Define uint unsigned integer

# Define uchar unsigned characters

Uchar code table []={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};

Ucal Bai and Shi;

uint a 1,a2;

sbit d 1=p3^0;

sbit d2=p3^ 1;

sbit d3=p3^2;

sbit d4=p3^3;

sbit key=p3^5;

sbit key 1=p3^7;

Bit? j;

uint? y;

void main()

{

TMOD = 0x 0 1;

TH0 =(65536- 10000)/256;

TL0 =(65536- 10000)% 256;

EA = 1;

ET0 = 1;

TR0 = 1;

White = 0;

Shi = 0;

while( 1)

{

if(key==0)

{

j = 0;

}

if(key 1==0)?

{

j = 1; a2 = 0;

}

}

}

Invalid timer 0 () interrupt 1

{

TH0 =(65536- 10000)/256;

TL0 =(65536- 10000)% 256;

a 1++;

y++;

if(a 1== 100)?

{

a 1 = 0;

if(j== 1)? a2++;

if(a2 & gt; = 10000)a2 = 0; ?

}

d 1 = 1; D2 = 1; D3 = 1; D4 = 1;

if(y== 1)

{

p 1 = table[a2 % 10000/ 1000]; ?

D4 = 0;

}

If (y==2)

{

P 1 = table [a2%1000/100];

D3 = 0;

}

If (y==3)

{

P 1 = table [a2%100/10];

D2 = 0;

}

If (y==4)

{

P 1 = table [a2%10]; ?

d 1 = 0;

y = 0;

}

}