Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC language?

Status
Not open for further replies.

uaefame

New Member
Hello everyone,

I started learning how to program a PIC using assembly language. It's becomming complicate to rotate a servo motor using assembly language. Therefore, I decided to shift to C language.

I am willing to spend time learning C language. I already download the C compiler for student for PIC 18FX. I have serveral questions to address.

1- To interact sensor and servo motor togather, what is recommend as a programming language C or assembly in term of difficuilties?
2- If C is recommend, Can you suggest PIC18F to start? and Some link to start learning C language for that PIC?

Thanks in advance
 
1- To interact sensor and servo motor togather, what is recommend as a programming language C or assembly in term of difficuilties?
You'll probably find C easier and quicker than asm as your programs get more complex. I love asm, but C is quicker and easier to write and to read (especially after a few weeks/months of not looking at a given piece of code).

2- If C is recommend, Can you suggest PIC18F to start? and Some link to start learning C language for that PIC?
Why not a 18F1320? Any 18F is fine though. They're all very similar.

If you've never programmed in C before at all, you might be better off learning C on the PC. That way you can follow one (or several) of the bazillions of tutorials out there. You have easy to use stdin and stdout that way, so you get good, easy to use feedback. With a PIC you have to write your own (or at least know how to use the libs to get the IO working). When you're brand new to the language that can be difficult. Get a feel for the language on the PC and then move to PIC.

If you run Windows, you'll have to find a C compiler. I do not know what's available for free. Compilers are expensive!!! There are probably some good demos available though.

If you run Linux, all the languages you need are probably already installed. Full C compiler and Python and Ruby and whatever else your distro has packaged with it. Everything is free! :D If you're a programmer, Linux is the greatest! SO much nicer and easier to deal with than crappy Windoze.

Don't bother with C++, which is a superset of C. C++ is C plus a bunch of object oriented stuff added on. You won't normally use the OO stuff on a PIC.
 
Last edited:
Interesting, So if i take a course in C language. It will be easy for me to program PIC using C language.

BTW, I am wondering if I am programming with C does i need to refer to PIC manual while programming?

Q2> Can you suggest a link to learn Basic of C language for PIC Programming.

Thanks in advance
 
Interesting, So if i take a course in C language. It will be easy for me to program PIC using C language.

BTW, I am wondering if I am programming with C does i need to refer to PIC manual while programming?

Q2> Can you suggest a link to learn Basic of C language for PIC Programming.

Thanks in advance

"I am wondering if I am programming with C does i need to refer to PIC manual while programming?"

Oh course you will need to reference the PIC data sheet. While there are 'core' functions, structures and rules common to any C compiler, any useful application written on a PIC will have to utilize input and output devices unique to the PIC chip being programmed.

Lefty
 
You'll probably find C easier and quicker than asm as your programs get more complex. I love asm, but C is quicker and easier to write and to read (especially after a few weeks/months of not looking at a given piece of code).


Why not a 18F1320? Any 18F is fine though. They're all very similar.

If you've never programmed in C before at all, you might be better off learning C on the PC. That way you can follow one (or several) of the bazillions of tutorials out there. You have easy to use stdin and stdout that way, so you get good, easy to use feedback. With a PIC you have to write your own (or at least know how to use the libs to get the IO working). When you're brand new to the language that can be difficult. Get a feel for the language on the PC and then move to PIC.
Not only great advice, very well stated!:)

If you run Windows, you'll have to find a C compiler. I do not know what's available for free. Compilers are expensive!!! There are probably some good demos available though.

If you run Linux, all the languages you need are probably already installed. Full C compiler and Python and Ruby and whatever else your distro has packaged with it. Everything is free! :D If you're a programmer, Linux is the greatest! SO much nicer and easier to deal with than crappy Windoze.

Don't bother with C++, which is a superset of C. C++ is C plus a bunch of object oriented stuff added on. You won't normally use the OO stuff on a PIC.
You can set up gcc under windoz, but even setting it up has quite a steep curve...:D

when I googled: windows + C compiler + free

there were tons of links, the first:
Free C / C++ Compilers and Interpreters (thefreecountry.com)

Interesting, So if i take a course in C language. It will be easy for me to program PIC using C language.

Programming is programming, and languages are languages. If you understand programming, it is easier to learn a given language...
If you understand C it will be easy to write a program for a PIC...

