Programming a PIC: What You Need

  • Thread starter Thread starter bleeker
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around the requirements and considerations for programming PIC microcontrollers, specifically the PIC16F627 and PIC16F84 models. Participants explore various programming languages, tools, and approaches, as well as share personal experiences and challenges faced while learning to program these devices.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants mention that programming languages for PICs include assembler, C, and BASIC, with preferences varying based on familiarity and project requirements.
  • One participant notes that assembler can yield better performance but is tedious, while C is easier to use.
  • Another participant inquires about using C++ and seeks information on syntax and commands for programming PICs.
  • Several participants discuss the importance of development environments and tools, mentioning that each PIC family has its own setup, including compilers and IDEs.
  • One participant expresses difficulty in programming their PIC and seeks advice on writing functional code, indicating challenges with error detection and compilation.
  • Another participant suggests sharing code and error messages for assistance, highlighting the utility of simulators in debugging.
  • Some participants debate the best language for beginners, with opinions on the ease of learning BASIC versus C or C++, and the trade-offs involved.
  • There is mention of the BasicStamp PIC, which can be programmed in BASIC, but some argue it may not be worth the investment due to its limitations.

Areas of Agreement / Disagreement

Participants express a range of opinions on the best programming language for PICs, with no clear consensus on which is the easiest or most effective for beginners. The discussion includes both supportive and critical views on various languages and tools.

Contextual Notes

Some participants emphasize the need for specific development kits and environments, while others note the challenges of debugging embedded programs without advanced tools. There are also references to the limitations of certain programming languages in the context of PIC microcontrollers.

Who May Find This Useful

This discussion may be useful for beginners looking to learn about programming PIC microcontrollers, educators teaching electronics, and hobbyists exploring embedded programming.

bleeker
Messages
13
Reaction score
0
What do I need to program a PIC.
Programms,Languages,etc.
 
Technology news on Phys.org
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
 
What language would you prefere or what one would work the best
It is a PIC16F627 and PIC16F84
 
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
 
I'm just starting with PIC's
I'm trying to learn how to use and program them.
 
Can I use C++ to program the PIC?
Where can I find the syntax,commands,etc.
 
Each family of pics will come with it's own development environment
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.
 
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.
 
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/" , 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.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
1K
Replies
65
Views
5K
Replies
86
Views
3K
Replies
38
Views
4K
Replies
65
Views
5K
  • · Replies 102 ·
4
Replies
102
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
4K
Replies
16
Views
3K
Replies
4
Views
2K
  • · Replies 49 ·
2
Replies
49
Views
4K