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

  • Thread starter pyroknife
  • Start date
  • Tags
    Programming
In summary: Objective-based programming (OOP) and debugging are important for programming microcontrollers, but they are not the only important aspects. You also need to have a good understanding of the CPU architecture and how the microcontroller memory is laid out. Having knowledge of these topics will help you to write code that is easy to read and debug.
  • #1
pyroknife
613
4
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
 
Engineering news on Phys.org
  • #2
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.
 
  • #3
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.
 
  • #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 want to work it you got to 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 a lot 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:
  • #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.
 
  • #6
pyroknife said:
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. [...] Specifically, I am interested in using an Arduino and PIC.
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.
 
  • #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?
 
  • #8
pyroknife said:
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?

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.
 
  • #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:

This is an introductory course in designing microcontroller-based embedded systems. Topics include an overview of a single-chip microcontroller, hardware and software concepts in microcontroller, system architecture, central processing unit (CPU), internal memory (ROM, EEPROM, RAM, FLASH), Input/ Output ports, serial communication, programmable interrupts, ADC, DAC, interfacing and timers, microcontroller programming model and instruction set , assembly and C language programming. Labs and projects are essential parts of this course and students are expected to spend a considerable time in laboratory work.
 

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

1. How much prior knowledge of C is required to program microcontrollers?

The level of C knowledge required to program microcontrollers can vary depending on the specific project and the complexity of the microcontroller. However, it is recommended to have a strong understanding of basic C syntax, data types, and control structures before attempting to program microcontrollers.

2. Can I learn how to program microcontrollers without any knowledge of C?

While it is possible to learn how to program microcontrollers without any prior knowledge of C, it is not recommended. Having a basic understanding of C will make it easier to understand the programming concepts and syntax specific to microcontrollers.

3. How long does it take to learn enough C to program microcontrollers?

The time it takes to learn C for programming microcontrollers can vary depending on individual learning pace and dedication. However, with consistent practice and dedication, one can gain enough knowledge of C for programming microcontrollers within a few months.

4. Do I need to know advanced C concepts to program microcontrollers?

It is not necessary to have a deep understanding of advanced C concepts to program microcontrollers. However, having knowledge of advanced concepts like pointers, structures, and memory management can be beneficial for more complex microcontroller projects.

5. Are there any resources available to learn C specifically for microcontroller programming?

Yes, there are many resources available online and in books that focus on teaching C specifically for microcontroller programming. These resources can provide a comprehensive understanding of C in the context of microcontrollers and can help beginners get started with programming microcontrollers more efficiently.

Back
Top