BTW, I am wondering if I am programming with C does i need to refer to PIC manual while programming?
See Lefty's good advice.

Q2> Can you suggest a link to learn Basic of C language for PIC Programming.

Thanks in advance

See the link I posted, and google.
 
Last edited:
BeeBop said:
You can set up gcc under windoz, but even setting it up has quite a steep curve...
Ya, I tinkered with that once. Gave up and used a "liberated" copy of Borland C instead. :p

Setting up Python and the PyGame libs on windoze is also not as simple as it could/should be.

I love Linux for programming (web dev stuff too). Everything is free and either already installed or just a few clicks away. Very good tools. And the OS is well documented - not all "trade secrets" like windoze.
 
Microsoft's visual studio would be a very good tool to learn C. It has a feature call intellisense that makes coding a bit easier. One feature will show you the .h code associated code in a .c file. For example in the editor you can click
TIMER_INT_OFF​
and
#define TIMER_INT_OFF 0b01111111 // Interrupts disabled​
will show up in the code definition window. There is also a completion tool where you type the first few characters and you can pick from a list of variables that you have defined. Great to have around when you do not know if you used ledOn or ledsOn sort of thing.

A simple but handy item is code snippets. You store bits of commonly used code as snippets that you select from a menu to paste into your code.

Some people will say it is a crutch. It may be, but it is a useful one. The Visual Studio IDE is more complex, everything is a tradeoff.

The C++ version will compile normal C code.

When you switch to PICs and MPLAB you can run both MPLAB and visual studio at the same time, each with its own project file in the same folder. This allows you to edit the code in VS and compile and run it in MPLAB. MPLAB has an option to automatically reload files if they are changed externally. It works fairly well.


3v0

Not only great advice, very well stated!:)



You can set up gcc under windoz, but even setting it up has quite a steep curve...:D

when I googled: windows + C compiler + free

there were tons of links, the first:
Free C / C++ Compilers and Interpreters (thefreecountry.com)
 
That's one of the things I really liked about the Swordfish IDE was the helpful modules library whenever you use a module.
When I started with PASCAL I really found this now free editor / interpreter really handy.
Alice Pascal
PC and ATARI! versions.
 
Last edited:
Ya, I tinkered with that once. Gave up and used a "liberated" copy of Borland C instead. :p

Setting up Python and the PyGame libs on windoze is also not as simple as it could/should be.

I love Linux for programming (web dev stuff too). Everything is free and either already installed or just a few clicks away. Very good tools. And the OS is well documented - not all "trade secrets" like windoze.

I had it running with Eclipse on my last windoz box for working on the LPC boards I have. It was too much trouble to do again.:( So I no longer play with my (expensive) ARM boards, which were also a huge climb up a curve...

I loved when mac came out with OSX, and would probably still be on that os, had there been any support for microcontrollers under it then...

I had a subscription to code warrior for the mac, and it included a tool chain for windows as well as mac. I think I still have it installed on my PC. OSX included gcc, so there was no longer a great need for the code warrior tools... but what a great company - Metrowerks!

It is a funny sort of story how I ended up with the PIC and not the freescale...
 
Microsoft's visual studio would be a very good tool to learn C. It has a feature call intellisense that makes coding a bit easier. One feature will show you the .h code associated code in a .c file. For example in the editor you can click
TIMER_INT_OFF​
and
#define TIMER_INT_OFF 0b01111111 // Interrupts disabled​
will show up in the code definition window. There is also a completion tool where you type the first few characters and you can pick from a list of variables that you have defined. Great to have around when you do not know if you used ledOn or ledsOn sort of thing.

A simple but handy item is code snippets. You store bits of commonly used code as snippets that you select from a menu to paste into your code.

Some people will say it is a crutch. It may be, but it is a useful one. The Visual Studio IDE is more complex, everything is a tradeoff.

The C++ version will compile normal C code.

When you switch to PICs and MPLAB you can run both MPLAB and visual studio at the same time, each with its own project file in the same folder. This allows you to edit the code in VS and compile and run it in MPLAB. MPLAB has an option to automatically reload files if they are changed externally. It works fairly well.


3v0


Hey WOW! I have got to play with that one. Excellent, thank you!
 
That's one of the things I really liked about the Swordfish IDE was the helpful modules library whenever you use a module.
When I started with PASCAL I really found this now free editor / interpreter really handy.
Alice Pascal
PC and ATARI! versions.

PASCAL is a great language to learn in.:) Or, PASCAL++ which is MODULA2

