Thread: Strange question here: do you know how to program a PIC?

  1. #1
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    Location
    Valhalla
    Posts
    56

    Strange question here: do you know how to program a PIC?

    Im basically asking if programming a PIC microcontroller is something every programmer should know. It may look like a weird question but whatever, I think you get the point. It looks interesting and today someone asked me to help with PIC programming. I couldnt help much, of course, Im not very familiar with it. I was wondering if this knowledge is something basic I should have. I don't even know its instruction set.

    Thanks
    2B OR !2B? That is the question!

  2. #2
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    >> I don't even know its instruction set.
    Wha...???

    Do you mean change the offset(remap) of the IRQs it fires? It's pretty simple. This article at osdev has some same C code on how to do it, and a general discourse on it's purpose. But, if you want to learn something relevant, learn the to manipulate the APIC. It has replaced the PIC in SMP environments.

    Just wondering, but why where they asking about the PIC?

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Quote Originally Posted by Dante Wingates View Post
    Im basically asking if programming a PIC microcontroller is something every programmer should know.
    No. Simple as that. It may be a good learning experience and some jobs may require this kind of programming close to the hardware, but it's surely not something, every developer has to know.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Embedded programming is more for electrical engineers, since it's so close to hardware. You need to have quite a bit of knowledge of electronics to be able to use one effectively.

  5. #5
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    Location
    Valhalla
    Posts
    56
    >> I don't even know its instruction set.
    Wha...???

    Do you mean change the offset(remap) of the IRQs it fires? It's pretty simple. This article at osdev has some same C code on how to do it, and a general discourse on it's purpose. But, if you want to learn something relevant, learn the to manipulate the APIC. It has replaced the PIC in SMP environments.

    Just wondering, but why where they asking about the PIC?
    I meant I don't know how to program one of those microcontrollers in Assembly language since I don't know its instruction set. Sorry, doesnt it make sense? I thought you had to know its instruction set in order to use it.

    Someone contacted me asking for help with a project with microcontrollers, and unfortunately I couldnt help as I never had to work with PIC microcontrollers before. The fact is that after that I got a bit interested, since it looks, well, interesting. I was wondering if I should already know...

    No. Simple as that. It may be a good learning experience and some jobs may require this kind of programming close to the hardware, but it's surely not something, every developer has to know.
    Thats what I thought, but I believe that the more you know, the better you are.

    Embedded programming is more for electrical engineers, since it's so close to hardware. You need to have quite a bit of knowledge of electronics to be able to use one effectively.
    Yes, the request came from a student of eletrical engineering

    Thanks
    2B OR !2B? That is the question!

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Last year and the year before that I grew very interested in learning how to program for the Z80 processor. This happened mostly because I developed a strong nostalgia for the ZX Spectrum. It's been a fun ride ever since. But one of the first things I realized when I was learning all about it, was how versatile this processor was. While searching for other things I could do with it, I was rapidly diverted into the world of PICs and its legion of fans.

    I have not actually delved much into it yet. But it is definitely on my list of purchases for next year, or maybe the following year depending on circumstances. So far, I've only dabbled with PIC emulators and I must say it really is not only for electrical engineers. Far from it. Most PIC programmers are hobbyists in fact. Programmers like you and me that happen to do PIC programming and the required basic electronics as an hobby, side-by-side with battleship modeling, puzzles and reading nerdy science fiction books.

    Just so you have an idea what you can do (and PIC programming is generally cheap) check this rather inspirational tutorial (Simple Bike Computer). And you can grow from there. Create your own thermostats, house alarms, automatic lighting system, ... alas, domestic electronics of all sorts. (Build Your Own Microcontroller Projects)

    As a side note, you don't actually need to do it in assembly. PICs and most micocontrollers can be programmed in a variety of languages, most notably C. But arguably assembly is the best way and the one giving you more power to control the processor with precision and with minimum memory requirements. Anyways, it's --- at least to me -- a rather exciting world I want to soon join. The opportunity to learn basic electronics, develop hardware gadgets of all sorts and securing my current understanding of assembly programming, all while having fun and sporting a fulfilling hobby, is too good to pass.

    If curiosity kills you, go for it.

    EDIT: There's a closely related, totally fun, and recent thread on these forums that further makes you realize the hobbyist nature of microcontroller programming. Search for the "Quadrocopter" thread.
    Last edited by Mario F.; 11-22-2010 at 04:10 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Quote Originally Posted by Dante Wingates View Post
    I meant I don't know how to program one of those microcontrollers in Assembly language since I don't know its instruction set. Sorry, doesnt it make sense? I thought you had to know its instruction set in order to use it.
    Oh. I was thinking Programmable Interrupt Controller.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Dante Wingates View Post
    Im basically asking if programming a PIC microcontroller is something every programmer should know. It may look like a weird question but whatever, I think you get the point. It looks interesting and today someone asked me to help with PIC programming. I couldnt help much, of course, Im not very familiar with it. I was wondering if this knowledge is something basic I should have. I don't even know its instruction set.

    Thanks
    Actually the PIC (and other microcontrollers) is a very specialized area. Most have their own development platforms, including both software and hardware emulators... Some even have their own versions of C.

    It's pretty unlikely you'd get mixed up with them unless you were messing with robotics, ham radio, remote control or some other hardware intensive undertaking.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    For the PIC, you can get a PICKit (the official hardware programmer) for $30, the chip for $2, a breadboard for $10, a few miscellaneous components (voltage regulator, crystal, capacitors) for $1, and maybe a few LEDs to see what's going on. That should get you started.

    Basic electronics knowledge will also be useful (ohm's law, capacitors, diodes, transistors).

    If you need some help with that feel free to ask. The datasheet is very resourceful, but will sound like Greek (or choose your favourite language that you don't speak) if you don't know all the jargon. After all, they are written by professional engineers for professional engineers.

    It's certainly very possible for hobbyists to do some embedded coding for fun, but it's difficult to do it for money because most "real world" applications are hardware heavy, and to do that kind of things you need to be a certified "professional engineer", etc.

    It sure is a lot of fun, though. I'm sure you will enjoy it.

    But no, it's not something most programmers should know.

    EDIT: There's a closely related, totally fun, and recent thread on these forums that further makes you realize the hobbyist nature of microcontroller programming. Search for the "Quadrocopter" thread.
    That would be mine . It is a hobbyist project for me, but I'm also a third year electrical engineering student, and still find the electronics aspect quite challenging.

    If you want to build something that moves, I suggest starting with some kind of robot on wheels. It will allow you to build something exciting (read: moves!), while learning about all sorts of sensors (ultrasonic, infrared, light), actuators (motors, sound?, light?), and microcontroller programming.

    I found this site really good for the basics -
    How to Build a Robot Tutorial - Society of Robots

    Or, if you want to do pure software, and as little hardware as possible, I suggest starting with the Arduino. The circuit is already built, programming is simple, gets power from USB, etc. It's convenient to have around, too. I don't use it for my real projects anymore, but it's convenient when I just want to hack something together quickly, or generate some arbitrary digital waveform to check something.

    To start in electronics, you'll also want to get a multimeter, and soldering equipment (both can be had for $10, for low end equipment).

  11. #11
    Registered User
    Join Date
    Nov 2010
    Posts
    1
    Well i just joined this forum like a minute ago and i was actually looking for some help on this as well.

    But so far i purchased just the Pickit 1 Flash Starter kit which is around R100 here in south africa (Around 15US$) and it works pretty well for doing what i need it to do for just getting past that learning curb.

    The great thing about it is that it comes with both a C and assembly compiler, a few tutorials and a a whole lot of source code thats well commented.
    You just might needa take a crash course in basic electronics and learn about how the registers and stuff works.

    I'd advise to get this first and if you dont like it,its not that much money gone to waste, from an engineers point of view though its pretty useful,but for a high level programmer its not something you'll really need but it'll be a nice learning experience .

    PICkit 1 Flash Starter Kit

  12. #12
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    Location
    Valhalla
    Posts
    56
    Agree completely with Mario R. It sounds like a lot of fun and a good learning experience, too good to pass. Unfortunately Im not very familiar with electrical engineering... Learning something new sounds like some work but Im sure it will be fun. Im not very good with hardware, I only know what assembly taught me.

    Basic electronics knowledge will also be useful (ohm's law, capacitors, diodes, transistors).

    If you need some help with that feel free to ask. The datasheet is very resourceful, but will sound like Greek (or choose your favourite language that you don't speak) if you don't know all the jargon. After all, they are written by professional engineers for professional engineers.

    It's certainly very possible for hobbyists to do some embedded coding for fun, but it's difficult to do it for money because most "real world" applications are hardware heavy, and to do that kind of things you need to be a certified "professional engineer", etc.
    Yep... Im a noob in that area... But its certainly the kind of thing I like... I have to try it now.

    I'll just have some fun, don't care about making money... After all those useful and inspirational links, I just cant help it...
    2B OR !2B? That is the question!

  13. #13
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    (Slightly OT) I've been told that Atmel AVRs are superior to PICs. Here's a nice comparison article: PIC vs. AVR smackdown

    Probably the most relevant point is that AVRs have a larger instruction set (not mentioned in the article) and programming in its assembly is less painful. You might want to check out some of the comparison articles to decide if you want to use PICs or AVRs.

  14. #14
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    AVR vs PIC is like Windows vs Mac in electronics. Even worse, because they do 95% of the same thing. Both sides have ample supply of fanboys.

    I am an AVR fanboy myself, but have used both in projects, as well as ARM and MCS-51.

    Just pick one and stick with it. You won't go wrong with either for a beginner.

    Only switch if you know there's something on the other side that you need. Eg. USB or ethernet support (you won't need them anytime soon).

    They are very similar. If you are familiar with one, it will only take you 20 minutes of reading to learn to use the other.

    Just close your eyes and pick.

  15. #15
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    If you have a robotics club around you might want to talk to them. They are probably heavily favoured towards either PIC or AVR and it is probably a good idea to roll the same as them to get the best help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very strange behavior from very simple program
    By somekid413 in forum C Programming
    Replies: 5
    Last Post: 12-17-2009, 08:53 PM
  2. Replies: 2
    Last Post: 10-10-2009, 10:38 PM
  3. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  4. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  5. Random Question Assign Program
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2005, 10:04 PM