Home
Downloads
Licenses Contact

OshonSoft

20th Anniversary

20th Anniversary of the
OSHONSOFT PROJECT
(2001 - 2021)

PIC10 Simulator IDE
Getting Started

This presentation will help you to test the examples included with the software package and in that way get acquainted with the most frequently used features of PIC10 Simulator IDE.


Example 1: demo.bas
Example 2: demo2.bas


Example 1: demo.bas

Examine demo.bas file from the application folder. This program first writes 32 bytes of data to an external 24C256 I2C EEPROM and then verifies the operation by reading the data back. During these operations formatted text is transmitted by a software implemented serial port. File demo.asm was generated using integrated Basic compiler. File demo.hex was generated using integrated assembler.


Define CONFIG = 0x0f94
Define CLOCK_FREQUENCY = 4
Define OSCCAL_VALUE = 0xfe

Define I2C_SDA_REG = PORTC
Define I2C_SDA_BIT = 4
Define I2C_SCL_REG = PORTC
Define I2C_SCL_BIT = 3
Define SEROUT_REG = PORTC
Define SEROUT_BIT = 5
Define SEROUT_BAUD = 9600

Dim addr As Word
Dim data As Byte

Dim print_value As Byte
Dim x100 As Byte
Dim x10 As Byte
Dim x1 As Byte

AllDigital 'configure all pins as digital I/O's

WaitMs 1 'suitable for simulation

For addr = 0 To 31
   data = 200 - addr
   I2CWrite 0xa0, addr, data
   print_value = addr
   Gosub ascii_print_prepare
   Serout "Write To EEPROM: ("
   Serout x100, x10, x1, ") = "
   print_value = data
   Gosub ascii_print_prepare
   Serout x100, x10, x1, CrLf
   WaitMs 1 'suitable for simulation
Next addr

For addr = 0 To 31
   I2CRead 0xa0, addr, data
   print_value = addr
   Gosub ascii_print_prepare
   Serout "Read From EEPROM: ("
   Serout x100, x10, x1, ") = "
   print_value = data
   Gosub ascii_print_prepare
   Serout x100, x10, x1, CrLf
   WaitMs 1 'suitable for simulation
Next addr

End

ascii_print_prepare:
Dim i As Byte
i = print_value / 100 'get number of 100s in print_value
print_value = print_value Mod 100
x100 = i + 48 'get ascii value of i
i = print_value / 10
x10 = i + 48
i = print_value Mod 10
x1 = i + 48
Return


- Start PIC10 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC16F506' and click on Select button.
- Click on Options\Change Clock Frequency.
- Enter '4' and click on OK button.
- Click on Tools\BASIC Compiler.
- Click on File\Open.
- Select demo.bas file and click on Open. The basic source program will be displayed in the editor.
- Click on Tools\Compile & Assemble & Load. The compiler will generate demo.asm file with assembler source. The integrated assembler will assemble that file and make demo.lst and demo.hex files. Demo.hex file will be loaded into the simulator program memory.
- Click on Tools\Software UART Simulation Interface. That will open the Software UART simulator window.
- Click on TX Line label on the Software UART window and select PORTC.5 pin.
- Click on Tools\I2C EEPROM. Another simulation interface will be displayed.
- Click on SDA Line label and select PORTC.4 pin.
- With similar procedure select PORTC.3 pin for the SCL Line.
- Reposition the windows on the screen to get better view. If needed use Always On Top option on the windows.
- Select the Rate\Extremely Fast simulation rate.
- Check that Options\Basic Program Tracking option is turned on.
- Click on Options\Infinite Loop Stops Simulation to turn on that option.
- Click on Simulation\Start. The simulation will start immediately.
- Watch the simulation on the main simulation interface, Software UART and I2C EEPROM simulation modules. Around 10ms of real simulation time will be necessary to pass to see the first activity on the Software UART module. Watch Real Time Duration field.
- The simulation can be stopped any time by clicking on Simulation\Stop. Otherwise, it will be automatically stopped after the whole program has been simulated and infinite loop has been detected.
- Try to run the simulation in Step By Step mode. Then use Run To Next Basic Statement command.