uaefame, you may want to look into the link blueroomelectronics posted.
 
Some good C tutorials here. **broken link removed**
For a free C/C++ IDE, there's Code Blocks.
It's being updated and comes with the gcc compiler. Code::Blocks
Setting up Python and the PyGame libs on windoze is also not as simple as it could/should be.
Those can be installed on Windows by running two installers.
 
There is also a setting in VS that will load files change outside (in MPLAB) but it has a nag box that pops up asking if you want to do so. Could be a setting to not show the box.

3v0

Actually, I often work in conTEXT: a free Text Editor for Windows

and am used to the nag box. In fact, with an old cob-webbed mind like mine, it helps remember what I'm doing.:eek:
 
Last edited:
Have to use windoze from time to time (usb osc sw works only on windoze, easyPic4 can be programmed only from windoze ... go my self a pickit2 but never tried it out from linux) so I in general use vi on linux to write program and then C18 if 18F.. or mikroC if 16F .. to compile

futz, have you manage to get some "good" gui for develop/compile/program on linux .. anything I tried was just not "worth it" .. not to mention that I never tried gcc for pic :) .. should do it, and compare the asm output from mikroC/C18/CSCC and GCC .. might get interesting results :) .. if you know of any IDE .. (like eclipse plugins or some other app), please enlighten me :) - I have piklab, but never managed to get anything done using it :(

mine advice for the uaefame would be more/less what anyone said
- use C
- learn both C and ASM, you will need them both
- for 18F use C18 c compiler from microchip, most of the examples and app notes are written init, it is free and pretty much good. The microchip ide is pretty nice and easy to work with, and you can program directly from the ide using pickit2 or junebug or many other programmers
- for 12F, 16F ... you will not find any "cheep&good" compiler, I personally use mikroC and CSC C ... both are very good and both cost ~100E, there is also swordfish C but I never tried it hence I cannot compare it to these two (purchased mikroC as it is local company and then got CSC C with some dev kit I purchased for USB FT* ...)

In general, you will have to use ASM inside C application in many cases when some precision or speed is needed, whatever C compiler you decide to use, make sure
- it has good support (forum, knowledge base, example base)
- it has "community"
- does it integrates with your "ide" (for e.g. mikroC uses its own ide, does not integrates with microchip tools, cannot program using pickit2... CSC C has own ide that is great but also integrates into microchip tools)
- what libraries you get and in what "form" (for e.g. mikroC has libraries for "almost everything" but all libraries are closed source and you cannot modify them, CSC C gets with less libraries but they are all in source and you can modify them to better suit you)

and then, learn the tricks for that C compiler. Compile some simple code snippets and look at the asm output .. for example the for loop or even single IF .. function call too ... for example, simple function call will take from 9 to 25 instructions depending on the compiler, or even things like "a = !a", this will be 1/2/3/4 instructions depending on the compiler, it is good to know and somethimes important to know things like that.

hope this helps
 
futz, have you manage to get some "good" gui for develop/compile/program on linux .. anything I tried was just not "worth it" .. not to mention that I never tried gcc for pic :) .. should do it, and compare the asm output from mikroC/C18/CSCC and GCC .. might get interesting results :) .. if you know of any IDE .. (like eclipse plugins or some other app), please enlighten me :) - I have piklab, but never managed to get anything done using it :(
Ya, Windoze has the best microcontroller tools. I've done some stuff with Piklab, but I run a windoze box at my electronics table. It does dual-boot Ubuntu, but normally runs Windows.

As for you never trying GCC for PIC, have you used any of Microchip's compilers? They're all GCC based, as far as I know.

- for 12F, 16F ... you will not find any "cheep&good" compiler, I personally use mikroC and CSC C ... both are very good and both cost ~100E, there is also swordfish C but I never tried it hence I cannot compare it to these two (purchased mikroC as it is local company and then got CSC C with some dev kit I purchased for USB FT* ...)
I hate to sound like a broken record, but...

futz said:
If you're looking for a C compiler I recommend SourceBoost BoostC. The demo is only code size/RAM limited - works for all supported PICs. And when you hit the limits of the demo, a full license for the compiler is only about $75! Compare with C18's price of ~$500 and PICC's price of ~$1000. It's a no brainer! Better yet, BoostC comes with both 16F (supports some 12F also) and 18F compilers.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top