Programming a PIC: What You Need

  • Thread starter bleeker
  • Start date
  • Tags
    Programming
In summary: Assembler is slow and tedious to program but you can squeeze most performance and space out of the design, while 'c' is a lot easier.
  • #1
bleeker
13
0
What do I need to program a PIC.
Programms,Languages,etc.
 
Technology news on Phys.org
  • #2
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
 
  • #3
What language would you prefere or what one would work the best
It is a PIC16F627 and PIC16F84
 
  • #4
Depends what you know / what you want to do.
Assembler is slow and tedious to program but you can squeeze most performance and space out of the design, while 'c' is a lot easier.

According to the reviews this book covers that chip.
https://www.amazon.com/dp/0071408517/?tag=pfamazon01-20
 
  • #5
I'm just starting with PIC's
I'm trying to learn how to use and program them.
 
  • #6
Can I use C++ to program the PIC?
Where can I find the syntax,commands,etc.
 
  • #7
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.
 
  • #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.
 
  • #9
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 let's 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.
 
  • #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
 
  • #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.
 
  • #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.
 
  • #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?
 
  • #14
bleeker said:
What words do I use while programming my pic. Where can I find the words that I need to know when programming the pic?

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.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=64

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

http://ww1.microchip.com/downloads/en/DeviceDoc/35007b.pdf

Section 7 shows the instruction set, i.e. the words you need to program the thing in assembler.
 
Last edited by a moderator:
  • #15
Thank you for your help it really helped
 
  • #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.
 
  • #17
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.
 
  • #18
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.
 
  • #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:
  • #20
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.
 
  • #21
I had to program a PIC last fall in an electronics course, having never programmed in assembly, I picked it up fairly quickly. I also got a better appreciation for my brother in laws job since he writes assembly for embedded programming everyday.
 
  • #22
There are demo versions of the HiTech C compiler available on their site.

It integrates with MPLAB for reasonably seamless development.

And it's easier than assembler.

Particularly PIC assembler.
 

1. What is a PIC and why do I need to program it?

A PIC (Programmable Integrated Circuit) is a small computer that can be programmed to perform specific tasks. It is commonly used in electronic devices such as appliances, cars, and medical equipment. Programming a PIC allows you to customize its functions for your specific needs.

2. What equipment do I need to program a PIC?

To program a PIC, you will need a PIC programmer, which can be purchased online or at electronics stores. You will also need a computer with programming software, a USB cable, and a breadboard to prototype your circuit.

3. What programming language should I use to program a PIC?

The most commonly used programming language for PICs is C. However, some programmers also use assembly language for more complex projects. It is important to research which language is best suited for your project and to have a basic understanding of programming concepts.

4. Can I program a PIC without any prior experience?

While it is possible to learn how to program a PIC without any prior experience, it is recommended to have a basic understanding of programming concepts and some experience in coding. There are also many online resources and tutorials available to help beginners learn how to program a PIC.

5. Are there any safety precautions I should take when programming a PIC?

Yes, it is important to take certain safety precautions when programming a PIC. Make sure to always disconnect power sources before connecting or disconnecting any components. Additionally, follow the manufacturer's instructions and use caution when handling the PIC programmer and other electronic components.

Similar threads

Replies
65
Views
3K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
4
Views
532
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
2
Views
732
  • Programming and Computer Science
2
Replies
49
Views
3K
  • Programming and Computer Science
Replies
9
Views
912
  • Programming and Computer Science
Replies
1
Views
325
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
15
Views
1K
Back
Top