Programming a PIC

  • Thread starter bleeker
  • Start date
  • #1
13
0

Main Question or Discussion Point

What do I need to program a PIC.
Programms,Languages,etc.
 

Answers and Replies

  • #2
mgb_phys
Science Advisor
Homework Helper
7,774
12
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
13
0
What language would you prefere or what one would work the best
It is a PIC16F627 and PIC16F84
 
  • #4
mgb_phys
Science Advisor
Homework Helper
7,774
12
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
13
0
I'm just starting with PIC's
I'm trying to learn how to use and program them.
 
  • #6
13
0
Can I use C++ to program the PIC?
Where can I find the syntax,commands,etc.
 
  • #7
mgb_phys
Science Advisor
Homework Helper
7,774
12
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
13
0
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
mgb_phys
Science Advisor
Homework Helper
7,774
12
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.
 
  • #10
13
0
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
13
0
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
156
0
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
13
0
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
156
0
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
13
0
Thank you for your help it realy helped
 
  • #16
13
0
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
Vid
401
0
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
rcgldr
Homework Helper
8,671
506
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
246
6
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
mgb_phys
Science Advisor
Homework Helper
7,774
12
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
Dr Transport
Science Advisor
Gold Member
2,308
428
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
156
0
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.
 

Related Threads for: Programming a PIC

  • Last Post
Replies
2
Views
3K
Replies
5
Views
2K
Replies
2
Views
4K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
1
Views
864
  • Last Post
Replies
11
Views
2K
  • Last Post
Replies
14
Views
2K
Replies
22
Views
3K
Top