(screenshot)


Example 2: demo2.bas

Examine demo2.bas file from the application folder. This program reads analog value on AN2 analog input and transmits formatted output by a software implemented serial port. That value is also displayed on PORTC pins. File demo2.asm was generated using integrated Basic compiler. File demo2.hex was generated using integrated assembler.


Define SEROUT_REG = PORTB
Define SEROUT_BIT = 5
Define SEROUT_BAUD = 9600

Dim print_value As Byte
Dim x100 As Byte
Dim x10 As Byte
Dim x1 As Byte

Define SIMULATION_WAITMS_VALUE = 1 'suitable for simulation, remove this line for real device code
Define CLOCK_FREQUENCY = 4
Dim an2 As Word

AllDigital 'configure all pins as digital I/O's
ADCON0.ANS0 = 1 'configure AN2 input for analog use
TRISC = 0x00 'configure all PORTC pins as outputs
WaitMs 1000

loop:
   Adcin 2, an2
   'formatted text for software implemented serial port
   print_value = an2
   Gosub ascii_print_prepare
   Serout "Analog input AN2"
   Serout " = ", x100, x10, x1, CrLf
   an2 = an2 / 4 'to get 0-63 range
   PORTC = an2.LB
   WaitMs 1000
Goto loop 'loop forever

End

ascii_print_prepare:
Dim i As Byte
i = print_value / 100 'get number of 100s in print_value
print_value = print_value Mod 100
x100 = i + 48 'get ascii value of i
i = print_value / 10
x10 = i + 48
i = print_value Mod 10
x1 = i + 48
Return


- Start PIC10 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC16F506' and click on Select button.
- Click on Options\Change Clock Frequency.
- Enter '4' and click on OK button.
- Click on Tools\BASIC Compiler.
- Click on File\Open.
- Select demo2.bas file and click on Open. The basic source program will be displayed in the editor.
- Click on Tools\Compile & Assemble & Load. The compiler will generate demo2.asm file with assembler source. The integrated assembler will assemble that file and make demo2.lst and demo2.hex files. Demo2.hex file will be loaded into the simulator program memory.
- Click on Tools\Software UART Simulation Interface. That will open the Software UART simulator window.
- Click on TX Line label on the Software UART window and select PORTB.5 pin.
- Click on RX Line label on the Software UART window and select PORTB.0 pin, so that Software UART does not interfere with our RB2/AN2 pin.
- Click on Tools\Microcontroller View. That will open the Microcontroller View window.
- If you click on the Pin Functions button, you will be able to select pin functions groups to be removed from the display for a more clear view.
- Click on Tools\Oscilloscope. That will open the four channel digital oscilloscope window.
- On the Oscilloscope window menu click on Settings\Change Display Interval and make the selection of 10000us.
- Click on one of the (inactive) labels and select PORTB.5 pin to be monitored by that oscilloscope channel.
- Reposition the windows on the screen to get better view. If needed use Always On Top option on the windows.
- Select the Rate\Extremely Fast simulation rate.
- Check that Options\Basic Program Tracking option is turned on.
- Click on Simulation\Start. The simulation will start immediately.
- Watch the simulation on the main simulation interface, Software UART, Oscilloscope and Microcontroller View simulation modules.
- During the simulation running, click on A button associated with RB2/AN2 pin.
- Using the slider change the analog value on this pin, then wait to see how your change will manifest in the simulator.
- On the main simulation interface, click on Options\Change Color Theme and select one of the many available color themes to customize your IDE.
- The simulation can be stopped any time by clicking on Simulation\Stop.
- Try to run the simulation in Step By Step mode. Then use Run To Next Basic Statement command.

(screenshot)