1. 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.
    Dismiss Notice

PIC language?

Discussion in 'Microcontrollers' started by uaefame, Nov 5, 2008.

  1. uaefame

    uaefame New Member

    Joined:
    Feb 22, 2008
    Messages:
    271
    Likes:
    9
    Location:
    Dubai, UAE
    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
     
  2. mississippi

    mississippi New Member

    Joined:
    Jun 21, 2005
    Messages:
    13
    Likes:
    0
    look at www.mikroe.com there you will find something more about this.
     
  3. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    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.

    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: Nov 6, 2008
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    If PWM is needed try a 18F1330 they are cool!
     
  6. uaefame

    uaefame New Member

    Joined:
    Feb 22, 2008
    Messages:
    271
    Likes:
    9
    Location:
    Dubai, UAE
    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
     
    • Like Like x 1
  7. Leftyretro

    Leftyretro New Member

    Joined:
    Mar 11, 2007
    Messages:
    1,420
    Likes:
    13
    Location:
    Hercules, California
    "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
     
  8. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    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)

    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...

    See Lefty's good advice.

    See the link I posted, and google.
     
    Last edited: Nov 6, 2008
  9. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    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.
     
  10. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    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

     
    • Like Like x 1
  11. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    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: Nov 6, 2008
  12. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    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...
     
  13. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada

    Hey WOW! I have got to play with that one. Excellent, thank you!
     
  14. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    PASCAL is a great language to learn in.:) Or, PASCAL++ which is MODULA2

    uaefame, you may want to look into the link blueroomelectronics posted.
     
  15. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    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
     
  16. colin mac

    colin mac New Member

    Joined:
    Jun 3, 2007
    Messages:
    367
    Likes:
    4
    Location:
    Ireland
    Some good C tutorials here. http://irc.essex.ac.uk/www.iota-six.co.uk/c/
    For a free C/C++ IDE, there's Code Blocks.
    It's being updated and comes with the gcc compiler. Code::Blocks
    Those can be installed on Windows by running two installers.
     
  17. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    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: Nov 6, 2008
  18. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    Looks like a good catch! I'll have to give it a spin, when I get some time.:D
     
  19. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Maybe things have changed for the better. I did it some years ago and I vaguely remember it being quite a pain in the butt.
     
  20. arhi

    arhi Member

    Joined:
    Apr 17, 2008
    Messages:
    887
    Likes:
    12
    Location:
    Belgrade, .rs
    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
     
  21. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    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.

    I hate to sound like a broken record, but...

     

Share This Page