Goodbye, Mr. (Micro)chips
Data banks use the same idea. In the device I am using, there are two bank bits. When you hand code assembly you can select exactly when to set or clear each bank bit. For example, if you know the bank bits are currently both zero, you can switch to bank 2 with a single instruction:
Then one more instruction can pick bank 3, later:
bsf STATUS, RP0
If you don't like setting the bits, you can use the fake
banksel instruction (or
pagesel for code pages). That's handy, but it always sets or clears all bank bits even if none needed changing. So if symbol XYZ is in bank 2, for example, you can write:
The assembler dutifully generates:
bcf STATUS,RP0 bsf STATUS, RP1
This seems like just a shorthand notion, but it becomes a very necessary shorthand when you use a C compiler. When you use a C compiler, or even the relocatable assembly language, you don't know which bank (or page) things will be in until link time. So you wind up using
pagesel) for almost everything. That's a lot of extra instructions. You can optimize some of these with sufficient horsepower, but it isn't easy to get them all.
So the PIC — at least the 16F family — is one of the few processors I usually just write assembly language and forget the C compiler. If I am especially lazy, I have a copy of PICBasic Pro. Don't laugh. Basic is a pretty good fit for the architecture. Not very stack intensive and full of global variables. It is a nice match and the compiler has a lot of libraries for doing things easily. Sure, it isn't too efficient either, but it does a nice job of rapid prototyping. Like the C compilers, it integrates with the MPLAB software, too.
MPLAB comes with a fairly nice simulator built in, so if you ever wanted to try your hand at PIC programming, you are a free download away. The simulator can even simulate things like buttons, LEDs, and even UARTs, although the simulation control can be harder than the program, or it seems that way to me.
Next time I'll show you a little about the new MPLAB-X and what it can do. Do you use the PIC? If so, what's your choice of language? Leave a comment and share your experiences.