The one we're going to use is the PIC32MX110F016B, which is a microcontroller built by Microchip. The PIC32MX110F016B has 19KB of flash memory and 4KB of RAM, which is not a lot of memory, but more than we probably need for the labs we're going to implement on it.
The PIC32MX110F016B costs $2.35, but a running system requires a breadboard, some bypass capacitors, and a 3.3V power supply. The breadboard is the most expensive part of the system, but of course we already have a number in the lab. For this first MIPS project, you'll build the system on a breadboard, and modify a program I wrote.
In this session, we connect up a PIC 32MX110F016B microcontroller in a circuit,
copy a small program into it, and run it. Here is the circuit diagram for
the microcontroller circuit:
Here is a photo of a completed version:
You can see the wires to the battery clip in the picture, but the battery happens to be unplugged.
The program begins at the label
and goes through the instruction on each line, then moves to the next line, unless the instruction is a branch, jump, or return instruction. Instructions in those families execute the instruction following (the branch delay slot) and then transfer control to another sequence of instructions.
The names of the various pins and registers are hidden inside a file which we include at the top of the program in the line
Then complete the program. I only wrote code to put my initials onto one digit, but I want you to make your name flow across the two 7-segment displays, so that (for example) they'd display:
St / tE / EP / PH / HE / En/ n / T / TA / AY / YL / Lo / or / r / / S / ...
Set up a new project, by choosing File > New Project. This will be a Microchip Embedded project, a Standalone Project. On the next screen, specify the 32-bit MCU Family, and the first chip on list is the PIC32MX110F016 chip; on the following screen, say that you'll debug using the simulator. On the next screen, you choose the xc32 toolchain, of which the assembler is a part, and on the final screen you give the project a name.
To add a new file with the .S extension (case sensitive!) choose File > New File > Other > emptyfile and type the name and .S extension.
To test your code, choose Debug > Debug project
The simulator supports breakpoints; that is, you can mark a spot for execution to stop by clicking in the left margin of the builtin editor (on the line number.) You can step through your code in the simulator using the icons, or you can just let it run from breakpoint to breakpoint. You can view various parts of the CPU memory by choosing Window > PIC Memory Views, and viewing the Peripheral Registor memory for PORTA and PORTB tells you which pins the program has turned on -- not quite as convenient to read as the LEDs on the board, but easier to debug with.
When you think you've found all the bugs, you can program the flash in the microController.
Place the PicKit2 programmer on the six pin programming header as shown: Plug the PicKit2 USB cable into the PC. I usually remove the capacitor from pin1 to ground at this point, although sometimes things work without doing so.
Check your circuit by typing the command
This is called a "probe" command; if all goes well, the software will report on your chip. If it can't find it, you may have a wiring error.
Now program the chip by typing (in my case)
If all goes well, the software will tell you how many bytes it programmed and how long it took.
Run your program by removing the programmer, replacing the capacitor between pin 1 and GND, and connecting the power.