我同意 zklapow 但也请查看 AVR Freaks 上的项目部分。这就是我在arduinos之前的一天学到的东西。此外,您几乎肯定必须阅读芯片的数据表才能完成任何有用的事情。没有很好的功能可以读取模拟引脚,因为 arduino 环境对您隐藏了太多参数。让我举一个例子:
int ledPin = 13; // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
大致类似于以下C(未测试):
int main(void) {
// I just randomly picked pin 6 on PORTB, this may not be the same on an arduino
DDRB = (1<<6); // set pin to output in data direction register
int i; // have to do this outside the for loop because of C standard
while(1) {
PORTB |= (1<<6); // send pin 6 high and leave other pins in their current state
for (i=0; i<10000; i++); // delay
PORTB &= ~(1<<6); // send pin 6 low
for (i=0; i<10000; i++); // delay
}
}
当然,有些库中有延迟函数,其他库中可能有输出函数,但要习惯于编写这样的代码。您可能知道所有这些 PORTB 和 DDRB 的含义的唯一方法是阅读数据表。我很抱歉就此发表意见,但没有足够多的人意识到数据表是获取信息的金矿。