Arduino 编程与标准 C 语言有何不同?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然我不了解 ATXMega,但 8 位 AVR 芯片(例如较新的 Arduino 上使用的 ATmega328)使用 AVR-GCC 编译器。这允许将 C 甚至 C++ 编译到 AVR 芯片。 AVR-GCC 之上的一个级别是 AVR Libc,这是一个 C 库,可以为AVR 是一个更高级别的任务(不再需要直接引用寄存器,等等)。
Arduino IDE在后端使用AVR-GCC和AVR libc库。此外,Arduino IDE 还提供其他库 ,就像一个漂亮的串行接口。
最后,Arduino 附带了烧录在 AVR 芯片上的引导加载程序。引导加载程序可以使用串行连接(通过 USB)而不是系统内编程器或开发板对 AVR 进行编程。
足够的背景故事来回答您的问题:Arduino 可以用 C 甚至 C++ 进行编程。可用的库是用 C 编写的,所有内容都将使用 AVR-GCC 进行编译。甚至不需要 Arduino IDE。
编辑
人们似乎对这个主题很感兴趣。我写了一篇博文,尝试提供有关 AVR、Arduino 和 AVR-GCC 的更多详细信息。
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).
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.
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.
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.
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.
使用 Arduino 时,您可以利用现有的 C 语言知识。
目的是让艺术家/非程序员轻松入门
与硬件编程和修补,所以“Arduino 语言”是
只是一个简化开发的包装器。
作为一名 C 程序员,使用 Arduino 对您来说应该更容易。
文档一点也不长,文档一点也不长。 cc/playground/" rel="nofollow">wiki 很好,而且
论坛上的人们热情且乐于助人。
You can take your existing C knowledge when using Arduino.
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.
It should be a lot easier for you, as a C programmer to use Arduino.
The documentation isn't lengthy at all, the wiki is nice and
the people on the forum are enthusiastic and helpful.
Arduino 是 C 语言,只不过它被插入到每个程序中:
Arduino is C, except that this is inserted into every program:
您几乎可以掌握 C 语言和嵌入式系统方面的所有知识,并且一切都会好起来的。使用起来一点也不难。将 Arduino 参考 页面添加为书签,您将立即开始编写内容。
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 Reference page and you'll be writing stuff in no time.
Arduino 与 C 类似,非常容易上手。他们已经从执行诸如读取和写入外围寄存器之类的事情中抽象出来以执行基本任务。
如果您实际上在任何其他平台上做过真正的 C 语言,那么只要看一下一些示例代码和 Arduino 参考,您就会立即启动并运行。
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.
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.