Manuale Picsimlab
Manuale Picsimlab
PICSimLab 0.9.1
Download: github
PICSimLab on Twitter
PICSimLab on Discord
1 Introduction 6
2 Install 8
2.1 Stable version executables download . . . . . . . . . . . . . . . . . . 8
2.2 Unstable version executables download . . . . . . . . . . . . . . . . 8
2.3 Install from source . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.2 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.3 macOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.4 Experimental version . . . . . . . . . . . . . . . . . . . . . . 9
3 Simulator Interface 10
3.1 Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 Interaction with the Board . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Remote Control Interface . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Picture Map Reference . . . . . . . . . . . . . . . . . . . . . . . . . 16
4 Boards 18
4.1 Arduino Mega . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Arduino Nano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.4 Blue Pill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.5 Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.6 Curiosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.7 Curiosity HPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.8 ESP32-C3-DevKitC-02 . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.9 ESP32-DevKitC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.10 Franzininho DIY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.11 K16F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.12 McLab1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.13 McLab2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.14 PICGenios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.15 PQDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1
CONTENTS 2
5 Serial Communication 33
5.1 Com0com Installation and Configuration(Windows) . . . . . . . . . . 33
5.2 tty0tty Installation and Configuration (Linux) . . . . . . . . . . . . . 35
5.3 Arduino IDE Integration (simavr) . . . . . . . . . . . . . . . . . . . 36
6 Backend Simulators 37
6.1 PICsim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.1.1 MPLABX Integrated Debug . . . . . . . . . . . . . . . . . . 37
6.2 simavr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.1 avr-gdb Debug . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.2.2 MPLABX Int. Debug . . . . . . . . . . . . . . . . . . . . . 38
6.3 qemu-stm32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.3.1 arm-gdb Debug . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.4 qemu-ESP32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.4.1 ESP32-gdb Debug . . . . . . . . . . . . . . . . . . . . . . . 40
6.5 uCsim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.5.1 uCsim Debug . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6 gpsim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.7 Remote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7 Tools 42
7.1 Serial Terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2 Serial Remote Tank . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2.1 Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2.2 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.2.3 Communication Protocol . . . . . . . . . . . . . . . . . . . . 44
7.3 Esp8266 Modem Simulator . . . . . . . . . . . . . . . . . . . . . . . 45
7.3.1 Supported Commands . . . . . . . . . . . . . . . . . . . . . 46
7.4 Arduino Bootloader . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.5 MPLABX Debugger Plugin . . . . . . . . . . . . . . . . . . . . . . 47
7.6 Pin Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8 Oscilloscope 48
9 Spare Parts 49
9.1 Pin Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
9.2 Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
9.2.1 ADXL345 (Accel) . . . . . . . . . . . . . . . . . . . . . . . 54
9.2.2 BMP180 (Pressure I2C) . . . . . . . . . . . . . . . . . . . . 55
CONTENTS 3
10 Troubleshooting 96
11 License 97
A Online Simulator 98
Introduction
6
CHAPTER 1. INTRODUCTION 7
Chapter 2
Install
To recompile use:
8
CHAPTER 2. INSTALL 9
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)
bscripts/build_all_and_install.sh exp
bscripts/build_w64.sh exp
bscripts/build_w32.sh exp
Simulator Interface
The frequency selection combobox directly changes the working speed of the mi-
10
CHAPTER 3. SIMULATOR INTERFACE 11
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
– uCboard - Choose board uCboard
• 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
– Serial Terminal - Open the serial terminal (default Cutecom)
– Serial Remote Tank - Open the remote tank simulator
CHAPTER 3. SIMULATOR INTERFACE 12
• 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 15
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: picsim, simavr, uCsim, gpsim
and qemu (stm32 and esp32).
The Figure below shows which boards are based on which backend simulator:
18
CHAPTER 4. BOARDS 19
The below table show the supported debug interface of each simulator:
Information on how to configure the PICSimLab integration with the Arduino IDE
can be found in the section: Arduino IDE Integration.
Examples
4.5 Breadboard
It is a generic board only with reset, serial and crystal circuits and support to multiple
microcontrollers of PICSim and simavr backend simulators.
Examples
4.6 Curiosity
This is a simple PIC microcontroller development board that uses the PICSim backend
simulator.
CHAPTER 4. BOARDS 23
Examples
Examples
4.8 ESP32-C3-DevKitC-02
It is a simple board only with reset, serial and crystal circuits and support for ESP32-C3
microcontroller of qemu-esp32 backend simulator.
CHAPTER 4. BOARDS 24
Examples
4.9 ESP32-DevKitC
It is a simple board only with reset, serial and crystal circuits and support for ESP32
microcontroller of qemu-esp32 backend simulator.
Examples
Examples
CHAPTER 4. BOARDS 25
4.11 K16F
It emulates an didactic board developed by author that uses one PIC16F84, PIC16F628
or PIC16F648 of PICSim backend simulator.
ICSP
I2C eeprom
serial
PORTA
PORTB
RTC
PIC serial LCD 16x2
4 x LEDs
3x4 keyboard
4.12 McLab1
It emulates the Labtools development board McLab1 that uses one PIC16F84, PIC16F628
or PIC16F648 of PICSim backend simulator.
ICSP
8 x LEDs
4 x push-buttons
PORTA
PORTB
PIC
2x 7 segments
lamp (PWM) multiplexed
display
4.13 McLab2
It emulates the Labtools development board McLab2 that uses one PIC16F777, PIC16F877A,
PIC18F452, PIC18F4520, PIC18F4550 or PIC18F4620 of PICSim backend simulator..
CHAPTER 4. BOARDS 27
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.14 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 backend simulator.
CHAPTER 4. BOARDS 28
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.15 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 backend simulator on PICSImLab.
Examples
Examples
Examples
4.18 X
It is a generic board, used as example in the tutorial Creating New Boards. This board
uses one PIC16F877A, PIC18F4550 or PIC18F4620 of PICSim backend simulator.
CHAPTER 4. BOARDS 31
Board X schematics.
Examples
4.19 Xpress
This is a simple PIC microcontroller development board that uses the PICSim backend
simulator.
Examples
CHAPTER 4. BOARDS 32
4.20 gpboard
It is a generic board only with reset, serial and crystal circuits and support to multiple
microcontrollers of gpsim backend simulator..
Examples
4.21 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 backend simulator..
Examples
Chapter 5
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:
33
CHAPTER 5. SERIAL COMMUNICATION 34
In the setup window, change the port names to COM1, COM2, COM3 .... Just
check the “enable buffer overrun” and “use Port class” options on the port used to
CuteCom, click in the “Apply” button and close the setup. In the configuration shown
in the figure below, the port COM1 (with buffer overrun disabled) must be used by
the PICSimLab and COM2 (with buffer overrun enabled) by the application with serial
communication.
CHAPTER 5. SERIAL COMMUNICATION 35
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.
Backend Simulators
PICSimLab currently supports five backend simulators: picsim, simavr, uCsim, gpsim
and qemu (stm32 and esp32).
The type of debug interface depends on the backend simulator utilized.
6.1 PICsim
“PICsim emulates some PIC microcontroller and periferics such as USART and timers,
the simulator architecture permit easy implementation of external elements in c lan-
guage. It can be used as a standalone simulator (picsim executable) or as a library in
other programs (As in PICSimLab).”
6.2 simavr
“simavr is a new AVR simulator for linux, or any platform that uses avr-gcc. It uses
avr-gcc’s own register definition to simplify creating new targets for supported AVR
devices. The core was made to be small and compact, and hackable so allow quick
prototyping of an AVR project. The AVR core is now stable for use with parts with <=
128KB flash, and with preliminary support for the bigger parts. The simulator loads
ELF files directly, and there is even a way to specify simulation parameters directly in
the emulated code using an .elf section. You can also load multipart HEX files.”
37
CHAPTER 6. BACKEND SIMULATORS 38
Graphic debug mode can be made using eclipse IDE with Sloeber Arduino plugin.
It is also possible to debug using platformIO in VSCode, just add the configuration
lines below in the project’s platformio.ini file:
build_type = debug
upload_port = COM7
;upload_port = /dev/tnt3
debug_tool = custom
debug_port = localhost:1234
debug_build_flags = -O2 -g
debug_init_break = tbreak setup
debug_init_cmds =
define pio_reset_halt_target
end
define pio_reset_run_target
end
target extended-remote $DEBUG_PORT
$LOAD_CMDS
pio_reset_halt_target
$INIT_BREAK
6.3 qemu-stm32
“Qemu STM32: QEMU with an STM32 microcontroller implementation”
CHAPTER 6. BACKEND SIMULATORS 39
Graphic debug mode can be made using eclipse IDE with Eclipse Embedded CDT
or using platformIO in VSCode, just add the configuration lines below in the project’s
platformio.ini file:
upload_port = com7
;upload_port = /dev/tnt2
build_type = debug
debug_tool = custom
debug_port = localhost:1234
debug_build_flags = -O2 -g
debug_init_break = tbreak main
debug_init_cmds =
define pio_reset_halt_target
monitor system_reset
end
define pio_reset_run_target
monitor system_reset
end
target extended-remote $DEBUG_PORT
$LOAD_CMDS
pio_reset_halt_target
$INIT_BREAK
6.4 qemu-ESP32
“Qemu ESP32: Qemu Emulator for TTGO TDisplay esp32 board. ”
For integrated use with the Arduino IDE or IDF esptool.py , simply configure
the serial port as explained in the Chapter Serial Communication to flash PICSimLab
ESP32-DevKitC as a real ESP32 board.
Atention! Qemu ESP32 don´t support the QIO and QOUT flash modes, use only
DIO or DOUT flash modes.
CHAPTER 6. BACKEND SIMULATORS 40
Graphic debug mode can be made using platformIO in VSCode, just add the con-
figuration lines below in the project’s platformio.ini file:
upload_port = com7
;upload_port = /dev/tnt2
build_type = debug
debug_tool = custom
debug_port = localhost:1234
debug_build_flags = -O2 -g
debug_init_break = tbreak main
debug_init_cmds =
define pio_reset_halt_target
monitor system_reset
end
define pio_reset_run_target
monitor system_reset
end
target extended-remote $DEBUG_PORT
$LOAD_CMDS
pio_reset_halt_target
$INIT_BREAK
6.5 uCsim
“uCsim Software simulator for microcontrollers. uCsim can be used to simulate micro-
controllers. It supports MCS51 family, AVR core, Z80, HC08, ST7, STM8, TLCS90,
XA51 and Padauk. It can run on Linux, Windows, OSX, BSD, and other systems.”
6.6 gpsim
“gpsim is a full-featured software simulator for Microchip PIC microcontrollers dis-
tributed under the GNU General Public License, Version 2 or higher, and some of it’s
libraries under GNU Lesser General Public License, Version 2 or higher.
gpsim has been designed to be as accurate as possible. Accuracy includes the entire
PIC - from the core to the I/O pins and including ALL of the internal peripherals. Thus
it’s possible to create stimuli and tie them to the I/O pins and test the PIC the same PIC
the same way you would in the real world.”
6.7 Remote
This is experimental support to allow other simulators acting as microcontrollers to
control PICSimLab remotely (TCP/IP).
Chapter 7
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.
42
CHAPTER 7. TOOLS 43
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.
7.2.1 Actuators
Digital inputs:
1. Inlet valve
2. Outlet valve
3. Heater
4. Cooler
5. Stirrer
CHAPTER 7. TOOLS 44
Analog inputs:
1. Minimal temperature alarm trigger level
2. Maximal temperature alarm trigger level
7.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(0x21);
valor=230;
Serial_write((valor&0xFF00)>>8);
Serial_write(valor&0x00FF);
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
serial port connected to a real device.
• 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.
48
Chapter 9
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
49
CHAPTER 9. SPARE PARTS 50
• Others
– ETH w5500 - Adds a ethernet shield w5500
– IO 74xx573 - Adds a 74xx573 octal latch
– IO 74xx595 - Adds a 74xx595 SIPO 8 bit shift register
– IO MCP23S17 - Adds a MCP23S17 serial SPI IO expander
– IO MM74C922 - Adds a MM74C922 key encoder
– IO PCF8574 - Adds a PCF8574 serial I2C IO expander
– IO UART - Adds a UART serial port
– Jumper Wires - Adds sixteen jumper wires
– MEM 24CXXX - Adds a 24CXXX serial I2C EEPROM memory
– RTC ds1307 - Adds a ds1307 real time clock
– RTC pfc8563 - Adds a pfc8563 real time clock
– SD Card - Adds a SD card shield
– Temperature System - Adds a temperature control system
• Virtual
– D. Transfer Function - Adds a discrete transfer function mathematical model
– IO Virtual term - Adds a virtual serial terminal
– Signal Generator - Adds a virtual signal generator
– Text Box - Adds a static text box
– VCD Dump - Adds a digital value file dump recorder
– VCD Dump (Analogic) - Adds a analog value file dump recorder
– VCD Play - Adds a digital value file dump player
• Help
– Contents - Open Help window
– About - Show message about author and version
CHAPTER 9. SPARE PARTS 52
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
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.
3. active the menu “Edit->Reload pin alias” to load new alias
4. active the menu “Edit->Toggle pin alias” to show new alias
9.2 Inputs
9.2.1 ADXL345 (Accel)
This part is ADXL345 accelerometer with I2C/SPI interface. Only raw values are
available.
To select SPI mode put low level in CS pin. In I2C mode (CS pin high), the address
is 0x1D when SDO is NC or high and 0x53 when SDO pin is held in low.
CHAPTER 9. SPARE PARTS 55
Examples
Datasheet
Examples
CHAPTER 9. SPARE PARTS 56
Datasheet
Examples
Datasheet
Examples
Datasheet
Examples
Datasheet
CHAPTER 9. SPARE PARTS 58
Examples
Datasheet
Examples
CHAPTER 9. SPARE PARTS 59
Datasheet
9.2.8 Encoder
This part is a rotary quadrature encoder (Ky-40) with push button. The output is twenty
pulses per revolution.
Examples
Datasheet
Examples
Datasheet
Examples
9.2.11 Gamepad
This part is a gamepad with two analog axis and 7 push buttons.
CHAPTER 9. SPARE PARTS 61
Examples
Examples
Datasheet
9.2.14 Keypad
It is a matrix keyboard configurable to 4x3 , 4x4 or 2x5 rows/columns.
CHAPTER 9. SPARE PARTS 63
CHAPTER 9. SPARE PARTS 64
Examples
9.2.15 LDR
This part is light dependent resistor (LDR) connected in series with one 10K resistor.
The analog output of the voltage divider is applied to one voltage follower and can be
read directly from pin A0. The analog value from voltage follower is compared with
one voltage threshold, the digital output of comparator and can be read directly from
pin D0.
Examples
Datasheet
Examples
Datasheet
9.2.17 MPU6050
This part is MPU6050 accelerometer and gyroscope with I2C interface. Only raw
values are available, DMP is not supported.
Ihe I2C address is 0x68 when AD0 is NC or low and 0x69 when AD0 pin is held
in high.
CHAPTER 9. SPARE PARTS 66
Examples
Datasheet
9.2.18 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 9. SPARE PARTS 67
Examples
Examples
CHAPTER 9. SPARE PARTS 68
Examples
Examples
Examples
Datasheet
9.2.23 Switches
This part consists of 8 switches with on or off position (0 or 1). The switches have
activation bounce effect emulation.
Examples
CHAPTER 9. SPARE PARTS 70
Examples
Datasheet
9.3 Outputs
9.3.1 7 Segments Display
This part can be configured as four multiplexed or one single 7 segments display.
Four Multiplexed
CHAPTER 9. SPARE PARTS 71
Single Display
Examples
CHAPTER 9. SPARE PARTS 72
Four Multiplexed
CHAPTER 9. SPARE PARTS 73
Examples
9.3.3 Buzzer
This is a active/passive buzzer. The buzzer has 3 operating modes:
CHAPTER 9. SPARE PARTS 74
Examples
9.3.4 DC Motor
This part is DC motor with H-bridge driver and quadrature encoder.
CHAPTER 9. SPARE PARTS 75
Examples
Examples
Datasheet
Examples
Datasheet ILI9341
Datasheet xpt2046
Examples
CHAPTER 9. SPARE PARTS 79
Examples
Datasheet
Examples
Datasheet
Examples
9.3.11 LEDs
This part is a bar of 8 independent colored LEDs.
CHAPTER 9. SPARE PARTS 81
Examples
Examples
Examples
Examples
Examples
9.4 Others
9.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.
w5500 Status Legend:
Examples
Datasheet
9.4.2 IO 74xx573
This is one 74xx573 octal latch.
Examples
9.4.3 IO 74xx595
This is one 74xx595 serial input and parallel output 8 bit shift register.
CHAPTER 9. SPARE PARTS 86
Examples
9.4.4 IO MCP23S17
It is a MCP23S17 serial SPI IO expander part.
Examples
9.4.5 IO MM74C922
It is a MM74C922 key encoder.
CHAPTER 9. SPARE PARTS 87
Examples
Datasheet
9.4.6 IO PCF8574
It is a PCF8574 serial I2C IO expander (Address 0x20 to 0x27).
Examples
Datasheet
9.4.7 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 Chapter: Serial Communication. The
serial communication uses the 8N1 format.
CHAPTER 9. SPARE PARTS 88
Examples
Examples
Examples
Datasheet 24C04
Datasheet 24C512
Examples
Datasheet
Examples
Datasheet
9.4.12 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)
CHAPTER 9. SPARE PARTS 91
Examples
Examples
9.5 Virtual
9.5.1 D. Transfer Function
This is a discrete transfer function mathematical model.
CHAPTER 9. SPARE PARTS 92
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Chapter 10
Troubleshooting
96
Chapter 11
License
97
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).
98
APPENDIX A. ONLINE SIMULATOR 99
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
100
APPENDIX B. USE WITH MPLABX 101
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
118
APPENDIX C. CREATING NEW BOARDS 119
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 121
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 using the PICSimLab
PcbDraw Library. The picture image is saved as “share/board/X/board.svg”.
APPENDIX C. CREATING NEW BOARDS 122
APPENDIX C. CREATING NEW BOARDS 123
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 126
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:[email protected] -->
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 129
97 #endif /* BOARD_x_H */
98
APPENDIX C. CREATING NEW BOARDS 131
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 133
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 137
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 138
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 143
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 148
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 }