Author Topic: C learning  (Read 12293 times)

0 Members and 1 Guest are viewing this topic.

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
C learning
« on: September 16, 2010, 02:27:51 am »
whats the best way to finish learning C? like i know how to make small programs, that perfrom small calculations and that make small decitions. I can how to scan, print, while loops... But still not to a point where i can program avr chips or feel really confortable with C..

Like i can do arduino code with no problem (i know im not that great on it but i feel a bit confortable to a point that i built a small robot (http://forums.adafruit.com/viewtopic.php?f=25&t=14402))

On AVR i can do realllllly basic stuff like turn a light on and off... but thats prob about it...

So should i go back to making C programs? or should i keep going forward with AVR

And with any of choices what should i do to get better? or to cross that basic line?
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11712
  • Country: my
  • reassessing directives...
Re: C learning
« Reply #1 on: September 16, 2010, 02:38:32 am »
learn C in PC first then move to mcu programming when you comfortable with C.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
Re: C learning
« Reply #2 on: September 16, 2010, 02:52:08 am »
learn C in PC first then move to mcu programming when you comfortable with C.

what would the best way for me to do that? a book?
 

Online EEVblog

  • Administrator
  • *****
  • Posts: 38722
  • Country: au
    • EEVblog
Re: C learning
« Reply #3 on: September 16, 2010, 02:57:29 am »
There are two issues at play here.
The first is knowing C and it's syntax. That simply comes with experience, and it makes no real difference what your target platform is (PC, AVR, PIC etc)

The second is knowing how to access the resources on the AVR chip. Things like setting up registers, using peripherals, reading/writing I/O etc. If you stick with Arduino then most of this is hidden from you.

But if you really want to learn microcontrollers then you have to learn to start using the resources on the chip. Start with I/O and then work your up to things like timers, interrupts, UART's, I2C/SPI etc. You usually need to do this on physical hardware so you can see some form of physical result. C really has nothing to do with learning stuff like this, it's the same process for assembler, BASIC, C or whatever, it's just that the syntax is different.

Dave.
 

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
Re: C learning
« Reply #4 on: September 16, 2010, 03:41:12 am »
Start with I/O and then work your up to things like timers, interrupts, UART's, I2C/SPI etc

umm is there a guide on this? or a book?
 

Online EEVblog

  • Administrator
  • *****
  • Posts: 38722
  • Country: au
    • EEVblog
Re: C learning
« Reply #5 on: September 16, 2010, 04:05:28 am »
Start with I/O and then work your up to things like timers, interrupts, UART's, I2C/SPI etc

umm is there a guide on this? or a book?

There are dozens of books on programming AVR chips.
Sorry, can't recommend any off-hand.

Dave.
 

Offline Zad

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: gb
    • Digital Wizardry, Analogue Alchemy, Software Sorcery
Re: C learning
« Reply #6 on: September 16, 2010, 04:06:30 am »
The first thing to do is to get hold of the technical manual for the product. You will be able to download a PDF of it from the manufacturer's site. (Oh for the days of printed manuals - they were so much easier to read!) That will have all the details of the UARTs, timers/counters, I/O registers, interrupts etc. Most embedded micros operate in a very similar manner. In theory they should be identical, but each manufacturer has their own idea of how best to do things, and bugs always creep in, so don't forget to download any errata sheets too.

There are books around on programming various micros. I can't really recommend any particular book, so have a browse around Amazon.

Offline DJPhil

  • Frequent Contributor
  • **
  • Posts: 511
  • Country: 00
Re: C learning
« Reply #7 on: September 16, 2010, 07:00:39 am »
There are two issues at play here.
The first is knowing C and it's syntax. That simply comes with experience, and it makes no real difference what your target platform is (PC, AVR, PIC etc)

The second is knowing how to access the resources on the AVR chip. Things like setting up registers, using peripherals, reading/writing I/O etc. If you stick with Arduino then most of this is hidden from you.

But if you really want to learn microcontrollers then you have to learn to start using the resources on the chip. Start with I/O and then work your up to things like timers, interrupts, UART's, I2C/SPI etc. You usually need to do this on physical hardware so you can see some form of physical result. C really has nothing to do with learning stuff like this, it's the same process for assembler, BASIC, C or whatever, it's just that the syntax is different.

Dave.
I've been struggling with this myself recently. I've been hitting the books hard in the last year or so learning analog stuff, but I haven't programmed seriously since Commodore basic. Enter the MSP430 Launchpad kit . . .

I'm still working my way through literature (MSP430 Microcontroller Basics has my approval), but I'm starting to see what Dave means above. I thought of computer languages as more of a deep investment, something you take pains to learn and lean heavily on as you expand. It seemed like a big choice to pick one for micros, but really it isn't. If you've got a fair grasp of logic and control structures you'll probably do fine. I haven't formally learned a shred of C and it's not the syntax that's not making sense when I first read code, it's the detailed manipulation of the dark corners of the peripherals and things like that. I'm sort of picking up the syntax as I go, and I'm sure when I actually start working with the chip instead of reading about it (projects have backed up a bit) it'll be no big deal compared to remembering how to set up the timers!

I hope that sets you at ease a bit. :)
 

Offline joelby

  • Frequent Contributor
  • **
  • Posts: 634
Re: C learning
« Reply #8 on: September 16, 2010, 07:06:22 am »
The best way is to have some project in mind. I find it very difficult to play around with a programming language for the sheer joy of it. If you have a useful goal in mind, you'll be able to eventually achieve some sense of self-satisfaction!


 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: C learning
« Reply #9 on: September 16, 2010, 09:36:55 am »
The second is knowing how to access the resources on the AVR chip. Things like setting up registers, using peripherals, reading/writing I/O etc. If you stick with Arduino then most of this is hidden from you.

But if you really want to learn microcontrollers then you have to learn to start using the resources on the chip. Start with I/O and then work your up to things like timers, interrupts, UART's, I2C/SPI etc. You usually need to do this on physical hardware so you can see some form of physical result. C really has nothing to do with learning stuff like this, it's the same process for assembler, BASIC, C or whatever, it's just that the syntax is different.

I would've thought using assembler would be the best way to learn about the hardware because you have no choice but to learn the different instructions and registers.

The best way is to have some project in mind. I find it very difficult to play around with a programming language for the sheer joy of it. If you have a useful goal in mind, you'll be able to eventually achieve some sense of self-satisfaction!

Yes, I've struggled with some PIC tutorials recently, not because I don't understand it but because it's boring so I thought of a simple project and it became easier.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14020
  • Country: gb
    • Mike's Electric Stuff
Re: C learning
« Reply #10 on: September 16, 2010, 09:44:54 am »
Quote
learn C in PC first then move to mcu programming when you comfortable with C.
NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources

The best way is to have some project in mind. I find it very difficult to play around with a programming language for the sheer joy of it. If you have a useful goal in mind, you'll be able to eventually achieve some sense of self-satisfaction!

Absolutely - By far the best way to learn pretty much anything is to have a definite project with fairly well-defined goals. It should be something that can be done in incremental steps.
The reason is that when you come up against a problem, you have to work through it instead of moving on to something else.
This is how you really learn stuff.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
Re: C learning
« Reply #11 on: September 16, 2010, 12:13:14 pm »
Quote
learn C in PC first then move to mcu programming when you comfortable with C.

NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources

lol...  ???
« Last Edit: September 16, 2010, 12:21:48 pm by SuperMiguel »
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11712
  • Country: my
  • reassessing directives...
Re: C learning
« Reply #12 on: September 16, 2010, 12:34:09 pm »
what would the best way for me to do that? a book?
with IDE such as Visual C++, and specifically console programming, you'll directly see the result on the console, such as:

int i = 12;
i =+ 13;
printf(i);

(not sure if thats correct, i've been playing more C for mcu lately (asm to be precise!) and not doing C for PC for a while) and you'll know your syntax and semantic is correct. my previous advice is if you are almost total zero experience in C, you'll get familiar and see the result quickly with C in PC. with mcu, you have to download the code, use IC debugging or simulated debugginng in order to debug your software, extra registers need to be learnt, silicon bugs etc. for the book, i suggest topic like... "C/C++ introduction". My best C bible is "C++ nuts and bolts for experienced programmers" by Larry Levitsky, Osborne McGraw Hill.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11712
  • Country: my
  • reassessing directives...
Re: C learning
« Reply #13 on: September 16, 2010, 12:45:04 pm »
Quote
learn C in PC first then move to mcu programming when you comfortable with C.
NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources
that is correct if you have not program to the maximum limit of a particular system you are working on (a PC in my context).... or you "half learn" programming C in PC and algorithm.
i have to admit that i've program in a very abundant of resources system (compared to 6 pin mcu), but can you believe i also hitted the limit and have to find the best programming style for it? have to design a specific assembly inline codes in PC? and when i moved to a very small mcu, i have to admit that i felt its very limiting, but can you believe that i made it working?

i'm not into portability and easiness of varying mcu's brand, features etc yet. if i let my points out, sure lots of people will argue, so i'd rather not to talk about it ;)... software and hardware... are two very different beasts.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
Re: C learning
« Reply #14 on: September 16, 2010, 12:57:24 pm »
software and hardware... are two very different beasts.

 :) but you need a bit of software to control hardware.And thats where i get confused, on whether i should focus more on hardware or on software for now that im learning.
« Last Edit: September 16, 2010, 01:20:14 pm by SuperMiguel »
 

Online EEVblog

  • Administrator
  • *****
  • Posts: 38722
  • Country: au
    • EEVblog
Re: C learning
« Reply #15 on: September 16, 2010, 01:35:37 pm »
Quote
learn C in PC first then move to mcu programming when you comfortable with C.
NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources

The best way is to have some project in mind. I find it very difficult to play around with a programming language for the sheer joy of it. If you have a useful goal in mind, you'll be able to eventually achieve some sense of self-satisfaction!

Absolutely - By far the best way to learn pretty much anything is to have a definite project with fairly well-defined goals. It should be something that can be done in incremental steps.
The reason is that when you come up against a problem, you have to work through it instead of moving on to something else.
This is how you really learn stuff.

I'll third that.
Keep it simple and try and get each peripheral feature working one at a time, don't try and do it all at once. Building your program up step by step is the best way.
That's not just for beginners either, but is a common practice for most programmers.

Dave.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: C learning
« Reply #16 on: September 16, 2010, 02:31:45 pm »
I learned a lot reading...

The C programming language
Brian W. Kernighan
Dennis M. Ritchie

Many people consider it as the C bible.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: C learning
« Reply #17 on: September 16, 2010, 03:27:10 pm »
NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources
Agreed, especially if you're going to learn assembly.

The PC has hundreds of powerful instructions, most MCUs have under 100 and baseline PICs have 33 simple instructions.

The PC has many general purpose registers, baseline PICs only have one working register and the rest are part of the RAM.


 

Offline SuperMiguelTopic starter

  • Regular Contributor
  • *
  • Posts: 205
Re: C learning
« Reply #18 on: September 16, 2010, 03:49:06 pm »
NO! no! no! You will get into bad habits learning on a platform that has essentially unlimited resources
Agreed, especially if you're going to learn assembly.

The PC has hundreds of powerful instructions, most MCUs have under 100 and baseline PICs have 33 simple instructions.

The PC has many general purpose registers, baseline PICs only have one working register and the rest are part of the RAM.


how important is to learn assembly?
« Last Edit: September 16, 2010, 04:41:31 pm by SuperMiguel »
 

Offline lhc

  • Contributor
  • Posts: 40
Re: C learning
« Reply #19 on: September 16, 2010, 07:24:16 pm »
http://www.avrfreaks.net
Go to the forums and read tutorials it will show you how to address different parts of AVR uC in C. Start with basic I/O tutorials and go from there.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: C learning
« Reply #20 on: September 16, 2010, 07:45:23 pm »
how important is to learn assembly?

For optimization.

If you know how a CPU works, then you can take advantage of the C instructions knowing how they translate into ASM code.

For example, an integer division by 32 in C code would be done by a novice like this:

Code: [Select]
int a, b, c;

a=450;
b=32;
c= a/b;

But a person who has used ASM would definitely know that it can be optimized...

Code: [Select]
int a, c;

a=450;
c= a>>5;
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: C learning
« Reply #21 on: September 16, 2010, 08:33:16 pm »
I don't know C.

I know some BASIC (VB and QBaisc) and a PC assembly (16-bit and 32-bit).

Now I know some baseline PIC assembly PIC12F509 and have completed my first program today but I'll start a new thread for that.

I tried C awhile ago but never got on with it and actually find assembler easier.

I'll probably try C again in the future it will be for an MCU. I can see the advantages: once learnt it's probably easier and it's easier to port to a new device.

I'll stick with PIC assembly for now though.
 

Offline djsb

  • Frequent Contributor
  • **
  • Posts: 964
  • Country: gb
Re: C learning
« Reply #22 on: September 16, 2010, 09:22:57 pm »
I learnt C from this book (C Programming- a modern approach)

http://knking.com/books/c2/index.html

For microcontroller C programming (PIC24) I use a Microchip Explorer 16 board that complements the following book which uses the board.

http://www.amazon.co.uk/exec/obidos/ASIN/0750682922/embeddedsys08-21

Books are a very personal thing and I find writing style and presentation very important. I found them very easy to learn from.

David.
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V8+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: C learning
« Reply #23 on: September 16, 2010, 09:29:25 pm »
I've found, what appears to be a good C tutorial here:
http://www.howstuffworks.com/c.htm

Maybe I'll give it a go one day but I'll get the hand of PIC assembler first.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14020
  • Country: gb
    • Mike's Electric Stuff
Re: C learning
« Reply #24 on: September 16, 2010, 11:04:42 pm »
Quote
how important is to learn assembly?
You can't beat assembly for learning the intimite details of the hardware of lower-end processors like PICs, however I'd say that as a minimum you should at least be able to read it and have a reasonable idea of what it's doing, so you can see what a C compiler is doing, and in particular if it's doing something stupid, or taking you too literally when you do something stupid.

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf