-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.0.c
47 lines (44 loc) · 1.24 KB
/
10.0.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
/********************************************************************
* 描述 : 继电器实验,按S19继电器吸合,按S18继电器释放。
* 杜邦线接法:P1.2用杜邦线连接到J17的左边第二个。
***********************************************************************/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^2;//定义按键位置,按了P3.2后继电器吸合
sbit key2=P3^3;//定义按键位置,按了P3.3后继电器释放
sbit RELAY = P1^1;
/********************************************************************
* 名称 : Delay_1ms()
* 功能 : 延时子程序,延时时间为 1ms * x
* 输入 : x (延时一毫秒的个数)
* 输出 : 无
***********************************************************************/
void Delay(uint i)
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
main()
{
while(1)
{
if(!key1) //按下相应的按键
{
Delay(15);
if(!key1) //去抖后是否按下相应的按键
{
RELAY=1; //继电器吸合
}
}
if(!key2) //按下相应的按键
{
Delay(15);
if(!key2) //去抖后是否按下相应的按键
{
RELAY=0; //继电器释放
}
}
}
}