|Chapter 2 - PIC information|
|Introduction to PICs and the Macintosh|
PICs are RISC based processors with their own 35 single word instruction set.
The code is written on the computer in a text editor and then downloaded to the
PIC's EPROM memory using a programmer device. Microchip does not support the
development of PIC programs on the Macintosh but a number of enthusiasts have
developed a very good set of software and hardware allowing other to develop code
PIC machine code is based around the working register, there are commands which load data in and out of the working and into other storage registers. Other commands perform operations on the working.
I used a shareware program called 'MacPIC' by Kevin Coble to write the code on the PIC. With MacPIC you can edit source code, assemble, simulate, program the EPROM and disassemble code. MacPIC connects via serial to my PIC programmer. Because MicroChip does not support the Macintosh platform I had to build my own PIC programmer. I followed a circuit design by Francis Deck with a few small modifications by myself.
|EPROM program description|
The PIC program starts off by initialising port directions (In or Out), and
setting up various options for the rest of the program. All the outputs are
turned off to make sure that the interface is in a standard state upon powerup.
The status LED is flashed on for a short time to indicate the program is
running correctly. The program then enters the main event loop.|
At the start of the main event loop, the registers which contain the previously processed command (if any) are cleared and the ElectroMac prompt 'EM>' is sent out on the serial port. It then waits for a command to arrive on the serial port. However if 'interrupts' are enabled and the input port is different form the previously stored value, then a serial message is sent to the computer along with the input port value. When a character is detected on the incoming serial line then it is received and stored in the command1 register. The command is then looked up in a table to see how many 'operand' characters are still to come. This is done to make sure that a <RETURN> character (ASCII value 13) is not interpreted as the command terminator rather than a piece of data for the command. The following character from serial is stored in the command2, command3 and command4 registers. It enters a loop until a return character is received.
Upon receiving a <RETURN> the command data received is processed. The first register command1 is looked up, if it is valid then the program jumps to the code for that command. If invalid then the error message 'ERR' is sent back to the computer. When a valid command has been processed then the status LED is flashed so the user knows that the interface is functioning and the program returns to the start of the main event loop. Note that the LED is turned on for a comparatively very long time, so that the next command is not missed the delay subroutine checks the serial line and exits if a serial character is detected.
|Command set description|
[A] - Get EPROM program version|
[B] - Get Digital Input value
[C] - Get Digital Output value
[D] - Set Digital Output value
[E] - Enable Input change interrupt
[F] - Disable Input change interrupt
[G] - Resets the interface
[H] - Get analogue input channel X
[I] - Get analogue output channel X
[J] - Set analogue output channel X to 16-bit value YZ
©1998 Nicholas Humfrey <e-mail> <www>