|
发表于 2018-6-3 01:51:37
|
显示全部楼层
我記得 ATMEGA328P 的 I/O 在未指定 PINMODE 時,
內定是 INPUT 作用,要用來 OUTPUT 就必須以 PINMODE
指定為 OUTPUT
這裏有一段說明(截自 ATMEGA328P DATASHEET)
If PORTxn is written to '1' when the pin is configured as an input pin, the pull-up resistor is activated. To
switch the pull-up resistor off, PORTxn has to be written to '0' or the pin has to be configured as an output
pin. The port pins are tri-stated when reset condition becomes active, even if no clocks are running.
If PORTxn is written to '1' when the pin is configured as an output pin, the port pin is driven high. If
PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low.
大致上也說明了你遇到的狀況,當未指定 PINMODE (即內定
為 INPUT)時,若對這個 PORT 進行設定為 1 的動作時,
PULL HIGH 機制會作動,也因此你可以量到 PORT 有高電位,
但那並不是用來驅動外部的 DRIVE HIGH 準位,用途差很多
ARDUINO 有專用指令 pinMode( 2, INPUT_PULLUP );
來達到 INPUT PULL HIGH 的作用,並且不會造成 I/O 的混淆,
我個人習慣用這種方式來指定輸入埠 PULL HIGH |
|