# best programming language for a microcontroller?

by Jarfi
Tags: language, microcontroller, programming
 P: 263 So I've taken a course in java and gotten a solid grasp on it, I've learned using the arduino assembly language and messed around with it making some gadgets, and now I wan't to go further. I want to buy a pure microcontroller or processer without a board, and start programming simple stuff on it, later graduating to more complex stuff like video transmission and all the mind can dream off. What is the top tier final language engineers can use to do just about anything, like controlling a machine via radio and transmitting and recieving a radio using the same antennas. Even controlling a large LED screen, you get the point. So the question is, best language for microcontrollers for use in machines p.s. out of curiosity, what is windows written on?
 PF Gold P: 5,674 assembly language will always do everything you want but it can be VERY tedious. C is generally the best language for stuff that is close to the hardware, but you'll need to be sure there is a cross-compiler for the microprocessor you decide on and that you have the wherewithal to move object code from the cross compiler output to the microprocessor. Windows is written for the Intel x86/Pentium platforms.
P: 263
 Quote by phinds assembly language will always do everything you want but it can be VERY tedious. C is generally the best language for stuff that is close to the hardware, but you'll need to be sure there is a cross-compiler for the microprocessor you decide on and that you have the wherewithal to move object code from the cross compiler output to the microprocessor. Windows is written for the Intel x86/Pentium platforms.
Aren't there several types of C ? and if so what one to I choose, also I've tested arduino assembly language which in based on C I think and it all looks almost exactly like java, I think I'd adapt to C in no time.

PF Gold
P: 5,674

## best programming language for a microcontroller?

 Quote by Jarfi Aren't there several types of C ? and if so what one to I choose, also I've tested arduino assembly language which in based on C I think and it all looks almost exactly like java, I think I'd adapt to C in no time.
No, there is only one C language. There is also C++ and C# but they are object oriented languages and not good if you want to stay close to the machine.

You may be thinking of compilers. Of course there are numerous C compilers, but that's not what you need. You need a cross compiler.

