Let's Make Robots!

How to get a start in using C and not bootloaders

Hello there lmr, I was thinking that it would be best for me to learn some C and program micros without using a bootloader (happy now krumlink?). I was wondering where to start. I am not trying to bring up a debate but i was wondering if PIC or AVR was better to start off with? Which one is easiest to use and which has the better programming environment. Also what would be needed to start in PIC or AVR? I know a chip, board, and programmer, any thing else? Or any thing else you can think of for someone trying to get into this. I have seen some stuff about this online but i want to get advice from the LMRers that i know.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I use PIC myself, but there's nothing wrong with the AVR chips. In many ways they're very similar.
You get a wider selection of chips with PIC, however since you've used Arduino in the past AVR might be slightly easier to get into. As stated you'll need a programmer and some chips to program, but you don't necessarily need a board as such - I sometimes program just the chips by themselves, but mostly I program them 'in-circuit' which is great for small projects.

Go to Atmel's (or Microchip's) website and grab the free IDE (Integrated Development Environment) software packages. I know Microchip's IDE, MPLAB, is very good, and I've heard the same about AVR Studio. Playing around with the simulator is a great way to get used to programming for the real thing.

Thanks telefox. I am downloading Atmel's IDE. I found this website http://imakeprojects.com/Projects/avr-tutorial/  which i might go through their tutorial. Once i get a programmer then i will get a little $2 Attiny45 and see if i can get it working. Arduino does not have a simulator but would you also suggest having some kind of communication between computer and micro? The programmers do not communicate both ways do they? Because i see that as a must for a lot of projects, the simulator is great for code but i guess you would need communication for debugging sensor values or do people just use multimeters  for that?
Smaller micros like the Tiny don't really have enough pins to run debugging communications easily, although technically it can be done. Personally I just use the simulator and a regular multimeter for most of my debugging, unless I'm using one of the larger micros in which case I do sometimes use the debugger to see what the micro's doing like you would with an Arduino.

Wow, so I hope you don't take Krumlinks opinion on bootloaders as gospel, serioiusly, there is nothing wrong with a bootloader. They serve a purpose and serve it well. Take most of this sites projects. Most of us use picaxes and arduinos and do pretty well with them. They are great for learning and when you eventually move on to raw chips, more power to ya.

As for learning C I think you can take a couple of approaches. If you have a linux machine or even a linux vm, you can create simple c programs and run them pretty quickly. This isn't specific to Uprocs, but with C it won't necessarily need to be. You can learn about the langauge and how to use it without worrying about other things that might be proc specific. I have read though that with memory you should look at best practices as dynaically allocating memory can be dangerous.

You could also take the approach of just getting the dev env as TF suggested. This will get you familiar with the ide and the sim that it uses. 

As far as what chip to get, I went the avr route as to me it was like Canon vs Nikon, they both have some great tech, it just seems to be what you end up with in the end. A lot of people like the pics though and there are plenty of people here who could help. TF comes to mind.  :D

The fastest way to get started though is just to use your arduinos as you can embed the avr c in your code and it's just like running it on an avr.

As far as debugging, you can get creative and use leds to do some. you could use a counter chip to say, output a binary representation of data.  it's not the most efficient or fastest, but it would get the job done. You could also find some rudimentary serial code and use that for communication. I've seen several pieces for the avr but I haven't tried any myself.



yeah i like bootloaders but when it comes to programming things in the real world, they use C. So i would hope to get a head start on it for my future career. I would probably stick with arduino for just about everything but i want to fiddle around a bit with the raw chips. Arduino and C language have a lot in common i notice. 

In the real world, they use assembly...

BTW, have you ever researched the Arduino?

You really should look at this....  http://arduino.cc/hu/Main/Documentation


Can I program the Arduino board in C?

In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process.

 So yeah, saying "Arduino and C language have a lot in common i notice" is like saying H2O has a lot in common with water....


well Arduino is still not pure C is what i am saying. 

What i am trying to get at is what would something that is massed produced be programmed in? Would it be assembly, C or what ever? Thats to say your average little programmed toy or something, maybe not even a average toy. I am trying to look ahead here. I am sure lots of people here would love to see a toy on the shelfs or some kind of iPod that was programmed in Arduino with a Arduino bootloader. Is there a reason why professionally made things would not use Arduino? Or is that the future? These are serious questions i have and please i am not trying to be rude if i sound that way. I just have lots of questions that my dad cant answer :P.

The industry is actually quite varied when it comes to microcontroller usage. PICs are the most commonly used microcontroller overall, not to say that AVR and others don't have a significant presence. Assembly and C are both still widely used, but other languages such as BASIC are surprisingly common, especially for low-end devices that may not need to respond quickly or work the micro hard to operate effectively.

Many small but powerful devices use ARM micros, including iPods, Nintendo GBA/DS, a huge number of cellphones, etc. In most cases there are other parts working together with the primary controller, and these may or may not be programmed in the same language. The Nintendo DS for example uses an ARM9 and an ARM7 working together.

Why don't professional products use Arduinos? They cost too much for a start. The bootloader uses up memory. There's no reason why an industrial electronic device manufacturer would choose an Arduino over a clean AVR chip which has the same capabilities.
Arduinos are made for two things - easy development for hobbyists and quick prototyping. If neither of those categories apply then you're wasting time and money using an Arduino =)
However, in your case, both of those things do apply, so unless you want to do something your Arduino can't there's no need to change to anything else. C/C++ are easy enough to learn, especially if you've already used essentially the same thing with Arduino C.

What is this pure form of C that you talk about? Can you explain this?

Not to be rude as well, but did you read the links or what I posted?

Okay, I think I may have not been clear.

Arduino bootloader facilitates in loading the program onto the chip, thats all, nothing more, nothing less.

The program is compiled against the avr gcc libs. this is what you'd use to program an avr chip. Same thing, nothing more, nothing less.

The arduino dev env adds the libraries that it needs in order to use the functions that they have defined in the ref manual.

This is a library that the ardunio guys wrote....in PURE C. 

With or without the bootloader, you're still writing a program in C/C++.....I hope you understand that.

The only reason you wouldn't want to use the arduino for a mass produced product is because it uses up some memory and if you buy the chip with the bootloader on it, they can be a bit more expensive. 

You can also embed assembly into the code written in the arduino dev env.








ok so i do already know some C is what you are telling me? everything i have done is in C and there fore i should have a easy time with grabbing some Attinys and getting them working correct? If this is true then i would love to try AVR mainly because i would like to see it for my self. I do not see anything to lose by trying something new even though, as you explained, it should not be new to me.