PIC microcontrollers

For PIC microcontrollers there is among many programs the Gnu PIC assembler gpasm (and xgpasm a front end for it) that comes with the gputils package https://gputils.sourceforge.io/.

To get debug info run gpasm <prgm name>.asm things as processor to be used can be set inside the asm file or passed as command line parameter. This produces the hex file for the processor but also a cod file used for the Gnu PIC simulator gpsim http://gpsim.sourceforge.net/.

The simulator has a gui where the code file can be opened. After that the code can be debugged in side the simulator. The simulator has many windows as asm, memory. Some of them are really advanced as breadboard and scope.

The breadboard shows the chip where arrows indicate if the pins are input or outputs and if they are low green or high read. Clicking on a input pin toggles its its level.

For a nice simulation there are other devices necessary to be put on the breadboard. Therefore add the library libgpsim_modules first, then add the desired modules to the breadboard. Now wires are needed to connect the modules to the PIC. Wires are nodes, that have to be created first and in a seconds step they need to be connected. To connect them click on the pins and select the node, repeat this until done, don't worry you will not see a lot. Then click Trace all and the wire appears. Modules can produces signals that are used to stimulate inputs, therefore the word stimulus appears.

Even gpsim is a gui program, the console is a key element, where at the gpsim> prompt commands can be entered. **gpsim> frequency 4000000 sets the clock frequency to 4MHz and can be read back via **gpsim> frequency


Also the modules and their effect including passing the signal from one end of the wire to the other require that the simulator is running. The simulator has different modes: Realtime with GUI is the most intensive of them and is therefore well suited for the first tests.

gpsim -c <breadboard>.stc -s <program>.cod it how it is called.

Observing the stc files shows that they just contain gpsim console commands, therefore it is a good habit to edit them with the missing stuff as frequency 4000000 to define the quartz used.

Figure 3.11. gpsim


Passing data to the usart can typed in directly in the USART console window when usart.console=true or at the console where gpsim got started usart.console=false and then usart.tx=82

There is also picprog a command line programmer, with a JDM style programmer picprog --erase --burn --input <filename>.hex --pic /dev/ttyS0

Finally there is an IDE piklab that has a gui (unfortunately the gui seems not to work on my machine, alternatively there is picdev). It is a front end for picasm and supports programming PICs and

Linurs startpage