Author Topic: Programming in C  (Read 9313 times)

0 Members and 1 Guest are viewing this topic.

Offline AnsonTopic starter

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Programming in C
« on: April 09, 2013, 04:51:47 pm »
Sometime soon I should be getting a programmer for Atmel AVR and using Atmel Studio 6 for programming. Thanks Jack! My question is which book should I get to teach me programming? Keep in mind I can get easily confused, I'm not stupid (yet) but between the Lyme disease and medications my cognitive functions are very slow. I am also on a very tight budget and cannot afford to buy several books. So I need a book that is complete with all the available functions and variables you can use yet is fairly stupid friendly.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17849
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming in C
« Reply #1 on: April 09, 2013, 05:44:41 pm »
Get a copy of "programming in C" by Stephen G. Kochan

I do have to warn though that no book will teach you to program a microcontroller. ALL C books are aimed at PC programming and you will have to work out the missing pieces. I'm dyslexic and gave up and went with the arduino as it's made easier. I got fed up with people saying to me that I had to learn C before trying to program. Knowing C does not equate to knowing the nuances of mcu's which are a totally different environment from PC's
 

Offline helloworld922

  • Regular Contributor
  • *
  • Posts: 56
  • Country: us
    • My personal blog
Re: Programming in C
« Reply #2 on: April 09, 2013, 07:08:45 pm »
Any C book which focuses on the basics will do. Like simon said, MCU programming is quite unique from general PC programming, but that doesn't mean there aren't similarities. I actually didn't use a C book to learn C to begin with, but I did have experience with other programming before-hand and there are quite a few good free online resources.

Things that are probably most important for MCU programming:

1. Basic syntax.
2. Get familiar with low-level operations, particularly bitwise integer operations. A lot of MCU programming deals with manipulating registers which control various hardware functions.
3. Interrupts. This is a topic that really isn't covered in PC programming since it's generally too low-level, but is one of the basic essentials for MCUs.
4. If you want to get more advanced, learning some assembly wouldn't hurt. Sometimes you'll find there are some operations you need to do specifically which you really can't define in C (for example, a NOP instruction).

Things you can likely safely ignore:

