PortInOut
使用 PortInOut 接口将基础 GPIO 端口读写为一个值。这比 BusInOut 快得多,因为您可以一次编写一个端口,但由于受到底层 GPIO 端口的端口和位布局的限制,它的灵活性要低得多。
可以提供掩码,因此您只使用端口的某些部分,允许其他位用于其他接口。
PortInOut 类参考
公共成员函数 | |
PortInOut (PortName port, int mask=0xFFFFFFFF) | |
void | write (int value) |
int | read () |
void | output () |
void | input () |
void | mode (PinMode mode) |
PortInOut & | operator= (int value) |
PortInOut & | operator= (PortInOut &rhs) |
operator int () |
PortInOut hello, world
// Toggle all four LEDs
#include "mbed.h"
// LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
#define LED_MASK 0x00B40000
PortInOut ledport(Port1, LED_MASK);
int main() {
int v = ledport;
ledport.output();
while(1) {
ledport = LED_MASK;
wait(0.5);
ledport = 0;
wait(1);
}
}
相关内容
- BusInOut API 参考。