Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
根据我的经验,你绝对必须了解 C,汇编语言也有帮助。
In my experience, you absolutely must know C, and assembly language helps too.
除非您正在处理非常简单的微控制器(如 RS08 系列),否则 C 语言是迄今为止的首选语言。了解 C,了解 volatile 和 const 等功能。还要了解架构 - 什么是有效的,什么是无效的,CPU 可以做什么。这些与“桌面”环境有很大不同。学会爱上 stdint.h。
随着项目规模的扩大,您将遇到 C++(或受限子集)。
但是,您需要了解 CPU 以及如何读取基本汇编作为调试工具。如果没有这些技能,您就无法成为一名优秀的嵌入式开发人员。
Unless you are dealing with very bare-bones microcontrollers (like the RS08 series), C is by far the language of choice. Get to know C, understand functionality like volatile and const. Also understand the architecture - what is efficient, what isn't, what can the CPU do. These will differ wildly from a "desktop" environment. Learn to love stdint.h.
You will encounter C++ (or a restricted subset) as projects scale up.
However, you need to understand the CPU and how to read basic assembly as a debugging tool. You can't become an excellent embedded developer without this skillset.
您听到过哪些“相反”的观点?在某种程度上,这取决于微控制器和应用。然而,C 几乎可用于所有架构(我犹豫是否说所有,但可能是您将遇到的所有架构);因此,仅就这一点而言,学习 C 语言就能给你带来最大的覆盖范围。
对于所有体系结构,汇编器和 C 编译器的可用性几乎是给定的。对于 32 位和大多数 16 位架构,C++ 也将可用。我遇到的值得注意的例外是 Microchip 的 PIC24/dsPIC 部件,Microchip 自己的基于 GNU 的编译器不支持 C++(尽管第 3 方编译器可能会支持)。
虽然有用于 8 位微控制器的 C++ 编译器,但 C++ 在此类平台上并不普遍,而且编译器通常是完整语言的子集。对于通常采用 8 位的应用程序类型(或更具体地说是大小),C++ 可能有用,但不足以用于更大的应用程序,因此 C 通常就足够了。
关于嵌入式系统中的 C++ 有很多神话;虽然该语言比 C 语言更大,并且具有可能会损害系统性能或容量的结构,但您只需为使用 C++ 的内容付费。但当然,如果您使用的只是 C 子集,那么 C 在任何情况下都足够了。
C(和 C++)的要点在于它是一种系统级语言;它将在您的微处理器上运行,无需额外支持,只需一个非常简单的运行时启动即可初始化处理器(可能还包括外部 SDRAM)、初始化静态数据、建立堆栈,以及在 C++ 的情况下调用静态构造函数。这就是为什么它与特定于目标的汇编器一起用于构建操作系统和内核 - 它不需要操作系统或内核本身来运行。
我建议它可能取决于微控制器的原因之一是,例如,如果它是带有几 Mb 外部 SDRAM 的 ARM9,并且至少有 4Mb 闪存(通常也是外部 - 存储器占用大量芯片空间) ,那么您可以在其上运行“重量级”操作系统,例如 Linux、WinCE 或 Symbian,甚至是大型 RTOS,例如 QNX 或 VxWorks。那么你选择的语言(一旦你让操作系统工作)将受到操作系统的影响,尽管对于实时应用程序,C 和 C++ 仍然占主导地位(或者在军事、航空电子设备和一些运输应用程序中通常是 Ada)。
对于中型应用程序 - 几百 KB 的代码和数据空间 - 在 .NET-Micro 平台上运行 C# 是可能的;然而,几年前,我在英国嵌入式系统展上参加了该产品的演示,当时它刚刚推出;当我问“但是它是实时的吗”并被告知“不,你需要 WinCE”时,许多观众发出了一声喘息和呻吟,有些人不再浪费时间,离开了演示。彼时彼地(包括我)。
所以我对你们听到的‘对比’的观点还是很感兴趣的;因为虽然可以使用其他语言;你的问题的答案:
那么最终答案是C;因为我已经给出的原因。对于任何可能选择质疑这一主张的人这里是统计数据(请注意不同的2004年以后的调查方法在文中解释)。然而,为了增加替代方案的集合,我曾经花了两年的时间在 Forth 在嵌入式系统上,我知道人们仍在使用它,但它有点小众。
What 'contrasting' views have you heard? To some extent it will depend on the microcontroller and the application. However C is available for almost all architectures (I hesitate to say all, but probably all that you will ever encounter); so on that point alone, learning C would give you the greatest coverage.
For all architectures, the availability of an assembler and a C compiler are pretty much a given. For 32-bit and most 16-bit architectures C++ will also be available. Notable exceptions I have encountered are Microchip's PIC24/dsPIC parts for which C++ is not supported by Microchip's own GNU based compiler (although 3rd party compilers may do so).
While there are C++ compilers for 8 bit microcontroller's C++ is not ubiquitous on such platforms, and often the compilers are subsets of the full language. For the types (or more specifically the size) of application for which 8-bit is usually employed, C++ may be useful but not to the extent that it is on much larger applications, so C is generally adequate.
There are lot of myths about C++ in embedded systems; while the language is larger than C and has constructs that may compromise the performance or capacity of your system, you only pay for what you use with C++. But of course if what you use is just the C subset, the C would be adequate in any case.
The point about C (and C++) is that it is a systems level language; it will run on your microprocessor with no additional support save a very simple runtime start-up to initialise the processor (and possibly external SDRAM), initialise static data, establish a stack, and in the case of C++ invoke static constructors. This is why along with target specific assembler, it is used to build operating systems and kernels - it needs no operating system or kernel itself to run.
One of the reasons I suggested that it may depend on the microcontroller is that if for example it is an ARM9 with a few Mb of external SDRAM, and at least say 4Mb Flash (also usually external - memory takes up a lot of die space), then you could run a 'heavyweight' OS on it such as Linux, WinCE, or Symbian, or even a large RTOS such as QNX or VxWorks. Then your choice of language (once you got the OS working), would be influenced by the OS, though for real-time applications C and C++ would still dominate, (or often Ada in military, avionics, and some transport applications).
For mid-size applications - a few hundred KBytes of code and data space - C# running on the .NET-Micro platform is possible; However I sat in a presentation of this at the Embedded Systems Show in the UK a few years ago, just after it was when it was launched; when I asked the question "but is it real-time", and was told, "no you need WinCE for that", there was a gasp and a groan from much of the audience, and some stopped wasting their time an left the presentation there and then (including me).
So I am still interested in the 'contrasting' opinions you have heard; because although it is possible to use other languages; the answer to your question:
then the definitive answer is C; for the reasons I have given. For anyone who might choose to contest this assertion here are the statistics (note the different survey method after 2004 explained in the text). However just to add to the collection of alternatives, I once spent two years programming in Forth on embedded systems, and I know of people still using it, but it is a bit of a niche.
我已经成功地使用了 C 和 C++,但在几乎所有微控制器项目中,您都需要熟悉目标微控制器的汇编语言。如果仅用于调试低级硬件问题,即使是粗略的熟悉,汇编也是必不可少的。
我认为从桌面环境迁移到微型环境时对我来说最困难的事情是几乎所有东西都需要静态分配。你不会经常在微型计算机中使用 malloc/new ,除非它有外部 RAM。
我注意到您还用 FPGA 和 Verilog 标记了您的问题,看看 Altium,他们有一个 C 到硬件与集成环境配合良好的编译器。
I've successfully used both C and C++ but in almost any microcontroller project you will need to be familiar with the assembly language of the target micro. If only for debugging low level hardware issues assembly will be indispensable, even if it is a cursory familiarity.
I think the hardest thing for me when moving from a desktop environment to a micro was that almost everything needs to be allocated statically. You won't often use malloc/new in a micro unless maybe it has external RAM.
I notice that you also tagged your question with FPGA and Verilog, take a look at Altium, they have a C to Hardware compiler that works really well with their integrated environment.
关于汇编程序:
Regarding assembler:
微控制器最初仅使用汇编语言进行编程,但现在也普遍使用各种高级编程语言来针对微控制器。这些语言要么是专门为此目的而设计的,要么是通用语言(例如 C 编程语言)的版本。通用语言的编译器通常会有一些限制和增强功能,以更好地支持微控制器的独特特性。一些微控制器具有帮助开发某些类型的应用程序的环境。微控制器供应商通常免费提供工具,以便更轻松地采用其硬件。
许多微控制器非常古怪,以至于它们实际上需要自己的非标准 C 语言,例如 8051 的 SDCC,这阻止使用标准工具(例如代码库或静态分析工具),即使对于与硬件功能无关的代码也是如此。解释器经常被用来隐藏这种低级的怪癖。
解释器固件也可用于某些微控制器。例如,早期微控制器 Intel 8052[4] 上的 BASIC; Zilog Z8[5] 以及一些现代设备上的 BASIC 和 FORTH。通常这些解释器支持交互式编程。
模拟器可用于某些微控制器,例如 Microchip 的 MPLAB 环境。这些允许开发人员分析微控制器及其程序在使用实际部件时的行为。模拟器将显示内部处理器状态以及输出状态,并允许生成输入信号。虽然一方面,大多数模拟器将受到限制,无法模拟系统中的许多其他硬件,但它们可以练习在物理实现中难以随意重现的条件,并且可以是调试和分析的最快方法问题。
Microcontrollers were originally programmed only in assembly language, but various high-level programming languages are now also in common use to target microcontrollers. These languages are either designed specially for the purpose, or versions of general purpose languages such as the C programming language. Compilers for general purpose languages will typically have some restrictions as well as enhancements to better support the unique characteristics of microcontrollers. Some microcontrollers have environments to aid developing certain types of applications. Microcontroller vendors often make tools freely available to make it easier to adopt their hardware.
Many microcontrollers are so quirky that they effectively require their own non-standard dialects of C, such as SDCC for the 8051, which prevent using standard tools (such as code libraries or static analysis tools) even for code unrelated to hardware features. Interpreters are often used to hide such low level quirks.
Interpreter firmware is also available for some microcontrollers. For example, BASIC on the early microcontrollers Intel 8052[4]; BASIC and FORTH on the Zilog Z8[5] as well as some modern devices. Typically these interpreters support interactive programming.
Simulators are available for some microcontrollers, such as in Microchip's MPLAB environment. These allow a developer to analyze what the behavior of the microcontroller and their program should be if they were using the actual part. A simulator will show the internal processor state and also that of the outputs, as well as allowing input signals to be generated. While on the one hand most simulators will be limited from being unable to simulate much other hardware in a system, they can exercise conditions that may otherwise be hard to reproduce at will in the physical implementation, and can be the quickest way to debug and analyze problems.
您需要了解汇编语言编程。您还需要具备良好的 C 和 C++ 知识。因此,努力学习这些知识,以获得更好的微控制器编程专业知识。
You need to know assembly language programming.You need to have good knowledge in C and also C++ too.so work hard on thse things to get better expertize on micro controller programming.
并且不要忘记 VHDL。
And don't forget about VHDL.
对于微控制器来说,汇编程序先于 C。在 ARM 开始进军这个市场之前,编译器很糟糕,内存和 ROM 也非常小。没有足够的资源或通用性来移植您的代码,因此用 C 语言编写代码以实现可移植性是没有意义的。
一些微控制器的汇编器并不理想,而 ARM 正在占领该市场。您可以花费更少的钱、更少的功耗和更少的占用空间来拥有拥有更多资源的 32 位处理器。这很有道理。如果你的代码仍然无法移植,那么你可能可以使用 C。
底线,汇编程序和 C。如果他们宣传 BASIC 或 Java 或类似的东西,请将该公司标记到你的黑名单上并继续前进。去过那里,做过那件事,有伤疤来证明这一点。
For microcontrollers assembler comes before C. Before the ARMs started pushing into this market the compilers were horrible and the memory and ROM really tiny. There are not enough resources or commonality to port your code so writing in C for portability makes no sense.
Some microcontroller's assembler is less than desirable, and ARM is taking over that market. For less money, less power, and less footprint you can have a 32-bit processor with more resources. It just makes sense. Much if your code will still not port, but you can probably get by with C.
Bottom line, assembler and C. If they advertise BASIC or Java or something like that, mark that company on your blacklist and move on. Been there, done that, have the scars to prove it.
第一次大会。 C之后。
我认为懂汇编和C的人比只懂C的人要好。
First Assembly. After C.
I think that who knows Assembly and C are better than who knows only C.