Do you fully understand the concept of what the BIOS is and what it does and what you have to do if you are doing raw programming on a microprocessor that doesn't have a BIOS ?
 P: 263 Nope. I have no Idea what a BIOS but Im guessing its something that that makes the processor be able to "talk" in C. Anyways since I need to get to the core I will choose C then, and yes C++ and C# is what I meant, I thought they were variatiants of C itself, apparently I was wrong. So what do I have to do to get my fresh out of the factory processor to work with C?
 P: 56 When you say that you have used the "Arduino Assembly Language", do you mean this language? /* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability } If this is what you mean, it is not Assembly, but C++ with a few custom libraries. Assembly depends on the architecture, and requires a knowledge of the available hardware functions, registers, and memory. C++ and C are both good languages for working close to the hardware without actually having to know what the hardware is. Of these, C is probably better.
P: 56
 Quote by Jarfi Nope. I have no Idea what a BIOS but Im guessing its something that that makes the processor be able to "talk" in C. Anyways since I need to get to the core I will choose C then, and yes C++ and C# is what I meant, I thought they were variatiants of C itself, apparently I was wrong. So what do I have to do to get my fresh out of the factory processor to work with C?
No processor speaks C natively. C must always be compiled to machine language, which is essentially Assembly with keywords swapped almost 1 to 1 with sequences of binary digits.

Don't worry about that though. Almost everything has a C compiler; you just need to find it.
P: 82
 Quote by Jarfi Nope. I have no Idea what a BIOS but Im guessing its something that that makes the processor be able to "talk" in C. Anyways since I need to get to the core I will choose C then, and yes C++ and C# is what I meant, I thought they were variatiants of C itself, apparently I was wrong. So what do I have to do to get my fresh out of the factory processor to work with C?
I think you're a bit lost. The microcontroller/microprocessor has its own language (machine code). It is a certain configuration of 1's and 0's. That language has been abstracted into "assembly language" by the chip manufacturer. They provide you with an assembler to use to turn that abstraction into the machine code. C is another layer of abstraction on top of assembly abstraction. When you compile a C program it gets turned into assembly and then into the actual machine code (or some shortcuts therein).

C is standardized. The specs must be purchased (but they're out there). Whether or not a particular C compiler will turn your C code into something correct (machine code-wise) for the target chip is probably the main thing to consider.
 PF Gold P: 5,674 Jarfi, I mean you no disrespect but if you have no idea what a BIOS is then you are planning to go in WAY over your head. I suggest that you study basic computer architecture and then basic operating system architecture before you attempt your project. Right now, you don't even know what questions to ask.
P: 82
 Quote by phinds Jarfi, I mean you no disrespect but if you have no idea what a BIOS is then you are planning to go in WAY over your head. I suggest that you study basic computer architecture and then basic operating system architecture before you attempt your project. Right now, you don't even know what questions to ask.
I know what you're saying but a microcontroller doesn't require a "BIOS". A microprocessor does. He seems to be leaning towards microcontrollers more. A microprocessor (more difficult to deal with from scratch) has no storage for a program. A microcontroller does and can be flashed or manufactured (internal "bios") with such..
PF Gold
P: 5,674
 Quote by rp55 I know what you're saying but a microcontroller doesn't require a "BIOS". A microprocessor does. He seems to be leaning towards microcontrollers more. A microprocessor (more difficult to deal with from scratch) has no storage for a program. A microcontroller does and can be flashed or manufactured (internal "bios") with such..
A reasonable point as far as it goes, but I believe my comment is still valid. It seems to me that he doesn't understand the fundamental structure and interrelationship of hardware / operating systems / computer languages. I could be wrong about that. Jarfi, what do you say?
P: 82
 Quote by phinds A reasonable point as far as it goes, but I believe my comment is still valid. It seems to me that he doesn't understand the fundamental structure and interrelationship of hardware / operating systems / computer languages. I could be wrong about that. Jarfi, what do you say?
Absolutely your comment is 100% valid, sorry if it came off as a negation. I agree he needs to understand architecturally what entails both IC types before proceeding (of which a bios is a key part of). I guess the reciprocal might have been if we said he needed to understand chip programmers before proceeding... which wouldn't necessarily apply much to the microprocessor (besides programming the bios lol).
PF Gold
P: 2,631
 Quote by phinds I suggest that you study basic computer architecture and then basic operating system architecture before you attempt your project.
I agree. He could use an old PC with an older operating system and play with a this very simple language which can make calls to system interrupts thereby learning it's architecture.
PF Gold
P: 5,674
 Quote by dlgoff I agree. He could use an old PC with an older operating system and play with a this very simple language which can make calls to system interrupts thereby learning it's architecture.
Yeah, that's a good idea.
P: 263
 Quote by phinds A reasonable point as far as it goes, but I believe my comment is still valid. It seems to me that he doesn't understand the fundamental structure and interrelationship of hardware / operating systems / computer languages. I could be wrong about that. Jarfi, what do you say?
First off, I'd like to say I am 19 years old studying physics with no educational backround in electronics, it is merely self taught apart from some java side courses. Most of my knowledge is assumptions based on observations I have learned over the past couple of months I've been discovering computer sciences and electronics.

Now, I am simply trying to get a solid grasp on microcontrollers, if I'd have to program a microprocessor I'd probably just get somebody to help me with that.

If I can program in C, turn it into the assembly code I need via compiler and then install that on my microcontroller, then that's all I really need. For now, I am not going to be learning hardcore computer science, I just started this.

I want to program, run my C code on some chips and that's it, I don't ask for much more. This is what I am already doing with my arduino I am simply going here because the arduino is a prototyping board which doesn't offer you all the benefits of a custom cirquit board, mainly weight and size wise.
P: 734
 Quote by Jarfi If I can program in C, turn it into the assembly code I need via compiler and then install that on my microcontroller, then that's all I really need.
If I were you I would start out with one of Microchip's PIC microcontrollers. It's very popular and there's a lot of beginner level books written for it. You can download a free IDE from their website. This IDE will allow you to write programs in assembly or C and it will compile and download them to your chip. There are a lot of PIC chips to choose from. I started with the PIC16F84. The only thing that may cost you, other than the chip itself, is the programmer. The programmer connects the chip to your computer and allows you to download your program to the chip. The one I used was the Microchip Picstart Plus. However, I noticed that the price for this has increased since I bought mine more than 10 years ago. There may be cheaper options available (but with limited capabilities).

The things you need to do are: get a beginners book, get a programmer, download the IDE, get a breadboard and associated parts (resistors, capacitors, power supply, etc...), get the part you want to program, and download the data sheet for it from Microchip. Don't be intimidated by the data sheet. You will not need to understand everything on it to write your first program. Your book should explain what you will need to get from the data sheet.

Good luck and have fun.
P: 263