1. Any PC-specific API usage (especially if it's specific to a certain platform)
2. Dynamic memory allocation
3. Multi-threading or more complicated parallel programming topics. This is generally an advanced PC topic anyways, and most MCU's only have one processor anyways. A few concepts may apply to when you want to interface multiple MCUs or are using interrupts, but they're generally handled differently .
4. Object oriented programming. Basic structures are useful, but I haven't found much use of more advanced object oriented topics such as inheritance, abstraction, and polymorphism.

Hopefully I haven't missed anything important, if so I'm sure the other members will chime in :P
 

Offline StevenB

  • Contributor
  • Posts: 36
  • Country: us
Re: Programming in C
« Reply #3 on: April 09, 2013, 07:24:39 pm »
 I learned C from The C Programming Language by Kernighan and Ritchie.  It's just the basics without PC centric stuff, and it's straight from the horse's mouth!

Beyond that, you can probably get free documentation for the specific platform you are programming for to fill in the gaps.
 

Offline AnsonTopic starter

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: Programming in C
« Reply #4 on: April 09, 2013, 07:28:24 pm »
there are quite a few good free online resources.

Yes there are and I have been looking at many of them. I have even downloaded .pdf copies of some AVR specific books and these would be helpful if I could read them. I cannot focus on my monitor long enough to finish more than a few sentences at a time. Small monitor and bad eyes. I can however print out a few useful pages and read them. This has been how I have been trying to learn thus far. I was hoping though that there would be a good book. Something like "Programming AVR in C for Dummies" but no one has written that yet.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17849
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming in C
« Reply #5 on: April 09, 2013, 07:29:01 pm »
I learned C from The C Programming Language by Kernighan and Ritchie.  It's just the basics without PC centric stuff, and it's straight from the horse's mouth!

Beyond that, you can probably get free documentation for the specific platform you are programming for to fill in the gaps.

if your new in programming that book is as concise as the language itself and may not explain too clearly enough
 

Offline MacAttak

  • Supporter
  • ****
  • Posts: 683
  • Country: us
Re: Programming in C
« Reply #6 on: April 09, 2013, 09:46:51 pm »
Best place to start is to skip the books at first and look at the example projects. Atmel Studio includes a number of samples if I recall.

And even if you are directly programming Atmel microcontrollers and not just using an Arduino, you can still use the sample sketches that are included with the Arduino software as a learning tool - the language and semantics used by Arduino's programming language are very similar to what you would be writing in C using Atmel Studio. You can look at those samples and review them line for line until you think you understand what they are doing (start with the simple ones before moving to the complex ones). If you have questions, try to figure out the answers to those questions using the Arduino language reference: http://arduino.cc/en/Reference/HomePage

Another great resource are the "Full" datasheets from atmel.com for the microcontroller chip you are using. There are a lot of small code snippets in there that illustrate how to use key features of the chip.

Other than that, most of the C language will eventually just start "making sense" to you after you have looked at it enough. The only part that might be a little difficult to grasp as a new programmer is the arithmetic operations. For the basics on that, I recommend starting with the Arduino documentation where it talks about direct port addressing: http://www.arduino.cc/en/Reference/PortManipulation. Using direct access to the port registers (PORTB, PORTC, PORTD) is much faster than the "easy" way of using digitalWrite() and digitalRead().... but it requires understanding how bitwise math works. Bitwise math is something most PC programmers don't have to deal with (they can get away with inefficient code)... but a microcontroller programmer is almost surely going to run into it sooner rather than later.
 

Offline MasterOfNone

  • Regular Contributor
  • *
  • Posts: 123
Re: Programming in C
« Reply #7 on: April 09, 2013, 10:51:07 pm »
there are quite a few good free online resources.

Yes there are and I have been looking at many of them. I have even downloaded .pdf copies of some AVR specific books and these would be helpful if I could read them. I cannot focus on my monitor long enough to finish more than a few sentences at a time. Small monitor and bad eyes. I can however print out a few useful pages and read them. This has been how I have been trying to learn thus far. I was hoping though that there would be a good book. Something like "Programming AVR in C for Dummies" but no one has written that yet.
A strange suggestion but if you have space for another monitor next to your current one could try to get an old 4:3 1240x1024 model and connect it to your PC/Laptop if it supports two screens. But rather than mounting it landscape (like normal) try to find a stand so you can mount it portrait.
If you do this PDF books and Datasheets displayed full screen would virtually fill the monitor. If you can read text books you may find that you can actually read a full page without having to zoom/scroll (providing you don't go for something like a tiny 15" model). 
Also having the examples/datasheet next to you so that don’t have to keep switching between the Development Environment and PDF reader is a real joy. Once you have worked like this you will not want to go back.
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming in C
« Reply #8 on: April 09, 2013, 11:31:00 pm »
Things you can likely safely ignore:

2. Dynamic memory allocation
3. Multi-threading or more complicated parallel programming topics. This is generally an advanced PC topic anyways, and most MCU's only have one processor anyways. A few concepts may apply to when you want to interface multiple MCUs or are using interrupts, but they're generally handled differently .
4. Object oriented programming. Basic structures are useful, but I haven't found much use of more advanced object oriented topics such as inheritance, abstraction, and polymorphism.
Disagree with these. Dynamic memory allocation is used in many embedded projects, multi-threading applies just as well to embedded RTOSes, and OO design techniques help improve overall software quality even if you're not using explicit object-oriented languages.

Also, you will inevitably need custom tools running on your PC, so learning how to write GUI software isn't a wasted effort (though plain C isn't necessarily the best option for that).

Offline Markybhoy

  • Regular Contributor
  • *
  • Posts: 59
  • Country: gb
Re: Programming in C
« Reply #9 on: April 09, 2013, 11:53:00 pm »
C Primer Plus by Stephen Prata is a good beginner book.
 

Offline AnsonTopic starter

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: Programming in C
« Reply #10 on: April 09, 2013, 11:53:28 pm »
Quote
A strange suggestion but if you have space for another monitor next to your current one could try to get an old 4:3 1240x1024 model and connect it to your PC/Laptop if it supports two screens. But rather than mounting it landscape (like normal) try to find a stand so you can mount it portrait.
If you do this PDF books and Datasheets displayed full screen would virtually fill the monitor. If you can read text books you may find that you can actually read a full page without having to zoom/scroll (providing you don't go for something like a tiny 15" model). 
Also having the examples/datasheet next to you so that don’t have to keep switching between the Development Environment and PDF reader is a real joy. Once you have worked like this you will not want to go back.

That's a great idea! I don't have another monitor but hey I can flip this one over for temporary will see how well it works. I can work on getting another monitor.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3460
  • Country: us
Re: Programming in C
« Reply #11 on: April 10, 2013, 03:49:27 am »
I learned C from The C Programming Language by Kernighan and Ritchie.  It's just the basics without PC centric stuff, and it's straight from the horse's mouth!

Beyond that, you can probably get free documentation for the specific platform you are programming for to fill in the gaps.

I assume you already know other programming languages?  If so, I agree with Steve, The C programming Language is really the best one to start.  When you are done with this book, you have a good idea of how things work in C.

If you don't know another programming language yet, start with BASIC to get an idea of programming first.  C is a great language to handle hardware.  Some call C "machine language done right" and I think with good justification.  It is however not the easiest to learn as a first programming language.

Rick
 

Offline ddavidebor

  • Super Contributor
  • ***
  • Posts: 1190
  • Country: gb
    • Smartbox AT
Programming in C
« Reply #12 on: April 10, 2013, 05:14:01 am »
Sometime soon I should be getting a programmer for Atmel AVR and using Atmel Studio 6 for programming. Thanks Jack! My question is which book should I get to teach me programming? Keep in mind I can get easily confused, I'm not stupid (yet) but between the Lyme disease and medications my cognitive functions are very slow. I am also on a very tight budget and cannot afford to buy several books. So I need a book that is complete with all the available functions and variables you can use yet is fairly stupid friendly.

Only a suggestion.

Buy a book about standard c, not c for avr.

When you've learn WELL standard c, you can find all the other information online and program all things of the word.
David - Professional Engineer - Medical Devices and Tablet Computers at Smartbox AT
Side businesses: Altium Industry Expert writer, http://fermium.ltd.uk (Scientific Equiment), http://chinesecleavers.co.uk (Cutlery),
 

Offline cwalex

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: au
Re: Programming in C
« Reply #13 on: April 10, 2013, 06:18:23 am »
I used this book and kit a few years ago and I had no knowledge of programming, avrs or microcontrollers. I found it really easy to follow and learnt a lot including some of the things that you won't see much in general c programming books like bit shifting and masking to control IO. Lots of other stuff that you really only use on microcontrollers but hardly ever in PC programming. It is pretty old so it would be best to follow it using avr studio 4 from the CD provided.

https://store-jwm4nhbo.mybigcommerce.com/c-programming-microcontrollers-book-and-projects-kit/

https://www.smileymicros.com
 

Offline MasterOfNone

  • Regular Contributor
  • *
  • Posts: 123
Re: Programming in C
« Reply #14 on: April 10, 2013, 08:03:09 am »
Quote
A strange suggestion but if you have space for another monitor next to your current one could try to get an old 4:3 1240x1024 model and connect it to your PC/Laptop if it supports two screens. But rather than mounting it landscape (like normal) try to find a stand so you can mount it portrait.
If you do this PDF books and Datasheets displayed full screen would virtually fill the monitor. If you can read text books you may find that you can actually read a full page without having to zoom/scroll (providing you don't go for something like a tiny 15" model). 
Also having the examples/datasheet next to you so that don’t have to keep switching between the Development Environment and PDF reader is a real joy. Once you have worked like this you will not want to go back.

That's a great idea! I don't have another monitor but hey I can flip this one over for temporary will see how well it works. I can work on getting another monitor.

I don’t know what type of monitor you have to do the test, but if you have a 1280x800 (or 1440x900) 16:9 monitor  it may not work as well as an old 4:3 1280x1024 monitor. Basically because it will have less horizontal pixels (when you rotate it) and the shape of a 16:9 might be too tall, so you won‘t use the whole screen. A 16:10 might be ok.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17849
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming in C
« Reply #15 on: April 10, 2013, 08:06:34 am »
the A4 page is 1:1.41 so the 1:1.5 ratio of a 15:10 is ideal. Personally i hate 16:9 monitors except on a rare occasion I'm watching a wide screen film.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3460
  • Country: us
Re: Programming in C
« Reply #16 on: April 10, 2013, 03:23:51 pm »
Actually, having two monitor in whatever orientation would be a good thing.  One view of the code, and the other view of the function specs.  Such as, while you are looking at your code MyMoney = fgets("blah",bleep,bloom); on the other monitor, you can check the function protocol for fgets().

With C and many other languages, you do want big screen to look at the code -  not physically big, but good resolution to be able to display many lines/column.  The more code you can fit on a screen, the easier it is to understand more of what is going on.   It is very hard to find problems looking at just 6 lines at a time and then page-up page-down.
 

Offline seb1982

  • Regular Contributor
  • *
  • Posts: 53
  • Country: gb
Re: Programming in C
« Reply #17 on: April 10, 2013, 03:51:37 pm »
Quote
It is very hard to find problems looking at just 6 lines at a time and then page-up page-down.

^ This!!  *Looks accusingly at Arduino IDE designers*...  >:( ::)
Smoking and melted? It was like that when I got here.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3460
  • Country: us
Re: Programming in C
« Reply #18 on: April 10, 2013, 04:52:35 pm »
Quote
It is very hard to find problems looking at just 6 lines at a time and then page-up page-down.

^ This!!  *Looks accusingly at Arduino IDE designers*...  >:( ::)

I do not intend any accusation of poor design; I have not seen the Arduino IDE.  If anyone took it that way … sorry…

Given that Arduino is open source, you take what you get.  Open source developers do what they can with what time/resource they have.  So anything is better than nothing.  I use open-source Java IDE, and thankful to the developers who made a tool I can use at no cost to me.

That said; if Arduino IDE shows only 6 lines or less, one may consider this a suggestion for future improvement.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17849
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming in C
« Reply #19 on: April 10, 2013, 05:25:11 pm »
Quote
It is very hard to find problems looking at just 6 lines at a time and then page-up page-down.

^ This!!  *Looks accusingly at Arduino IDE designers*...  >:( ::)

I do not intend any accusation of poor design; I have not seen the Arduino IDE.  If anyone took it that way … sorry…

Given that Arduino is open source, you take what you get.  Open source developers do what they can with what time/resource they have.  So anything is better than nothing.  I use open-source Java IDE, and thankful to the developers who made a tool I can use at no cost to me.

That said; if Arduino IDE shows only 6 lines or less, one may consider this a suggestion for future improvement.

Cool off, no one said anything. The arduino IDe can actually be the less obstructive than any. Although it opens as a small window it can be maximized and you only have a slim status window at the bottom so you have as much room as a word processor
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Programming in C
« Reply #20 on: April 10, 2013, 05:30:57 pm »
It is very hard to find problems looking at just 6 lines at a time and then page-up page-down.
The ability to show several files side-by-side, and several views of the same file should be minimum feature requirements for any serious programming editor by now.

Offline AnsonTopic starter

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: Programming in C
« Reply #21 on: April 10, 2013, 05:52:13 pm »
Anybody have an extra monitor laying around?  :P
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17849
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming in C
« Reply #22 on: April 10, 2013, 06:05:00 pm »
When I bought a secnd hand monitor for work they thought I was being clever and copying the people in the engineering office. What I had to explain was that I had dual monitors over a year before the company did and it was natural for me.

Now i am in the engineering office I appreciate having two of the same monitors..... one day
 

Offline AnsonTopic starter

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
Re: Programming in C
« Reply #23 on: April 10, 2013, 06:43:49 pm »
For my eyes i think I would need a pair of 21 inchers. :P I have in the past had a temporary dual monitor setup. It worked great for learning sketchup I could have the tutorial running in one window and the program in another. However my daughter stole my second monitor once I fixed her computer. Looking back maybe I should have told her I couldn't fix it.  >:D
 

Offline ddavidebor

  • Super Contributor
  • ***
  • Posts: 1190
  • Country: gb
    • Smartbox AT
Re: Programming in C
« Reply #24 on: April 10, 2013, 06:50:55 pm »
27" 2560x1440, work for three  O0
David - Professional Engineer - Medical Devices and Tablet Computers at Smartbox AT
Side businesses: Altium Industry Expert writer, http://fermium.ltd.uk (Scientific Equiment), http://chinesecleavers.co.uk (Cutlery),
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf