Picsimlab MANUEL
Picsimlab MANUEL
Picsimlab MANUEL
Download: github
PICSimLab on Twitter
PICSimLab on Discord
1 Introduction 2
2 Install 4
2.1 Stable version executables download . . . . . . . . . . . . . . . . . . 4
2.2 Unstable version executables download . . . . . . . . . . . . . . . . 4
2.3 Install from source . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.2 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3.3 macOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3.4 Experimental version . . . . . . . . . . . . . . . . . . . . . . 5
3 Simulator Interface 6
3.1 Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Interaction with the Board . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Remote Control Interface . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 Picture Map Reference . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Boards 14
4.1 Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2 McLab1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 K16F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 McLab2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.5 PICGenios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.6 PQDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.7 Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.8 Franzininho DIY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5 Experimental Boards 23
5.1 Blue Pill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 uCboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.3 gpboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.4 STM32 H103 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.5 X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1
CONTENTS 2
5.6 Curiosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.7 Curiosity HPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.8 Xpress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6 Serial Communication 28
6.1 Com0com Installation and Configuration(Windows) . . . . . . . . . . 28
6.2 tty0tty Installation and Configuration (Linux) . . . . . . . . . . . . . 30
7 Debug Support 32
7.1 MPLABX Integrated Debug (picsim and simavr) . . . . . . . . . . . 32
7.2 Arduino IDE Integration (simavr) . . . . . . . . . . . . . . . . . . . 32
7.3 avr-gdb Debug (simavr) . . . . . . . . . . . . . . . . . . . . . . . . 33
7.4 arm-gdb Debug (qemu-stm32) . . . . . . . . . . . . . . . . . . . . . 33
7.5 uCsim Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8 Tools 34
8.1 Serial Terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
8.2 Serial Remote Tank . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
8.2.1 Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2.2 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8.2.3 Communication Protocol . . . . . . . . . . . . . . . . . . . . 36
8.3 Esp8266 Modem Simulator . . . . . . . . . . . . . . . . . . . . . . . 37
8.3.1 Supported Commands . . . . . . . . . . . . . . . . . . . . . 38
8.4 Arduino Bootloader . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
8.5 MPLABX Debugger Plugin . . . . . . . . . . . . . . . . . . . . . . 38
8.6 Pin Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
9 Oscilloscope 40
10 Spare Parts 41
10.1 Pin Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
10.2 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
10.2.1 DS1621 (Temperature I2C) . . . . . . . . . . . . . . . . . . . 46
10.2.2 Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
10.2.3 FM50 (Temperature) . . . . . . . . . . . . . . . . . . . . . . 46
10.2.4 Fixed Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . 47
10.2.5 Gamepad . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
10.2.6 Gamepad (Analogic) . . . . . . . . . . . . . . . . . . . . . . 49
10.2.7 Keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
10.2.8 LM35 (Temperature) . . . . . . . . . . . . . . . . . . . . . . 51
10.2.9 MPU6050 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
10.2.10 Potentiometers . . . . . . . . . . . . . . . . . . . . . . . . . 52
10.2.11 Potentiometers (Rotary) . . . . . . . . . . . . . . . . . . . . 53
10.2.12 Push Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . 53
10.2.13 Push Buttons (Analogic) . . . . . . . . . . . . . . . . . . . . 54
10.2.14 SHT3X (Temp. Hum.) . . . . . . . . . . . . . . . . . . . . . 54
CONTENTS 3
10.2.15 Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
10.2.16 Ultrasonic HC-SR04 . . . . . . . . . . . . . . . . . . . . . . 55
10.3 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
10.3.1 7 Segments Display . . . . . . . . . . . . . . . . . . . . . . . 55
10.3.2 7 Segments Display (Decoder) . . . . . . . . . . . . . . . . . 56
10.3.3 Buzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.3.4 DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.3.5 LCD hd44780 . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.3.6 LCD ili9341 . . . . . . . . . . . . . . . . . . . . . . . . . . 59
10.3.7 LCD pcf8833 . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.3.8 LCD pcd8544 . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.3.9 LCD ssd1306 . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.3.10 LED Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
10.3.11 LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
10.3.12 RGB LED . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
10.3.13 Servo Motor . . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.3.14 Step Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.4 Others . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.4.1 ETH w5500 . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.4.2 IO 74xx595 . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
10.4.3 IO MCP23S17 . . . . . . . . . . . . . . . . . . . . . . . . . 66
10.4.4 IO PCF8574 . . . . . . . . . . . . . . . . . . . . . . . . . . 66
10.4.5 IO UART . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
10.4.6 Jumper Wires . . . . . . . . . . . . . . . . . . . . . . . . . . 67
10.4.7 MEM 24CXXX . . . . . . . . . . . . . . . . . . . . . . . . . 67
10.4.8 RTC ds1307 . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.4.9 RTC pfc8563 . . . . . . . . . . . . . . . . . . . . . . . . . . 68
10.4.10 SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10.4.11 Temperature System . . . . . . . . . . . . . . . . . . . . . . 69
10.5 Virtual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
10.5.1 D. Transfer Function . . . . . . . . . . . . . . . . . . . . . . 70
10.5.2 IO Virtual Term . . . . . . . . . . . . . . . . . . . . . . . . . 70
10.5.3 Signal Generator . . . . . . . . . . . . . . . . . . . . . . . . 71
10.5.4 VCD Dump . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
10.5.5 VCD Dump (Analogic) . . . . . . . . . . . . . . . . . . . . . 72
10.5.6 VCD Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
11 Troubleshooting 74
12 License 75
A Online Simulator 76
CONTENTS 4
Introduction
5
CHAPTER 1. INTRODUCTION 6
Chapter 2
Install
To recompile use:
7
CHAPTER 2. INSTALL 8
make -j4
2.3.2 Windows
Cross-compiling for Windows (from Linux or WSL on win10)
In first time build in Debian Linux and derivatives target Windows 64 bits:
To recompile use:
To recompile use:
2.3.3 macOS
Theoretically it is possible to compile PICSimLab natively on macOS. But I do not
have access to any computer with macOS to try to compile and until today nobody has
communicated that they managed to do it. (help wanted)
./picsimlab_build_all_and_install.sh exp
./picsimlab_build_w64.sh exp
./picsimlab_build_w32.sh exp
Simulator Interface
The frequency selection combobox directly changes the working speed of the mi-
9
CHAPTER 3. SIMULATOR INTERFACE 10
crocontroller. The “Spd” label show the ratio between simulation speed and real time.
when the “Spd” label goes red indicates that the computer is not being able to run the
program in real time for the selected clock. In this case the simulation may present
some difference than expected and the CPU load will be increased.
The on/off button to enable debugging is used to enable debugging support, when
active simulation load is increased.
The menus and their functions are listed below:
• File
– Load Hex - Load .hex files
– Reload Last - Reload the last used .hex file
– Save Hex - Save memory in a .hex file
– Configure - Open the configuration windows
– Save Workspace - Saves all current workspace settings to a .pzw file
– Load Workspace - Loads saved settings from a .pzw file
– Exit
• Board
– Arduino Uno - Choose board Arduino Uno
– Breadboard - Choose board Breadboard
– Franzininho - Choose board Franzininho
– K16F - Choose board K16F
– McLab1 - Choose board McLab1
– McLab2 - Choose board McLab2
– PICGenios - Choose board PICGenios
– PQDB - Choose board PQDB
• Microcontroller
– xxxxx - Selects the microcontroller to be used (depends on the selected
board)
• Modules
– Oscilloscope - Open the oscilloscope window
– Spare parts - Open the spare parts window
• Tools
• Help
– Contents - Open the Help window
– Board - Open the Board Help window
– Examples - Load the examples
– About Board - Show message about author and version of board
– About PICSimLab - Show message about author and version of PICSim-
Lab
The first part of the status bar shows the state of the simulation, in the middle
part the status of the debug support and in the last part the name of the serial port
used, its default speed and the error in relation to the real speed configured in the
microcontroller.
picsimlab file.pzw
help
List of supported commands:
dumpe [a] [s]- dump internal EEPROM memory
dumpf [a] [s]- dump Flash memory
dumpr [a] [s]- dump RAM memory
exit - shutdown PICSimLab
get ob - get object value
help - show this message
info - show actual setup info and objects
loadhex file - load hex file (use full path)
pins - show pins directions and values
pinsl - show pins formated info
quit - exit remote control interface
reset - reset the board
set ob vl - set object with value
sim [cmd] - show simulation status or execute cmd start/stop
sync - wait to syncronize with timer event
version - show PICSimLab version
Ok
info
Board: Arduino Uno
Processor: atmega328p
Frequency: 16000000 Hz
Use Spare: 1
board.out[00] LD_L= 254
part[00]: LEDs
part[00].out[08] LD_1= 254
part[00].out[09] LD_2= 30
part[00].out[10] LD_3= 254
part[00].out[11] LD_4= 254
part[00].out[12] LD_5 254
part[00].out[13] LD_6= 254
part[00].out[14] LD_7= 254
part[01]: Buzzer
part[01].out[02] LD_1= 140
part[02]: Push buttons
part[02].in[00] PB_1= 1
part[02].in[01] PB_2= 0
part[02].in[02] PB_3= 1
part[02].in[03] PB_4= 1
part[02].in[04] PB_5= 1
part[02].in[05] PB_6= 1
part[02].in[06] PB_7= 1
part[02].in[07] PB_8= 1
Ok
The “pins” command show all pins directions and digital values:
pins
pin[01] ( PC6/RST) < 0 pin[15] ( PB1/~9) > 0
pin[02] ( PD0/0) < 1 pin[16] ( PB2/~10) > 0
pin[03] ( PD1/1) < 1 pin[17] ( PB3/~11) > 0
pin[04] ( PD2/2) < 1 pin[18] ( PB4/12) < 0
pin[05] ( PD3/~3) > 0 pin[19] ( PB5/13) > 0
pin[06] ( PD4/4) < 1 pin[20] ( +5V) < 1
pin[07] ( +5V) < 1 pin[21] ( AREF) < 0
pin[08] ( GND) < 0 pin[22] ( GND) < 0
pin[09] ( PB6/X1) < 0 pin[23] ( PC0/A0) < 0
pin[10] ( PB7/X2) < 0 pin[24] ( PC1/A1) < 0
pin[11] ( PD5/~5) < 1 pin[25] ( PC2/A2) < 0
pin[12] ( PD6/~6) < 1 pin[26] ( PC3/A3) < 0
pin[13] ( PD7/7) < 1 pin[27] ( PC4/A4) > 0
pin[14] ( PB0/8) > 0 pin[28] ( PC5/A5) > 0
Ok
The “pinsl” command show all pins info in text formatted output:
CHAPTER 3. SIMULATOR INTERFACE 14
pinsl
28 pins [atmega328p]:
pin[01] D I 0 000 0.000 "PC6/RST "
pin[02] D I 1 200 0.000 "PD0/0 "
pin[03] D I 1 200 0.000 "PD1/1 "
pin[04] D I 1 200 0.000 "PD2/2 "
pin[05] D O 0 007 0.000 "PD3/~3 "
pin[06] D I 1 200 0.000 "PD4/4 "
pin[07] P I 1 200 0.000 "+5V "
pin[08] P I 0 000 0.000 "GND "
pin[09] D I 0 000 0.000 "PB6/X1 "
pin[10] D I 0 000 0.000 "PB7/X2 "
pin[11] D I 1 200 0.000 "PD5/~5 "
pin[12] D I 1 200 0.000 "PD6/~6 "
pin[13] D I 1 200 0.000 "PD7/7 "
pin[14] D O 0 000 0.000 "PB0/8 "
pin[15] D O 0 000 0.000 "PB1/~9 "
pin[16] D O 0 000 0.000 "PB2/~10 "
pin[17] D O 0 006 0.000 "PB3/~11 "
pin[18] D I 0 000 0.000 "PB4/12 "
pin[19] D O 0 000 0.000 "PB5/13 "
pin[20] P I 1 200 0.000 "+5V "
pin[21] R I 0 000 0.000 "AREF "
pin[22] P I 0 000 0.000 "GND "
pin[23] A I 0 000 0.875 "PC0/A0 "
pin[24] A I 0 000 1.925 "PC1/A1 "
pin[25] A I 0 000 2.700 "PC2/A2 "
pin[26] A I 0 000 4.275 "PC3/A3 "
pin[27] D O 1 179 0.000 "PC4/A4 "
pin[28] D O 1 186 0.000 "PC5/A5 "
Ok
You can view one input/output state using the “get” command:
get board.out[00]
get part[02].in[01]
Its possible use the “get” command to view individual pins state:
#digital state
get pin[19]
pin[19]= 0
Ok
Ok
#analog state
get apin[25]
apin[25]= 2.700
Ok
#all info
get pinl[13]
pin[13] D I 1 200 0.000 "PD7/7 "
Ok
set part[02].in[01] 0
set part[02].in[01] 1
#digital
set pin[10] 2
#analog
set apin[20] 2.345
For windows users putty telnet client is a good option to access the remote control
interface.
For example area named B_PB_Start, which describes the position of a push but-
ton named "Start". The B_ bidirectional indicates that the mapped area serves as user
action input and drawing output.
Chapter 4
Boards
PICSimLab currently supports five backend simulators. The stable version supports
picsim and simavr. The experimental version supports uCsim, gpsim and qemu-stm32
in addition to the stable ones.
The Figure 4.1 shows which cards are based on which backend simulator:
17
CHAPTER 4. BOARDS 18
The below table show the supported debug interface of each simulator:
4.1 Breadboard
It is a generic board only with reset, serial and crystal circuits and support to multiple
microcontrollers of picsim and simavr.
Examples
4.2 McLab1
It emulates the Labtools development board McLab1 that uses one PIC16F84, PIC16F628
or PIC16F648 of picsim.
ICSP
8 x LEDs
4 x push-buttons
PORTA
PORTB
PIC
2x 7 segments
lamp (PWM) multiplexed
display
CHAPTER 4. BOARDS 20
4.3 K16F
It emulates an didactic board developed by author that uses one PIC16F84, PIC16F628
or PIC16F648 of picsim.
ICSP
I2C eeprom
serial
PORTA
PORTB
RTC
PIC serial LCD 16x2
4 x LEDs
3x4 keyboard
CHAPTER 4. BOARDS 21
4.4 McLab2
It emulates the Labtools development board McLab2 that uses one PIC16F777, PIC16F877A,
PIC18F452, PIC18F4520, PIC18F4550 or PIC18F4620 of picsim.
CHAPTER 4. BOARDS 22
ICSP
4 x LEDs
PORTA
PORTB
potentiometer
buzzer 4x 7 segments
multiplexed
fan PIC display
PORTC
fan tacometer
PORTD
heater
serial LCD 16x2
I2C eeprom PORTE
4.5 PICGenios
It emulates the microgenius development board PICGenios PIC18F e PIC16F Mi-
crochip that uses one PIC16F777, PIC16F877A, PIC18F452, PIC18F4520, PIC18F4550
or PIC18F4620 of picsim.
CHAPTER 4. BOARDS 23
ICSP
8 x LEDs
push-button
6 x push-buttons
PORTA
PORTB
2 x potentiometer
relay 3x4 keyboard
fan PIC 4x 7 segments
fan tacometer multiplexed
PORTC
PORTD
heater display
serial 8 x LEDs
I2C eeprom PS2
PORTE
RTC
LCD 16x2
relay
buzzer temp. sensor
4.6 PQDB
The PQDB board is an opensource/openhardware project, more info at https://github.com/projetopqdb/.
It was developed to be used with arduino/freedom boards, but adapted to use the mi-
crocontroller PIC18F4520 of picsim on PICSImLab.
Examples
Examples
Chapter 5
Experimental Boards
Boards in the experimental phase. Probably with some bugs and missing features.
Examples
5.2 uCboard
It is a generic board only with reset, serial and crystal circuits and support to multiple
microcontrollers (initially C51, Z80 and STM8S103 )of uCsim.
26
CHAPTER 5. EXPERIMENTAL BOARDS 27
Examples
5.3 gpboard
It is a generic board only with reset, serial and crystal circuits and support to multiple
microcontrollers of gpsim.
Examples
Examples
5.5 X
It is a generic board, used as example in How to Compile PICsimLab and Create New
Boards.
Examples
5.6 Curiosity
This is a simple PIC microcontroller development board that uses picsim.
CHAPTER 5. EXPERIMENTAL BOARDS 29
Examples
Examples
5.8 Xpress
This is a simple PIC microcontroller development board that uses picsim.
CHAPTER 5. EXPERIMENTAL BOARDS 30
Examples
Chapter 6
Serial Communication
To use the simulator serial port emulation, you must install a NULL-MODEM emula-
tor:
For communication the PICSimLab should be connected in one port of the NULL-
MODEM emulator and the other application connected in the other port. Configuration
examples linking PICSimLab to Cutecom for serial communication:
31
CHAPTER 6. SERIAL COMMUNICATION 32
In the setup window, change the port names to COM1, COM2, COM3 .... Just
check the “enable buffer overrun” option on the two ports, click in the “Apply” button
and close the setup. In the configuration shown in the figure below, the COM1 and
COM2 ports form a NULL-MODEM connection, where one port must be used by the
PICSimLab and another by the application with serial communication.
CHAPTER 6. SERIAL COMMUNICATION 33
TX -> RX
RX <- TX
RTS -> CTS
CTS <- RTS
DSR <- DTR
CD <- DTR
DTR -> DSR
DTR -> CD
Any pair of ports form a NULL-MODEM connection, where one port must be used
by the PICSimLab and another by the application with serial communication.
Chapter 7
Debug Support
35
CHAPTER 7. DEBUG SUPPORT 36
Graphic debug mode can be made using eclipse IDE with Sloeber Arduino plugin.
Graphic debug mode can be made using eclipse IDE with Eclipse Embedded CDT.
Tools
A serial terminal is used to send and receive data over a serial communication
channel. The use of this terminal can be replaced by others like the Arduino IDE serial
monitor.
To use this tool with PICSimLab you first need to configure a virtual serial port as
described in Chapter: Serial Communication. It is possible to use this tool with a real
serial port connected to a real device.
37
CHAPTER 8. TOOLS 38
the communication protocol. The parameters of the serial communication port must be
19200 8N1.
To use this tool with PICSimLab you first need to configure a virtual serial port as
described in Chapter: Serial Communication. It is possible to use this tool with a real
serial port connected to a real device.
8.2.1 Actuators
Digital inputs:
1. Inlet valve
2. Outlet valve
3. Heater
4. Cooler
5. Stirrer
Analog inputs:
1. Minimal temperature alarm trigger level
2. Maximal temperature alarm trigger level
CHAPTER 8. TOOLS 39
8.2.2 Sensors
Digital outputs:
1. High floater
2. Low floater
3. Minimal temperature
4. Maximal temperature
Analog outputs:
1. Volume
2. Temperature
Serial_write(0x02);
Serial_write(0x01);
Serial_write(0x13);
valor=Serial_read(0);
Serial_write(0x21);
valor=230;
Serial_write((valor&0xFF00)>>8);
Serial_write(valor&0x00FF);
CHAPTER 8. TOOLS 40
Serial_write(0x32);
valorh=Serial_read(0);
valorl=Serial_read(0);
valor=(valorh<<8)|valorl;
To use this tool with PICSimLab you first need to configure a virtual serial port as
described in Chapter: Serial Communication. It is possible to use this tool with a real
CHAPTER 8. TOOLS 41
• AT+CWDHCP=1,1
• AT+CWLAP
• AT+CWJAP="rede1","123456"
• AT+CIFSR
• AT+CIPMUX=1
• AT+CIPSERVER=1,2000
• AT+CIPSEND=0,10
• AT+CIPCLOSE=0
Oscilloscope
The PICSimLab has a basic two-channel oscilloscope that can be used to view the
signal on any pin of the microcontroller. The oscilloscope can be accessed through the
“Modules->Oscilloscope” menu.
43
Chapter 10
Spare Parts
The PICSimLab has a window that allows the connection of spare parts to the micro-
controller, it can be accessed through the menu “ Modules-> Spare parts ”.
The main window has the menu with the following functions:
• File
– New configuration - Clear the spare parts window
– Save configuration - Saves the current settings of the spare parts into .pcf
file
– Load configuration - Loads the settings from .pcf file
– Save pin alias - Saves the current pin alias to .ppa text file
– Load pin alias - Loads the pin alias from .ppa file
• Edit
– Clear pin alias - Clear the pin alias
– Toggle pin alias - Enable/Disable pin alias use
– Edit pin alias - Open current pin alias .ppa file in text editor
– Reload pin alias - Reload the current .ppa pin alias file (need after edit .ppa
file)
– Zoom in - Increase draw scale
– Zoom out - Decrease draw scale
• Inputs
44
CHAPTER 10. SPARE PARTS 45
After adding the part, with a right click of the mouse you can access the options
menu of the part with the options:
• Properties - Opens the connection settings window
• Move - Unlocks the part to move
To use:
1. active the menu “Edit->Clear pin alias” to reset the pin alias file
2. active the menu “Edit->Edit pin alias” to open pin alias file, change the names,
save and close.
CHAPTER 10. SPARE PARTS 49
10.2 Inputs
10.2.1 DS1621 (Temperature I2C)
This part is DS1621 I2C temperature sensor. The measurement range is -55 to 125 °C.
Examples
10.2.2 Encoder
This part is a rotary quadrature encoder with push button. The output is twenty pulses
per revolution.
Examples
Examples
Examples
10.2.5 Gamepad
This part is a gamepad with two analog axis and 7 push buttons.
CHAPTER 10. SPARE PARTS 51
10.2.7 Keypad
It is a matrix keyboard configurable to 4x3 , 4x4 or 2x5 rows/columns.
CHAPTER 10. SPARE PARTS 53
CHAPTER 10. SPARE PARTS 54
Examples
Examples
10.2.9 MPU6050
This part is MPU6050 accelerometer and gyroscope with I2C interface. Only raw
values are available, DMP is not supported.
CHAPTER 10. SPARE PARTS 55
Examples
10.2.10 Potentiometers
This part is formed by 4 potentiometers connected between 0 and 5 volts, the output is
connected to the cursor and varies within this voltage range.
CHAPTER 10. SPARE PARTS 56
Examples
Examples
Examples
Examples
Examples
CHAPTER 10. SPARE PARTS 58
10.2.15 Switches
This part consists of 8 switches with on or off position (0 or 1).
Examples
Examples
10.3 Outputs
10.3.1 7 Segments Display
This is a four multiplexed 7 segments displays.
CHAPTER 10. SPARE PARTS 59
Examples
Examples
CHAPTER 10. SPARE PARTS 60
10.3.3 Buzzer
This is a active/passive buzzer. The buzzer has 3 operating modes:
• Active: When powered, the buzzer emits a frequency of 440Hz.
• Passive: In this mode the values read from the input pin are sent directly to the
sound card, this mode only works well if the simulation is in real time.
• Tone: This second passive mode measures the frequency on the input and up-
dates the frequency of the buzzer every 100ms, its accuracy is less than the nor-
mal passive mode but it works better when the simulation is not in real time.
Examples
10.3.4 DC Motor
This part is DC motor with H-bridge driver and quadrature encoder.
Examples
Examples
Examples
Examples
Examples
Examples
Examples
10.3.11 LEDs
This part is a bar of 8 independent red LEDs.
CHAPTER 10. SPARE PARTS 65
Examples
Examples
CHAPTER 10. SPARE PARTS 66
Examples
Examples
10.4 Others
10.4.1 ETH w5500
This part is a ethernet shield w5500 with support to 8 sockets simultaneously.
Only TCP/UDP unicast address sockets is supported. DHCP is emulated and return
a fake ipv4 address.
All listening ports below 2000 are increased by 2000 to avoid operational system
services ports. For example listening on port 80 becomes 2080.
CHAPTER 10. SPARE PARTS 68
Examples
10.4.2 IO 74xx595
This is one 74xx595 serial input and parallel output 8 bit shift register.
Examples
CHAPTER 10. SPARE PARTS 69
10.4.3 IO MCP23S17
It is a MCP23S17 serial SPI IO expander part.
Examples
10.4.4 IO PCF8574
It is a PCF8574 serial I2C IO expander.
Examples
10.4.5 IO UART
This part is a UART serial port. This part connects the hardware/software UART IO
pins of microcontroller to one real/virtual PC serial port. To use virtual port is need
to install a virtual port software, as described in 6. The serial communication uses the
8N1 format.
CHAPTER 10. SPARE PARTS 70
Examples
Examples
Examples
Examples
Examples
10.4.10 SD Card
This part is a SD Card shield. It’s necessary set one sd card file image before use it.
(Click on SD card connector to open file dialog)
On Linux one empty image can be created with this command:
dd if=/dev/zero of=sd.img bs=1M count=32
This empty image can be used with raw sd card access, to work with FAT file system
the image need to be formatted before the use. (using SdFormatter.ino for example)
Examples
Examples
10.5 Virtual
10.5.1 D. Transfer Function
This is a discrete transfer function mathematical model.
Examples
Examples
Examples
Examples
Examples
Examples
Chapter 11
Troubleshooting
77
Chapter 12
License
78
Appendix A
Online Simulator
The online version of PICSimLab has the same source code as the desktop version
compiled using Emscripten. The online version does not have the Tools menu, support
for debugging and serial communication (only for IO Vterm).
79
APPENDIX A. ONLINE SIMULATOR 80
Clicking on the three-bar menu (botton left) or any loading option in the menus
to open the file loading window. Files can be loaded by drag and drop or by the load
button.
The simulator can also be accessed from the examples page for online viewing of
most examples (View Online link).
Due to the limitations of the online version, it is advisable to use the desktop version
which has more resources and higher simulation speed, especially above 8Mhz clocks.
Appendix B
81
APPENDIX B. USE WITH MPLABX 82
The plugin connect to Picsimlab through a TCP socket using port 1234, and you have
to allow the access in the firewall. Verify in the PICsimLab statusbar the message
“MplabxD: Ok”. It’s show debugger server state.
First get the source code and compile as described in Install from source.
ICSP
PIC
Serial Switch Input
99
APPENDIX C. CREATING NEW BOARDS 100
And the PCB layout was made in Kicad too. The PCB is not necessary if you have
a real board.
APPENDIX C. CREATING NEW BOARDS 102
It is also possible to use images in SVG format for better viewing quality. PCBDraw
can be used to convert a Kicad PCB project to an SVG image. The picture image is
saved as “share/board/X/board.svg”.
APPENDIX C. CREATING NEW BOARDS 103
APPENDIX C. CREATING NEW BOARDS 104
After area is select, in the settings windows select the link type for “Other”.
And write the name of area. The name must describe the area function on the board
and follow the Picture Map Reference.
APPENDIX C. CREATING NEW BOARDS 107
Board map
For this tutorial board, twelve areas are marked:
• I_PG_ICSP - where user click to load hexfile.
Board map generated by Gimp image map editor and saved as “share/boards/X/board.map”.
1 <img src="[board_x] (imported)" width="448" height="491" border="0" usemap="#map" />
2
3 <map name="map">
4 <!-- #$-:Image map file created by GIMP Image Map plug-in -->
5 <!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
6 <!-- #$-:Please do not edit lines starting with "#$" -->
7 <!-- #$VERSION:2.3 -->
8 <!-- #$AUTHOR:lcgamboa@yahoo.com -->
9 <area shape="rect" coords="196,45,280,58" href="I_PG_ICSP" />
10 <area shape="rect" coords="409,30,441,46" href="I_SW_PWR" />
11 <area shape="rect" coords="133,379,142,401" href="B_SW_D1" />
12 <area shape="rect" coords="74,42,156,61" href="B_PO_1" />
13 <area shape="rect" coords="105,162,138,195" href="B_PB_RST" />
14 <area shape="rect" coords="37,327,70,360" href="B_PB_D0" />
15 <area shape="circle" coords="59,454,17" href="O_LD_LD0" />
16 <area shape="circle" coords="137,454,17" href="O_LD_LD1" />
17 <area shape="circle" coords="418,102,17" href="O_LD_LPWR" />
18 <area shape="circle" coords="418,189,17" href="O_LD_RB1" />
19 <area shape="circle" coords="418,232,17" href="O_LD_RB0" />
20 <area shape="rect" coords="227,220,247,328" href="O_IC_CPU" />
21 </map>
The kicad project files can be download from github PICSimLab repository.
board_x.h
board_x.h online file.
board_x.h online doxygen version.
1 /* ########################################################################
2
5 ########################################################################
6
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
26 #ifndef BOARD_x_H
27 #define BOARD_x_H
28
29 #include<lxrad.h>
30
31 #include "bsim_picsim.h"
32
35 //new board class must be derived from board class defined in board.h
36 class cboard_x:public bsim_picsim
37 {
38 private:
39 unsigned char p_BT1; //first board push button in RD0
40 unsigned char p_BT2; //second board switch in RD1
41
42 //value of potentiometer
43 unsigned char pot1;
APPENDIX C. CREATING NEW BOARDS 110
97 #endif /* BOARD_x_H */
APPENDIX C. CREATING NEW BOARDS 112
board_x.cc
board_x.cc online file.
board_x.cc online doxygen version.
1 /* ########################################################################
2
5 ########################################################################
6
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
26 //include files
27 #include"../picsimlab1.h"
28 #include"../picsimlab4.h" //Oscilloscope
29 #include"../picsimlab5.h" //Spare Parts
30 #include"board_x.h"
31
44 enum
45 {
46 O_POT1, //potentiometer
47 O_RST, //Reset button
48 O_SD1, //switch position (On/Off)
49 O_LD0, //LED on RD0 push button
50 O_LD1, //LED on RD1 switch
51 O_LPWR, //Power LED
52 O_RB0, //LED on RB0 output
53 O_RB1, //LED on RB1 output
54 O_BD0, //RD1 switch
55 O_CPU //CPU name
56 };
57
60 unsigned short
61 cboard_x::get_in_id(char * name)
62 {
63 if (strcmp (name, "PG_ICSP") == 0)return I_ICSP;
64 if (strcmp (name, "SW_PWR") == 0)return I_PWR;
65 if (strcmp (name, "PB_RST") == 0)return I_RST;
66 if (strcmp (name, "PB_D0") == 0)return I_BD0;
67 if (strcmp (name, "SW_D1") == 0)return I_SD1;
68 if (strcmp (name, "PO_1") == 0)return I_POT1;
69
70 printf ("Error input '%s' don't have a valid id! \n", name);
71 return -1;
72 }
73
76 unsigned short
77 cboard_x::get_out_id(char * name)
78 {
79
91 printf ("Error output '%s' don't have a valid id! \n", name);
APPENDIX C. CREATING NEW BOARDS 114
92 return 1;
93 }
94
97 cboard_x::cboard_x(void) :
98 font(10, lxFONTFAMILY_TELETYPE, lxFONTSTYLE_NORMAL, lxFONTWEIGHT_BOLD)
99 {
100 Proc = "PIC18F4550"; //default microcontroller if none defined in preferences
101 ReadMaps (); //Read input and output board maps
102
105 active = 0;
106
166 cboard_x::~cboard_x(void)
167 {
168 //controls destruction
169 Window1.DestroyChild (gauge1);
170 Window1.DestroyChild (gauge2);
171 Window1.DestroyChild (label2);
172 Window1.DestroyChild (label3);
173 }
174
177 void
178 cboard_x::Reset(void)
179 {
180 pic_reset (1);
181
189
211 void
212 cboard_x::RegisterRemoteControl(void)
213 {
214 //register inputa
215 input_ids[I_BD0]->status = &p_BT1;
216 input_ids[I_SD1]->status = &p_BT2;
217 input_ids[I_POT1]->status = &pot1;
218
233 void
234 cboard_x::RefreshStatus(void)
235 {
236 //verify serial port state and refresh status bar
237 #ifndef _WIN_
238 if (pic.serial[0].serialfd > 0)
239 #else
240 if (pic.serial[0].serialfd != INVALID_HANDLE_VALUE)
241 #endif
242 Window1.statusbar1.SetField (2, lxT ("Serial: ") +
243 lxString::FromAscii (SERIALDEVICE) + lxT (":") + itoa (pic.serial[0].
244 lxString ().Format ("%4.1f", fabs ((100.0 * pic.serial[0].serialexbau
245 pic.serial[0].serialbaud) / pic.s
246 else
247 Window1.statusbar1.SetField (2, lxT ("Serial: ") +
248 lxString::FromAscii (SERIALDEVICE) + lxT (" (ERROR)"));
249
250 }
251
254 void
255 cboard_x::WritePreferences(void)
256 {
257 //write selected microcontroller of board_x to preferences
258 Window1.saveprefs (lxT ("X_proc"), Proc);
259 //write switch state of board_x to preferences
260 Window1.saveprefs (lxT ("X_bt2"), lxString ().Format ("%i", p_BT2));
261 //write microcontroller clock to preferences
262 Window1.saveprefs (lxT ("X_clock"), lxString ().Format ("%2.1f", Window1.GetClock ()));
263 //write potentiometer position to preferences
264 Window1.saveprefs (lxT ("X_pot1"), lxString ().Format ("%i", pot1));
265 }
266
269 void
270 cboard_x::ReadPreferences(char *name, char *value)
271 {
272 //read switch state of board_x of preferences
273 if (!strcmp (name, "X_bt2"))
274 {
275 if (value[0] == '0')
276 p_BT2 = 0;
277 else
278 p_BT2 = 1;
279 }
APPENDIX C. CREATING NEW BOARDS 118
298
301 void
302 cboard_x::EvKeyPress(uint key, uint mask)
303 {
304 //if keyboard key 1 is pressed then activate button (state=0)
305 if (key == '1')
306 {
307 p_BT1 = 0;
308 output_ids[O_BD0]->update = 1;
309 }
310
318 }
319
322 void
323 cboard_x::EvKeyRelease(uint key, uint mask)
324 {
325 //if keyboard key 1 is pressed then deactivate button (state=1)
326 if (key == '1')
APPENDIX C. CREATING NEW BOARDS 119
327 {
328 p_BT1 = 1;
329 output_ids[O_BD0]->update = 1;
330 }
331
332 }
333
336 void
337 cboard_x::EvMouseButtonPress(uint button, uint x, uint y, uint state)
338 {
339
340 int i;
341
342 //search for the input area which owner the event
343 for (i = 0; i < inputc; i++)
344 {
345 if (((input[i].x1 <= x)&&(input[i].x2 >= x))&&((input[i].y1 <= y)&&
346 (input[i].y2 >= y)))
347 {
348
374 //if event is over I_RST area then turn off and reset
375 case I_RST:
376 if (Window1.Get_mcupwr () && pic_reset (-1))//if powered
377 {
378 Window1.Set_mcupwr (0);
379 Window1.Set_mcurst (1);
380 }
381 p_RST = 0;
382 output_ids[O_RST]->update = 1;
383 break;
384 //if event is over I_D0 area then activate button (state=0)
385 case I_BD0:
386 p_BT1 = 0;
387 output_ids[O_BD0]->update = 1;
388 break;
389 //if event is over I_D1 area then toggle switch state
390 case I_SD1:
391 p_BT2 ^= 1;
392 output_ids[O_SD1]->update = 1;
393 break;
394 case I_POT1:
395 {
396 active = 1;
397 pot1 = (x - input[i].x1)*2.77;
398 if (pot1 > 199)pot1 = 199;
399 output_ids[O_POT1]->update = 1;
400 }
401 break;
402 }
403 }
404 }
405
406 }
407
410 void
411 cboard_x::EvMouseMove(uint button, uint x, uint y, uint state)
412 {
413 int i;
414
421 {
422 if (active)
423 {
424 pot1 = (x - input[i].x1)*2.77;
425 if (pot1 > 199)pot1 = 199;
426 output_ids[O_POT1]->update = 1;
427 }
428 }
429 break;
430 }
431 }
432 }
433
436 void
437 cboard_x::EvMouseButtonRelease(uint button, uint x, uint y, uint state)
438 {
439 int i;
440
441 //search for the input area which owner the event
442 for (i = 0; i < inputc; i++)
443 {
444 if (((input[i].x1 <= x)&&(input[i].x2 >= x))&&((input[i].y1 <= y)&&
445 (input[i].y2 >= y)))
446 {
447 switch (input[i].id)
448 {
449 //if event is over I_RST area then turn on
450 case I_RST:
451 if (Window1.Get_mcurst ())//if powered
452 {
453 Window1.Set_mcupwr (1);
454 Window1.Set_mcurst (0);
455
468 break;
469 case I_POT1:
470 {
471 active = 0;
472 output_ids[O_POT1]->update = 1;
473 }
474 break;
475 }
476 }
477 }
478
479 }
480
481
485 void
486 cboard_x::Draw(CDraw *draw)
487 {
488 int update = 0; //verifiy if updated is needed
489 int i;
490
491
499 if (!update)
500 {
501 draw->Canvas.Init (Scale, Scale);
502 }
503 update++; //set to update buffer
504
515 {
516 //draw a grey rectangle
517 draw->Canvas.SetBgColor (70, 70, 70);
518 draw->Canvas.Rectangle (1, output[i].x1, output[i].y1 +
519 ((int) ((output[i].y2 - output[i].y1)*0.35)), output[i].x2 - outp
520 (int) ((output[i].y2 - output[i].y1)*0.65));
521 }
522 else //draw switch on
523 {
524 //draw a grey rectangle
525 draw->Canvas.SetBgColor (70, 70, 70);
526 draw->Canvas.Rectangle (1, output[i].x1,
527 output[i].y1, output[i].x2 - output[i].x1,
528 (int) ((output[i].y2 - output[i].y1)*0.65));
529 }
530 }
531 else if (output[i].id == O_BD0)
532 {
533 draw->Canvas.SetColor (102, 102, 102);
534 draw->Canvas.Circle (1, output[i].cx, output[i].cy, 10);
535 if (p_BT1)
536 {
537 draw->Canvas.SetColor (15, 15, 15);
538 }
539 else
540 {
541 draw->Canvas.SetColor (55, 55, 55);
542 }
543 draw->Canvas.Circle (1, output[i].cx, output[i].cy, 8);
544 }
545 else if (output[i].id == O_RST)
546 {
547 draw->Canvas.SetColor (102, 102, 102);
548 draw->Canvas.Circle (1, output[i].cx, output[i].cy, 10);
549
550 if (p_RST)
551 {
552 draw->Canvas.SetColor (15, 15, 15);
553 }
554 else
555 {
556 draw->Canvas.SetColor (55, 55, 55);
557 }
558 draw->Canvas.Circle (1, output[i].cx, output[i].cy, 8);
559 }
560 else if (output[i].id == O_POT1)
561 {
APPENDIX C. CREATING NEW BOARDS 124
623 if (update)
624 {
625 draw->Canvas.End ();
626 draw->Update ();
627 }
628
634 }
635
636 void
637 cboard_x::Run_CPU(void)
638 {
639 int i;
640 int j;
641 unsigned char pi;
642 const picpin * pins;
643 unsigned int alm[40];
644
648
722 }
723
724
The sample program below can be used to test new board, this code is write for
XC8 compiler:
1 #include <xc.h>;
2
3 #include "config_4550.h"
4 #include "adc.h"
5 #include "serial.h"
6 #include "itoa.h"
7
8 void main()
9 {
10 unsigned int val;
11 char buffer[10];
12
13 ADCON1=0x02;
14 TRISA=0xFF;
15 TRISB=0xFC;
16 TRISC=0xBF;
17 TRISD=0xFF;
18 TRISE=0x0F;
19
APPENDIX C. CREATING NEW BOARDS 129
20 adc_init();
21 serial_init();
22
23
24 while(1)
25 {
26 val=adc_amostra(0);
27
28 if(PORTDbits.RD1)
29 {
30 if(val > 340)
31 PORTBbits.RB0=1;
32 else
33 PORTBbits.RB0=0;
34
53 }
54
55 serial_tx_str(itoa(val,buffer));
56 serial_tx_str("\r\n");
57 }
58
59 }