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 program chips both raw and use the Arduino enviroment. I, personally am partial to AVR but PIC is just as good. I have programmers for both and they are essentially the same. One thing I did find is a great library which makes interfacing much easier using header files. I am not affiliated with this, just find it very useful.

Its called webbot and provides code to interface almost everything. Here's the link:  http://webbot.org.uk/iPoint/30.page.

link is broken....

but this should work  http://webbot.org.uk/iPoint/ipoint

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

 and...

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.

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.

What I've been saying is that you've been using C in your syntax, but there is a lot to C and there are some HW specific portions that you have yet to touch on. 

So again, Yes, you already know some C at least as far as using control structures, operators and use of functions, but there is a lot to know about C before you can be an expert at it. This will help you when you start writing your own functions and header files. I wouldn't say it'll be easy unless you think that dealing with the hardware directly by writing the functions yourself vs indirectly through functions that were predefined for you is easy. You will have to learn that hw level. I'd suggest looking through the source for for the arduino includes.

 

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.