-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdianji.c
More file actions
104 lines (88 loc) · 1.23 KB
/
Copy pathdianji.c
File metadata and controls
104 lines (88 loc) · 1.23 KB
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
//直流电机PWM调速系统设计
#include <reg52.h>
int i,d0,v;
int table[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit key1 = P3^5;
sbit key2 = P3^4;
sbit key3 = P3^3;
sbit key4 = P3^2;
void main()
{
int j,m1,m2,m3,m4;
d0 = 1;
v = 1;
m4 = 1;
P1 = 0xff;
TMOD = 0x01;
TH0 = 0xff;
TL0 = 0x9c;
EA = 1; //开中断
ET0 = 1; //允许定时器0中断
TR0 =1 ; //启动定时器0
while(1)
{
P0=table[m1];
P2_0 = 0;
for(j=0;j<20;j++);
P2_0 = 1;
P0=table[m2];
P2_1 = 0;
for(j=0;j<20;j++);
P2_1 = 1;
P0=table[m3];
P2_2 = 0;
for(j=0;j<20;j++);
P2_2 = 1;
P0=table[m4];
P2_3 = 0;
for(j=0;j<20;j++);
P2_3 = 1;
if(key1==0)
{
while(key1==0);
d0 = !d0;
m2 = !m2;
}
if(key2==0)
{
v = 1;
m4 = 1;
}
if(key3==0)
{
v = 2;
m4 = 2;
}
if(key4==0)
{
v = 3;
m4 = 3;
}
}
}
void t0(void) interrupt 1
{
TH0 = 0xff;
TL0 = 0x9c;
i++;
if(i>=5)
i = 0;
if(i<v)
{
if(d0==1)
P1_0 = 0;
else
P1_1 = 0;
}
else
{ P1_0 = 1;
P1_1 = 1;
}
}