Home
Downloads
Licenses Contact

OshonSoft

20th Anniversary

2021 - 20th Anniversary of the
OSHONSOFT PROJECT
OshonSoft © 2001 - 2024

PIC18 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 PIC18 Simulator IDE.


Example 1: demo.bas
Example 2: demo2.bas
Example 3: demo3.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 displayed on the attached 2x16 character LCD module. File demo.asm was generated using integrated Basic compiler. File demo.hex was generated using integrated assembler.


Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 1
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD
Define LCD_RWBIT = 2
Define LCD_COMMANDUS = 1000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device

Dim addr As Word
Dim data As Byte

AllDigital 'configure all pins as digital I/O's
Symbol sda = PORTC.4
Symbol scl = PORTC.3

Lcdinit LcdCurBlink
WaitMs 1 'suitable for simulation

For addr = 0 To 31
   data = 200 - addr
   I2CWrite sda, scl, 0xa0, addr, data
   Lcdcmdout LcdClear
   Lcdout "Write To EEPROM"
   Lcdcmdout LcdLine2Home
   Lcdout "(", #addr, ") = ", #data
   WaitMs 1 'suitable for simulation
Next addr

For addr = 0 To 31
   I2CRead sda, scl, 0xa0, addr, data
   Lcdcmdout LcdClear
   Lcdout "Read From EEPROM"
   Lcdcmdout LcdLine2Home
   Lcdout "(", #addr, ") = ", #data
   WaitMs 1 'suitable for simulation
Next addr


- Start PIC18 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC18F4520' and click on Select button.
- Click on Options\Change Clock Frequency.
- Enter '8' 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\LCD Module. That will open the LCD Module simulator window. Click on Yes to load the LCD parameters from the basic program file.
- Click on Setup button on the LCD Module window.
- Click on Change LCD Module Color Scheme.
- Select blue background choice and confirm with Select button.
- Click on Apply! button. Reposition the windows on the screen to get better view.
- 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, LCD and I2C EEPROM simulation modules. Around 15ms of real simulation time will be necessary to pass to see the first activity on the LCD 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 AN0 analog input and transmits formatted output by a software implemented serial port. That value is also displayed on PORTB pins. File demo2.asm was generated using integrated Basic compiler. File demo2.hex was generated using integrated assembler.


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

AllDigital 'configure all pins as digital I/O's
ADCON1 = 0x0e 'configure AN0 input for analog use
TRISB = 0x00 'configure all PORTB pins as outputs
WaitMs 1000

loop:
   Adcin 0, an0
   'formatted text for software implemented serial port
   Serout PORTC.6, 9600, "Analog input AN0"
   Serout PORTC.6, 9600, " = ", #an0, CrLf
   an0 = an0 / 4 'to get 0-255 range
   PORTB = an0.LB
   WaitMs 1000
Goto loop 'loop forever


- Start PIC18 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC18F2520' 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 PORTC.6 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 PORTC.6 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 RA0/AN0 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)


Example 3: demo3.bas

Examine demo3.bas file from the application folder. This program requires that basic compiler floating point math support add-on is enabled, so it can not be tested without a proper license for the software. It used Single data type variables and performs trigonometric functions calculation. It also displays formatted text on the attached 2x20 character LCD module. File demo3.asm was generated using integrated Basic compiler. File demo3.hex was generated using integrated assembler.


Define SIMULATION_WAITMS_VALUE = 1 'suitable for simulation, remove this line for real device code
Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 1
Define LCD_EREG = PORTC
Define LCD_EBIT = 0
Define LCD_RWREG = PORTC
Define LCD_RWBIT = 2
Define LCD_COMMANDUS = 1000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device

Dim x1 As Single
Dim x2 As Single
Dim y1 As Single
Dim y2 As Single

Define SINGLE_DECIMAL_PLACES = 4
AllDigital 'configure all pins as digital I/O's
Lcdinit LcdCurBlink
WaitMs 1000

x1 = 2.2
x2 = 2.2

loop:
   y1 = Sin(x1)
   y2 = Cos(x2)
   Lcdcmdout LcdClear
   Lcdout "Sin(", #x1, ")=", #y1
   Lcdcmdout LcdLine2Home
   Lcdout "Cos(", #x2, ")=", #y2
   WaitMs 1000
   x1 = x1 + 0.1
   x2 = x2 + 0.1
Goto loop 'loop forever


- Start PIC18 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC18F2550' 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 demo3.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 demo3.asm file with assembler source. The integrated assembler will assemble that file and make demo3.lst and demo3.hex files. Demo3.hex file will be loaded into the simulator program memory.
- Click on Tools\LCD Module. That will open the LCD Module simulator window. Click on Yes to load the LCD parameters from the basic program file.
- Click on Setup button on the LCD Module window.
- Click on Change LCD Module Color Scheme.
- Select green background choice and confirm with Select button.
- Click on LCD Type label and select 2 lines, 20 characters LCD module type.
- 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\Watch Variables to open another very useful simulation interface for basic program debugging. Its window is resizeable. Variables from the loaded basic program will be automatically added to the display.
- 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.
- On the main simulation interface, click on Options\Change Color Theme and select one of the many available color themes to customize your IDE.
- Click on Simulation\Start. The simulation will start immediately.
- Watch the simulation on the main simulation interface, LCD display, Watch Variables and Microcontroller View simulation modules. Around 15ms of real simulation time will be necessary to pass to see the first activity on the LCD module. Watch Real Time Duration field.
- 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)