C in Embedded Systems

  • Thread starter AK2
  • Start date
  • #1
AK2
39
0

Main Question or Discussion Point

I am currently learning C so that I can design a project using a pic microcontroller. I want to learn C first before studying the microcontroller. I want to ask, what topics should I learn, so that I will be using what I need to know to program the chip. Thanks
 

Answers and Replies

  • #2
berkeman
Mentor
57,306
7,287
I am currently learning C so that I can design a project using a pic microcontroller. I want to learn C first before studying the microcontroller. I want to ask, what topics should I learn, so that I will be using what I need to know to program the chip. Thanks
What other languages have you used, or is C the first one you are learning? Are you using the K&R book to self-study? Or do you have some other C learning resources?

Have you used Assembly Language before? I think it might be more intuitive to learn PIC assembly first, and write some simple programs with assembly. Then look at how you can make them more readable and maintainable by writing them in C.

Just going front-to-back in K&R is not a bad way to learn C, as long as you are comfortable with self-study.
 
  • #3
Having a lot of experience with PICs, I would recommend the book Programming 16-Bit PIC Microcontrollers in C: Learning to Fly the PIC 24 by Lucio Di Jasio. This way, you can learn C and PIC programming simultaneously. I personally found this book quite helpful. You will need to purchase Microchip's 16-bit development system, and one of the projects requires a PC serial port which is not on some of the latest PCs, but serial port plug-in cards are cheap.
 
  • #4
AK2
39
0
What other languages have you used, or is C the first one you are learning? Are you using the K&R book to self-study? Or do you have some other C learning resources?

Have you used Assembly Language before? I think it might be more intuitive to learn PIC assembly first, and write some simple programs with assembly. Then look at how you can make them more readable and maintainable by writing them in C.

Just going front-to-back in K&R is not a bad way to learn C, as long as you are comfortable with self-study.
I am a beginner in programming and C is the first language I am learning. I am/was using Sams Teach Yourself C in 21 days. I think I'm going to drop it because its voluminous. I was reading K&R for a while but I didnt really get it. I think I will go back to it since the book I'm using is making me feel C is impossible to learn. I just started reading K&R today and I'm understanding it. I can't explain it but I guess it because I like straightforward books more than books that kind of go around in circles. I have no experience in assembly. Is it a good idea to learn matlab and C at the same time. I just used matlab like a calculator.
 
  • #5
berkeman
Mentor
57,306
7,287
The book and development system recommended by Otto sound good. Be sure to check them out.
 
  • #6
20
0
Some topics that may be useful would be anything that shows how to deal with Registers. You will need a strong understanding of boolean algebra and the boolean numbering system. As for the C language, the basics are all you need: For-Loops, Do-Loops, If-Statements, etc. Generally, PIC Microcontrollers will have a particular library of commands that you can use. There are plenty of articles online to learn this.

I've done a few projects with microcontrollers (stationary solar tracker, serial communication, etc) and all have been with PICs. If you're trying to do something in particular, just email me and I'll write an article on my blog. Hope this helps.

P.S. Be sure to learn how to use Microchip's MPLAB. This is the hardest part about programming a pic. That and interfacing with the chip itself. Good luck


-----------------
Justin Coulston
<< e-mail address deleted by berkeman >>
TheModernEngineer.blogspot.com
 
Last edited by a moderator:
  • #7
AK2
39
0
I need like a comprehensive list of topics in C I need to learn in C, so that I can be atleast be comfortable in them before I start studying microcontrollers. After having a good understanding of microcontrollers I can think of a good idea for a project using microcontrollers for now. I have the book ''Programming and Customizing The Pic Microcontroller'' by Mike Predko. Thanks for the responses. I don't to learn a feature of C that I don't need to program the chip.
 
  • #8
245
13
AK, I was a C pro before I saw my first microcontroller (miC for short). It didn't look like anything I had ever done before. Beyond languages, there are a multitude of programming paradigms. You can't just write a program for a miC like you would see in the C books. For a micC, you have to ensure that volatile memory is placed in RAM and not FLASH, you have ensure that the startup code is placed at the zeroth address, there is no operating system in a miC to provide dynamic memory allocation so you must define all memory at compile time, and you have to write your own interrupts.

I really think you should just plunge straight into a C book designed for miC's. The only thing you need to know about the actual language of C is the bare basics: math operators and relational operators, bit-wise operators, include files and source files, functions, structures, pointers, branches, and loops. That's it. You don't even need to know much about the print() function even though you'll see it over and over in tutorials. Printing is provided by the OS and, like I said, the OS doesn't typically exist in a miC unless you put one there.

Bit-wise operations are the most important thing for miC's that you won't see much of in the C books . A typical operation in a miC is to get a flag register from memory and mask it to see if some operation is completed (an analog to digital conversion perhaps). You'll be doing that over and over.
 
Last edited:
  • #9
154
0
Or, if you can get your hands on BASIC Stamp Editor, you can plop that sucker down on top of an IC or and program in BASIC. It's really cool :P
 
  • #10
AK2
39
0
AK, I was a C pro before I saw my first microcontroller (miC for short). It didn't look like anything I had ever done before. Beyond languages, there are a multitude of programming paradigms. You can't just write a program for a miC like you would see in the C books. For a micC, you have to ensure that volatile memory is placed in RAM and not FLASH, you have ensure that the startup code is placed at the zeroth address, there is no operating system in a miC to provide dynamic memory allocation so you must define all memory at compile time, and you have to write your own interrupts.

I really think you should just plunge straight into a C book designed for miC's. The only thing you need to know about the actual language of C is the bare basics: math operators and relational operators, bit-wise operators, include files and source files, functions, structures, pointers, branches, and loops. That's it. You don't even need to know much about the print() function even though you'll see it over and over in tutorials. Printing is provided by the OS and, like I said, the OS doesn't typically exist in a miC unless you put one there.

Bit-wise operations are the most important thing for miC's that you won't see much of in the C books . A typical operation in a miC is to get a flag register from memory and mask it to see if some operation is completed (an analog to digital conversion perhaps). You'll be doing that over and over.
thanks for the tips. I have covered some of the topics you mentioned. Guess I will have to work on the remaining and start studying the microcontroller. I will start with Bitwise operations.
 

Related Threads on C in Embedded Systems

  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
3K
Replies
1
Views
9K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
1
Views
1K
Replies
4
Views
3K
Replies
2
Views
1K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
1
Views
1K
Top