Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming a PIC

  1. Jun 11, 2008 #1
    What do I need to program a PIC.
  2. jcsd
  3. Jun 11, 2008 #2


    User Avatar
    Science Advisor
    Homework Helper

    Depends what pic and what you want to do with it.
    You can program in assembler, C or basic (and probably a bunch of others)
    Generally the program is written on a PC and downloaded through a serial port but it varies.

    The wiki article is a good starting point http://en.wikipedia.org/wiki/PIC_microcontroller
  4. Jun 11, 2008 #3
    What language would you prefere or what one would work the best
    It is a PIC16F627 and PIC16F84
  5. Jun 11, 2008 #4


    User Avatar
    Science Advisor
    Homework Helper

  6. Jun 11, 2008 #5
    I'm just starting with PIC's
    I'm trying to learn how to use and program them.
  7. Jun 11, 2008 #6
    Can I use C++ to program the PIC?
    Where can I find the syntax,commands,etc.
  8. Jun 11, 2008 #7


    User Avatar
    Science Advisor
    Homework Helper

    Each family of pics will come with it's own development enviroment
    Ussually a simple commandline compiler/linker ( gcc for some of the more advanced ones) and maybe a simple ide.

    They generally use a version of C and will supply a C std library. This may have some functions missing, eg printf() and file io. It will also have extra functions to access IO pins and the ADC etc.
    You compile the program and then download it into the pic with the supplied tool, either directly into the PIC if it has a serial port or sometimes by putting the chip in a special socket programmer.
    The basic stamp is a popular pic that can be programmed in basic.

    You should probably start with a development kitthat will include a sample board, software and a manual, there are lots of these available very cheaply sincethey are used in lots of school/college electronics classes.

    You should also look at the 'atel AVR' it seems to have a very big hobby following http://www.avrfreaks.net/. I don't know any particular suppliers to recommend in your country.
  9. Jun 11, 2008 #8
    I get all of my components from Communica. I have baught a development kit and some PIC's but struggles to program it. It is connected to the PC via a serialcable. I just can't find any info on writing a program that works. I'm trying to use different languages and find the easeist and fastest way to write a program.
  10. Jun 11, 2008 #9


    User Avatar
    Science Advisor
    Homework Helper

    Embedded programming is tricky, it's hard to debug a program using only an Oscope!
    Does your dev kit come with a PC emulator that lets you test the program on the PC and check what it is doing?

    You also need to be sure that you are downloading the program correctly, try one of their examples first.
  11. Jun 11, 2008 #10
    No but I'v tried to write it on context and converting it to hex with MPASMWIN but it detects errors the whole time and I can't find the fault. The examples work but my programs don't work
  12. Jun 11, 2008 #11
    I have even treid using MPLAB but I can't connect with it to my programmer. I also don't understand the format that I must use so MPLAB can't compile it.
  13. Jun 12, 2008 #12
    If you post your program that doesn't work, plus the error messages from MPLAB, maybe we can help.

    Once you've managed to assemble the program with no errors, then MPLAB has a simulator that allows you to run your code on the PC and step through it line by line to find errors.

    The output from MPLAB is a hex file that should be understood by most, if not all, device programmers.

    It's also useful to know which of the many hundreds of different pics you are trying to program.
  14. Jun 12, 2008 #13
    What words do I use while programming my pic. Where can I find the words that I need to know when programming the pic?
  15. Jun 12, 2008 #14
    Which PIC is it?

    Go on, just give us a hint...

    If you want data on PIC programming then try the Microchip website.

    It's a remarkably good place to start since they make the things.


    This shows you the range of 8 bit PIC chips.

    The PIC16F84 used to be the beginner's chip of choice.

    Download the pdfs.

    This is the pdf for the PIC16F84A


    Section 7 shows the instruction set, i.e. the words you need to program the thing in assembler.
    Last edited by a moderator: Apr 23, 2017
  16. Jun 12, 2008 #15
    Thank you for your help it realy helped
  17. Jun 12, 2008 #16
    Preffered language C or C++

    Wat is your preffered language?
    I want to start with an easy language and wants to learn to use it propperly.
    Is assembler,C,C++,or BASIC the easiest one to start with or are there easeir ones?
    Please let me know! I want to use it to program PIC,etc. I'm wery eager to start programming them.
  18. Jun 12, 2008 #17


    User Avatar

    I learned C++ first and found it pretty easy to move to other languages from there. BASIC would probably be the easiest to first learn to program with, but it's pretty limited.
  19. Jun 12, 2008 #18


    User Avatar
    Homework Helper

    Assembler would give you a better understanding of how computers implement programs, but it's not necessary, and as a learning tool, should only be used for very small projects.

    Since C is a sub-set of C++, it would be easier to learn, provided you're doing simple things like console programs or very simple Windows programs. Again you'd be more exposed to how windows programs work with C as opposed to C++.

    In C, your code includes a message handling loop, and you handle the few message types your program will deal with, and pass the other messages onto a default handler. In C++, the message handling loop is handled outside of your program (it's handled by the C++ library), and there is a class that includes functions for all the message types, and your program includes a sub-class that "overrides" the message types your program will deal with. Message types include things like button clicks, keystrokes, or movement of the mouse pointer into and out of regions on a screen.
  20. Jun 12, 2008 #19
    C and C++ are generally taught as beginning languages in today's universities, but they are not very good languages for that purpose, in my opinion.

    BASIC is a much higher level language, and allows you to concentrate more on the actual mechanics and logic of programming, rather than the language peculiarities and syntax.

    QuickBasic was really the first language I ever learned, and still a great language in my opinion, but being 16 bit, it is extremely outdated. I would recommend http://www.freebasic.net/" [Broken], which is nearly 100% compatible. Unfortunately, it is not very well-known like Qbasic was and Visual Basic is, so you are not going to be able to talk to many other FreeBasic programmers or get support from a large community like you would with C, C++, or Visual Basic.

    Ultimately, you will probably want to learn C++ if you are serious about programming, so maybe it is better to learn it from the beginning; however, if you want to concentrate on learning to program (and learn the difficult peculiarities of C later), then I would recommend a high level language like FreeBasic.

    It is much more important to understand programing controls and algorithms. Once you understand how to program, you can learn the syntax of any computer language and apply it.
    Last edited by a moderator: May 3, 2017
  21. Jun 12, 2008 #20


    User Avatar
    Science Advisor
    Homework Helper

    For pics your choice is pretty much assembler or c
    There are some embedded c++ compilers but the lack of most C++ runtime features mean you are really programming 'c with classes'.

    C is a lot easier to get started with than assembler, but it is low enough level to give you an understanding of memory and bit operations that you need for uC work.

    There is a PIC called a BasicStamp that you can program in basic but it's not really worth it. It costs more and has lower capabilities.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook