Which programming language should I learn first?

JoeAnt

Joined Apr 15, 2011
6
What C version/compiler are you using?

Don't get me wrong working through the examples is by no means a bad way of learning, it's just a personal thing that I find it easier to learn when I've got an application in mind.
 

JoeAnt

Joined Apr 15, 2011
6
Im not sure if MPLAB installs a C compiler as standard. Just had a look on the Microchip website, you can download 'HI-TECH C Lite' for free.

I use CCS C, it's not free, unless you know where to look... You can download a demo version though.
 

Thread Starter

epic_newb

Joined Apr 10, 2011
44
you're a lifesaver :)

I figured it would have a c compiler default but guess not.

Although I was able to install the c compiler I wasn't able to make some simple code work. Any idea why this code wouldn't work?



#include <stdio.h>
{
printf("To C, or not to C: that is the question.\n");
return 0;
}
 

JoeAnt

Joined Apr 15, 2011
6
How exactly are you testing the code? What are you running it on?

That code would work if you were writing it to run on Windows etc.
 

Thread Starter

epic_newb

Joined Apr 10, 2011
44
Well, I'm on mplab IDE.

I started a project using project wizard. picked the PIC18F4220 although I don't think it matters too much, selected HI-TECH Universal Toolsuite and then I attached my file containing the code to my project under source file. Then I attempted to build the project but for some reason it failed.
 

nerdegutta

Joined Dec 15, 2009
2,684
Rich (BB code):
#include <stdio.h>
{
printf("To C, or not to C: that is the question.\n");
return 0;
}
If this code was compiled to an *.exe-file, I'll guess it would work. But I do not think you could get the PIC 18F4220 to do something useful with it.

I started a project using project wizard. picked the PIC18F4220 although I don't think it matters too much, selected HI-TECH Universal Toolsuite and then I attached my file containing the code to my project under source file. Then I attempted to build the project but for some reason it failed.
Well, I think it matters. Read the datasheet to the PIC18F4220. There you will find lots of info.
 

AlexR

Joined Jan 16, 2008
732
The C function "printf() prints a string to the standard output device (screen). Microcontrollers don't by default have screens attached or if they do you have to provide your own driver so the compiler would not know what to do with that instruction.

Do you want to learn the C language in general or as applied specifically to microcontrollers?

MPLAB only compiles code for PIC microcontrollers and does require you to have a knowledge of the the internal workings of PIC chips.

If you are just after a C compiler to learn the C programming language take a look at OpenWatcom http://www.openwatcom.org/index.php/Main_Page It's a free C compiler/IDE that is suitable for learning C.
 

JoeAnt

Joined Apr 15, 2011
6
Are you working from a book? If you are and that code's taken from it then it's probably aimed at Windows, Linux etc.

If you were to compile that code (not in MPLAB) into a .exe, it would run on windows command line and would print to the screen.

When writing C for microcontrollers it's slighty different, you have to set up config registers etc. to make the PIC run. You would then have to interface the PIC to either a PC or LCD module.

If you're not in any hurry to actually use microcontrollers you could carry on writing code for Windows until you get the hang of it, then when you feel like it make the sideways step to writing for microcontrollers.

If you do want to go straight to microcontrollers then you're probably better off getting a book aimed specifically at microcontrollers. 'Programming 8-bit PIC Microcontrollers in C' is a good one.

Sorry about the essay :)
 

cheezewizz

Joined Apr 16, 2009
82
There's plenty of good sites for learning C on PICs too.... http://www.gooligum.com.au/tut_midrange_C.html is a good one and covers both CCS and hitech C syntax.
Or if you're more into PCs rather than microcontrollers there's this one which is handy... http://publications.gbdirect.co.uk/c_book/

I am quite surprised no one pointed out one flaw from the code you posted earlier mind. You're missing a 'main' function in your little snippet.. As you're returning 0 I'm assuming this is meant to be code for a PC rather than PIC
Rich (BB code):
#include <stdio.h>

int main()
{
    printf("To C, or not to C: that is the question.\n");
    return 0;
}
should work. Or
Rich (BB code):
#include <stdio.h>

void main(void)
{
    printf("To C, or not to C: that is the question.\n");
    while(1)
    {
    }
}
for the PIC version.
 

Thread Starter

epic_newb

Joined Apr 10, 2011
44
Oh wow. thanks guys! Yeah, I was under the assumption that it would compile regardless as long as the code was valid in c. I didn't know I would need to learn c specifically for microcontrollers. I think I will learn "pc c" first and then switch over. But thanks for all your help :)

I shall try openwatcom :)
 

qlue

Joined Apr 15, 2011
5
I would say C but it's like driving a fast motorcycle on a twisty mountain road at first, it takes a while to get in the zone. So a training wheel language like BASIC would be a good choice for a total beginner.

http://www.sfcompiler.co.uk/swordfish/download/index.html
BASIC is not a good language to start with unless it's the only language you ever intend to learn! But I think most people would agree that C is the basis of most modern languages and a good foundation. :)
epic_newb said:
A teacher I used to know always talked about how assembly is the best language because it is such a basic machine language. I tried learning it but that didn't work out well. I think learning "C" first will allow me to learn it in the future if i need to.
EXcept that every cpu has it's own instruction set and every implementation of a given cpu has it's own memory map and hardware IO routines! :p So there is no single 'Assembly Language'
 
Top