Hello, programmer
You’ve seen that we have already used some PICs (that colour sensor video some posts ago?), so we have programmed them. You’ve seen, too, that we have made a program (in Perl) that generates some assembly code to load the information of a sudoku into memory.
But, we haven’t really got into programming yet, have we?
Since we have already coded a first version of our sudoku solving program (and a second version too, actually), the time for a ’source code’-post is not far. But before that, let’s get ready to code!
In this post, we’ll explain how to set some tools up to ease the coding process.
Firstly, we will need PIC Simulator to test our programs. Let’s explain a bit how it works.
That’s what it looks like when you start PIC Simulator. You can select there which microcontroller you are going to be working with, and at which clock speed. Also, note the section dedicated to General Purpose Registers (GPRs).
If you go to Tools -> Assembler, a text editor will open. Here’s where you are supposed to write the code. Or you can File -> Open another .asm file. Then, Tools -> Assemble & Load and the program gets loaded and ready to be run.
At this point, one basically uses Simulation and Rate tabs at the main window of the program.
The breakpoints manager (Tools -> Breakpoints Manager) is also very helpful (particularly, if you are bug-hunting). This is how it looks:
So far, so good. But the editor that comes with PIC Simulator kind of sucks, and you do realize that when you are writing a program with many lines of code.
We didn’t like it’s poor color-coding, or the fact that it didn’t have code regions. So we decided to move on to an editor that had it all: Notepad++.
It’s a great text editor and, best of all, allows you to define your own languages (user defined languages, yay!).
So we defined a PIC16F language, and that way we had colour coding that we liked, and regions! (They start with the keyword ‘;region’ and end with ‘;endregion’)
If you want to use yourself this language with Notepad++, you just have to download the userDefineLange.xml file and paste it into the folder that opens when you type ‘%APPDATA%\Notepad++’ and press OK at Start->Run.
Well, I think that’s all. You learnt how to use the basic functionality on PIC Simulator and you have a powerful editor to program in. Next, we’ll give you some source code to play around. Later dudes and dudettes!


June 11, 2008 at 4:16 pm
Good Job guys!
I have tested the simulator and it is awesome!!
Besides it is also cool to write pic assembler but… Wouldn’t be better to use a pic c compiler? xD Nonetheless that is a good point for learning.
I am expecting your next post!! ;-)
June 12, 2008 at 10:28 pm
Wep, I prefer a c compiler too.
PICC may be a good one.
Classical flow control operators are always useful.
Nice post borja!!!!
June 12, 2008 at 10:37 pm
Hehe thanks.
Yeah well, using C could have made some parts easier… but isn’t assembly beautiful? I mean, it makes you feel so powerful and… you get this… minimalistic pleasure.. xDD
Every clock cycle matters, my friend.
September 19, 2008 at 8:15 am
Hai!
Well, I’ve always used Assembly code (and told this guys to xD) because it lets us have a total control on the peripherals in the PIC, and I personally don’t “trust” C compilers because I don’t know the code that’s being written in the PIC.
For example, enabling an Analog-to-Digital converter. If the register to enable it is in bank 0 and you know you are already in bank 0, you won’t modify STATUS register to switch to it. Maybe the function that enables it in a C compiler adds those 2 lines to switch registers. That’s an example of my distrust. I don’t know if those lines are really added as I have not compiled any C code into Assembly yet.
I may someday take a look at some C compilers, but I’ll stay in Assembly by now, it’s comfortable xD
September 19, 2008 at 9:57 am
That, my friend, is one late reply. =P
September 19, 2008 at 10:36 am
Just realized these comments were here xD