Skip to content

Commit 8dbf884

Browse files
committed
【完善】pin 引脚中断说明文档
1 parent a423844 commit 8dbf884

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

docs/04-Hardware_Control_Module/02-machine-Pin.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@
3838
#### **Pin.name**()
3939
返回引脚对象在构造时用户自定义的引脚名。
4040

41+
#### **Pin.irq**(handler=None, trigger=(Pin.IRQ_RISING))
42+
43+
配置在引脚的触发源处于活动状态时调用的中断处理程序。如果引脚模式是, `Pin.IN` 则触发源是引脚上的外部值。 如果引脚模式是, `Pin.OUT` 则触发源是引脚的输出缓冲器。 否则,如果引脚模式是, `Pin.OPEN_DRAIN` 那么触发源是状态'0'的输出缓冲器和状态'1'的外部引脚值。
44+
45+
参数:
46+
47+
- `handler` 是一个可选的函数,在中断触发时调用
48+
- `trigger` 配置可以触发中断的事件。可能的值是:
49+
- `Pin.IRQ_FALLING` 下降沿中断
50+
- `Pin.IRQ_RISING` 上升沿中断
51+
- `Pin.IRQ_RISING_FALLING` 上升沿或下降沿中断
52+
- `Pin.IRQ_LOW_LEVEL` 低电平中断
53+
- `Pin.IRQ_HIGH_LEVEL` 高电平中断
54+
4155
### 常量
4256

43-
下面的常量用来配置 `Pin` 对象。
57+
下面的常量用来配置 `Pin` 对象。
4458

4559
#### 选择引脚模式:
4660
##### **Pin.IN**
@@ -53,7 +67,16 @@
5367
##### **None**
5468
使用值 `None` 代表不进行上下拉。
5569

56-
### 示例
70+
#### 选择中断触发模式:
71+
##### **Pin.IRQ_FALLING**
72+
##### **Pin.IRQ_RISING**
73+
##### **Pin.IRQ_RISING_FALLING**
74+
##### **Pin.IRQ_LOW_LEVEL**
75+
##### **Pin.IRQ_HIGH_LEVEL**
76+
77+
### 示例一
78+
79+
控制引脚输出高低电平信号,并读取按键引脚电平信号。
5780

5881
```
5982
from machine import Pin
@@ -69,4 +92,19 @@ p_in = Pin(("key_0", PIN_IN), Pin.IN, Pin.PULL_UP)
6992
print(p_in.value() ) # get value, 0 or 1
7093
```
7194

72-
更多内容可参考 [machine.Pin](http://docs.micropython.org/en/latest/pyboard/library/machine.Pin.html)
95+
### 示例二
96+
97+
上升沿信号触发引脚中断后执行中断处理函数。
98+
99+
```
100+
from machine import Pin
101+
102+
PIN_KEY0 = 58 # PD10
103+
key_0 = Pin(("key_0", PIN_KEY0), Pin.IN, Pin.PULL_UP)
104+
105+
def func(v):
106+
print("Hello rt-thread!")
107+
108+
key_0.irq(trigger=Pin.IRQ_RISING, handler=func)
109+
```
110+
更多内容可参考 [machine.Pin](http://docs.micropython.org/en/latest/pyboard/library/machine.Pin.html)

0 commit comments

Comments
 (0)