Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How much of C do you have to know before programming microcontrollers?

  1. Jan 18, 2013 #1
    I'm learning C on my own time. I'm going at a pretty fast pace, but I'm highlighting most of the important things or at least, what I think is important so I can refer back to it later. I struggle with most of the back of the chapter exercises mainly because I'm going through it really fast and most of the time, I have to end up looking at the solutions.

    How much of C do you have to know before you start programming microcontrollers for basic circuits needs such as controlling the elements in a circuit, motors, etc... Not too advanced programming stuff, but stuff that requires programming.

    I'm like 3/4 of the way through the book and I can see where some of this would apply, but if I were given a microcontroller and told to program it so it would behave (control a circuit) a certain way, I wouldn't even know where to start.

    Specifically, I am interested in using an Arduino and PIC
     
  2. jcsd
  3. Jan 18, 2013 #2

    berkeman

    User Avatar

    Staff: Mentor

    Which C book? Are you reading K&R?

    I would think you are good to go. Once you have the basics (especially bitwise operations and logical operations), that's most of what you need. Depending on what you want to do, arrays will help. Eventually you will want to be comfortable with pointers, but not for initial uC programming, IMO.
     
  4. Jan 18, 2013 #3

    rbj

    User Avatar

    you better get some of the microcontroller basics. like how the peripherals are done. are the periphs memory mapped? or are they special MPU registers?

    anything that is memory mapped, you should be able to manipulate with instructions in C. but if these periphs are special internal registers, then only the MPU assembly language can get to it. you should at least have an idea how your development system connects C routines to assembly routines.

    C is pretty low level, but it is not assembly language and you might need both for development.
     
  5. Jan 18, 2013 #4
    Really understanding uControllers reauires 3 things from my point of view

    - Hardware knowledge
    - Programming knowledge
    - Usage knowledge

    What I mean by this is that a person wanting to work with microcontrollers has to have some kind of knowledge about the CPU architecture and the memory layout. This means

    - Some basic courses in computer architecture.

    - If you really wanna work it you gotta know about how to set up the microcontroller, most times this means understanding how a bootloader works, or bootstrap, in terms of assembler language (specific to the CPU architecture). This will allow you to create drivers for all the peripherals in C language.

    - If the usage of your microcontroller is going to be very specific, your programming is going to be specific (means drivers, and higher applications will be centered around the usage)

    - If the usage of your microcontrolller is going to be general, you will need to analyze the different systems that your controller must interact with, and create drivers that can handle dynamic interaction with these devices.

    Edit: Controlling motors etc.
    My field is about control systems, and while many people see controlling motors etc., as an inexact science, there is alot you can learn from studying first classical control theory and then digital control theory.

    Those two subjects will give you the best engineering understanding of how to achieve your goals.
     
    Last edited: Jan 18, 2013
  6. Jan 18, 2013 #5
    Thanks for all the responses.

    I am using Kochan's "Programming in C" book. I started using K&R's, but they do expect you to know some of the basics, which I didn't know.

    I am actually a MECH major. We're doing a project for the mechatronics class this coming semester. I'm not sure what the exact details are yet. These are projects made up by individuals, so each project will vary. For ours, I am not sure how complicated the coding will be.
     
  7. Jan 19, 2013 #6
    I agree with berkeman—just go for it. The best way to learn programming microcontrollers in C is to program microcontrollers in C. Find a simple LED blinking code snippet, copy it to your project, compile, download and see that it works. Once you've done that, you can start modifying the code and expand it to do more interesting stuff. There's enough Arduino/PIC/Atmega code out there now that will allow you to do almost anything. I wouldn't worry too much about assembly language and what not at this stage. Just get a system up and running (which is easy) and take it from there.
     
  8. Jan 21, 2013 #7
    How important is objective based programming and Debugging for programming microcontrollers?

    There's a chapter in my book called "objective oriented programming" and another called "Debugging Programs."

    How importnat are these 2 things when it comes to programming microcontrollers like PICs and Arduinos?
     
  9. Jan 21, 2013 #8

    nsaspook

    User Avatar
    Science Advisor

    For most small micro-controller programming projects OOP is overkill because the amount of global data/program structure is small, machine resources are limited and the micro-controller usually operates at the task level. The OOP paradigm is just not very useful at this level.

    Debugging micro-controllers is a very important subject that usually requires specialized knowledge of the hardware/software tool environment used to develop programs for the devices and is normally supplied by the manufacturer.
     
  10. Jan 22, 2013 #9
    I have a Microcontroller and Microprocessor course that I will take a semester later. I've finished the prerequisite, which is Digital Design I, and I'm looking forward to prepare myself to the Microcntroller course before I take it. What would you recommend me to do? I'm thinking of learning programming in Assembly and C and getting an Arduino Uno board. Give me an advice.

    This is the description of the Microcontroller course in my college:

     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook