我不允许为该程序使用 Arduino 库(或任何库)。我将如何检查引脚的输入?
我发现了两个不同的函数:
在 Arduino.h 中:
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
跟随 digitalRead 回到 pgmspace.h:
#define __LPM_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ __volatile__ \
( \
"lpm %0, Z" "\n\t" \
: "=r" (__result) \
: "z" (__addr16) \
); \
__result; \
}))
对于第一个,我不知道比特和值(value)从何而来,我根本不理解第二个。
最佳答案
这些实现就不用去了。如下所示非常简单。
当引脚 0 为高电平时,LED13 将点亮。我在 arduino 上测试了这段代码
#include <avr/io.h> // Includes all the definition of register port etc
#ifndef F_CPU
#define F_CPU 16000000UL //Need to include it before <util/delay.h>
#endif //Change 16000000 with your crystal freq. In my case its 16 MHz
#include <util/delay.h> //includes delay functions delay_ms and delay_us
void setup() {
// put your setup code here, to run once:
DDRB |= 0xFF; //Configured Port B as OP
DDRD &= 0x00; //Configured Port D as IP
}
void loop() {
// put your main code here, to run repeatedly:
if (PIND&(0x01)) //to check pin0 of portD (which is Pin 0 of arduino)
PORTB |= 0xFF;
else
PORTB &= 0x00;
}
关于c++ - 在没有 Arduino 库的情况下获取引脚输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39866771/