Arduino 编程与标准 C 有何不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5931572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:12:16  来源:igfitidea点击:

How is programming an Arduino different than standard C?

c++carduino

提问by Nathan

I have a background in programming embedded systems (TI MSP430, Atmel ATxmega). How is programming an Arduino different than those? What knowledge about C can I take in to programming the Arduino?

我有编程嵌入式系统的背景(TI MSP430,Atmel ATxmega)。对 Arduino 进行编程与那些有什么不同?我可以采用哪些 C 知识来对 Arduino 进行编程?

回答by baalexander

While I don't know about the ATXMega, the 8-bit AVR chips like the ATmega328 used on the newer Arduinos use the AVR-GCC compiler. This allows for compiling C and even C++ to an AVR chip. One level above the AVR-GCC is the AVR Libc, a C library that makes programming for the AVR a higher level task (no longer have to refer to registers directly, and so on).

虽然我不了解 ATXMega,但在较新的 Arduino 上使用的 ATmega328 等 8 位 AVR 芯片使用 AVR-GCC 编译器。这允许将 C 甚至 C++ 编译为 AVR 芯片。AVR-GCC 上一层是AVR Libc,这是一个 C 库,它使 AVR 的编程成为更高级别的任务(不再需要直接引用寄存器等)。

The Arduino IDE uses AVR-GCC and AVR libc library in the backend. In addition, the Arduino IDE makes other libraries available, like a nice Serial interface.

Arduino IDE 在后端使用 AVR-GCC 和 AVR libc 库。此外,Arduino IDE 还提供了其他库,比如一个不错的串行接口。

Finally, the Arduino comes with a bootloader burned on the AVR chip. The bootloader simply makes it possible to program the AVR using a serial connection (from USB) instead of an In-Sytem Programmer or Development Board.

最后,Arduino 带有一个烧录在 AVR 芯片上的引导程序。引导加载程序可以简单地使用串行连接(来自 USB)而不是系统内编程器或开发板对 AVR 进行编程。

Enough backstory, to answer your question: The Arduino can be programmed in C and even C++. The libraries available are written in C and everything will compiled using AVR-GCC. The Arduino IDE isn't even required.

足够的背景故事来回答你的问题:Arduino 可以用 C 甚至 C++ 进行编程。可用的库是用 C 编写的,一切都将使用 AVR-GCC 编译。甚至不需要 Arduino IDE。

Edit

编辑

There seems to be a decent amount of interest in this topic. I wrote a blog post to try and give more in-depth details on the AVR, Arduino, and AVR-GCC.

似乎对这个话题有相当多的兴趣。我写了一篇博文,试图提供有关 AVR、Arduino 和 AVR-GCC 的更深入的详细信息

回答by George Profenza

You can take your existing C knowledge when using Arduino.

使用 Arduino 时,您可以利用现有的 C 知识。

The purpose was to allow artists/non-programmers to get started easily with hardware programming and tinkering, so the 'Arduino language' is just a wrapper to simplify development.

目的是让艺术家/非程序员轻松开始硬件编程和修补,因此“Arduino 语言”只是简化开发的包装器。

It should be a lot easier for you, as a C programmer to use Arduino. The documentationisn't lengthy at all, the wikiis nice and the people on the forumare enthusiastic and helpful.

作为 C 程序员,使用 Arduino 应该容易得多。该文件是不是在所有冗长的维基是好的,人们对论坛热心,乐于助人。

回答by Nick ODell

Arduino is C, except that this is inserted into every program:

Arduino 是 C,除了它被插入到每个程序中:

void main() {
  setup();
  for(;;) {
    loop();
  }
}

回答by Pete

You can pretty much take all your knowledge with C and embedded systems and you will be more than OK. It's not hard to use at all. Bookmark the Arduino Referencepage and you'll be writing stuff in no time.

您几乎可以掌握所有有关 C 和嵌入式系统的知识,而且您会非常满意。一点都不难用。将Arduino 参考页面添加为书签,您很快就会开始写东西。

回答by Jon

Arduino is C-like and extremely easy to pick up. They have abstracted away from doing things like reading and writing into peripheral registers for doing basic tasks.

Arduino 类似于 C 语言,非常容易上手。他们已经从执行基本任务的外围寄存器读取和写入等操作中抽象出来。

One look at some example code and the Arduino reference and you'll be up and running in no time if you've actually done real C on any other platform.

看看一些示例代码和 Arduino 参考,如果您实际上已经在任何其他平台上完成了真正的 C,您将立即启动并运行。