-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.c
104 lines (89 loc) · 1.12 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,aa,bai,shi,ge;
sbit DU=P2^6;
sbit WE=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z);
void init();
void display(uchar bai,uchar shi,uchar ge);
void main()
{
init();
while(1)
{
if(aa==10)
{
aa=0;
temp++;
if(temp==255)
{
temp=0;
}
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
}
display(bai,shi,ge);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=112;y>0;y--);
}
void init()
{
WE=0;
DU=0;
temp=0;
aa=0;
bai=0;
shi=0;
ge=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void display(uchar bai,uchar shi,uchar ge)
{
DU=1;
P0=table[bai];
DU=0;
P0=0xff;
WE=1;
P0=0xfe;
WE=0;
delay(1);
DU=1;
P0=table[shi];
DU=0;
P0=0xff;
WE=1;
P0=0xfd;
WE=0;
delay(1);
DU=1;
P0=table[ge];
DU=0;
P0=0xff;
WE=1;
P0=0xfb;
WE=0;
delay(1);
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}