Whats the best resource to learn Assembly language for PIC microcontroller's

Seidleroni picture Seidleroni · Sep 24, 2009 · Viewed 18.9k times · Source

I'm going to start working on a project where I need to have a decent understanding of Assembly language for the PIC microcontroller's. I'm intimately familiar with C/C++, so I know how to code for the most part, and I have done many projects for the PIC already so I understand the architecture, but have done all my programming for it in 'C'.

Is there a good book or website which does a good job explaining what all the Assembly commands mean and how to do fairly simple tasks (blink LED's, basic math, etc...) for the PIc microcontroller?

Edit: The primary purpose of this post is to request resources for learning Assembly, not debating the merits of C vs Assembly in the PIC's, or whether the PIC is a 'good' microcontroller to use. I am using a PIC18 microcontroller if that makes any difference.

Answer

Clifford picture Clifford · Sep 24, 2009

There is more that one PIC architecture, with significantly different instruction sets. Microchip do not have the architectural consistency of Atmel AVR for example. So you need to specify what you are using - PIC12, 16, 24, 32 for example.

So first of all I would suggest avoiding PIC assembler on the basis that what you learn on say a PIC12, that may not be very applicable to a PIC24. Secondly I would avoid using a PIC at all if I possibly could as a software developer - though I concede there are other considerations, and you may have no choice.

What you may have a choice over is not using assembler. While the lower end PICs are not perhaps best suited to C code generation, that's the compiler writer's problem; it is still more cost effective in terms of development time to use C where possible. On the other hand for high volume products, if you can fit the code into a smaller part by using assembler, that may be a factor. Deciding you need assembler before you have tested a C solution is often a 'premature optimisation'. Even if the C implementation fails size or time constraints, you can just call it a prototype, and recode it to meet constraints. Doing than may still be faster than starting assembler coding from scratch and struggling with both design and instruction set at the same time. Tell your boss you'll prototype it in C, then when it meets requirements, no one will want to waste money re-coding it is sone non-portable, unmaintainable assembler code.

Finally to answer your question, assuming you need to get work done quickly and efficiently, use Microchip's examples and app-notes as much as possible, and familiarise yourself with the instruction set from the manufacturers instruction set reference. The instruction set for the lower-end parts is not large. For day-to-day work I like to use an "Instruction set reference card" as an aide-mémoire - it summarises all the essential details of each instruction, usually in a couple of pages - print it double sided and laminate it! ;). Here is a PIC16 example