Monday, June 24, 2024

PIC Simulator IDE 6.96

- Advertisement -

Example 1: Timer0 module simulation
The easiest example file given in the package is that of an 8-bit Timer0 module of PIC16F84. The BASIC file timer0.bas uses Timer0 module interrupts to periodically change the value on Port B pins. The assembler source file timer0.asm was generated using Basic compiler integrated with the tool and the hexadecimal source file timer0.hex was generated using the integrated assembler:

[stextbox id=”grey”]TRISB = 0x00 ‘set all PORTB pins as
PORTB = %11111111 ‘make all PORTB
pins high
INTCON.T0IE = 1 ‘enable Timer0
INTCON.GIE = True ‘enable all
un-masked interrupts
OPTION_REG.T0CS = False ‘set Timer0
clock source to internal instruction
cycle clock
On Interrupt ‘interrupt routine
PORTB = PORTB – 1 ‘decrement the
value on PORTB
INTCON.T0IF = 0 ‘enable new TMR0

Go to File > Load Program, or press Ctrl+L. Browse and select the file timer0.hex from the window, and open it. The path of the file now appears in the box next to Program Location, and the file will be loaded into IC program memory.

- Advertisement -

Select the PIC model from Options > Select Microcontroller (or simply click on the box next to Microcontroller in main window) and select the appropriate microcontroller (PIC16F84 in this example) from the window.

To open the graphical view of microcontroller pinout and logic states, click on Tools > Microcontroller View. Select the simulation rate to Extremely Fast from Rate in menu bar (or press Ctrl+F5.) The simulation will start immediately when you select Simulation > Start, or press F1. To stop the simulation any time, click on Simulation > Stop (or press F3.)

It is to be noted that, in order to compile this file for other PIC microcontroller models, you may have to change T0IE and T0IF bit names in the source code to TMR0IE and TMR0IF. The datasheet of the model you want to use would have the correct bit names for the INTCON register.

Example 2: 7-segment LED display simulation

The following Basic program makes the numbers 0 to 100 display on a 7-segment LED display:

658_A56_Table[stextbox id=”grey”]Dim digit As Byte ‘input variable for
GETMASK subroutine
Dim digit1 As Byte ‘current high
Dim digit2 As Byte ‘current low digit
Dim mask As Byte ‘output variable
from GETMASK subroutine
Dim mask1 As Byte ‘current high digit
Dim mask2 As Byte ‘current low digit
Dim i As Byte
Dim phase As Bit
Symbol d1enable = PORTC.0 ‘enable
line for higher 7-segment display
Symbol d2enable = PORTC.1 ‘enable
line for lower 7-segment display
TRISB = %00000000 ‘set PORTB pins as
TRISC.0 = 0 ‘set RC0 pin as output
TRISC.1 = 0 ‘set RC1 pin as output
d1enable = False
d2enable = False
mask1 = 0
mask2 = 0
phase = 0
INTCON.T0IE = 1 ‘enable Timer0
INTCON.GIE = 1 ‘enable all un-masked
OPTION_REG.T0CS = 0 ‘set Timer0 clock
source to internal instruction
cycle clock
For i = 0 To 99
digit1 = i / 10 ‘get current high
digit2 = i Mod 10 ‘get current low
TMR0 = 0 ‘reset Timer0 to prevent its
interrupt before both masks are
digit = digit1
Gosub getmask ‘get mask for high
mask1 = mask
digit = digit2
Gosub getmask ‘get mask for low digit
mask2 = mask
Gosub show1 ‘display new mask
Gosub show2 ‘display new mask
WaitUs 500 ‘delay interval suitable
for simulation
‘use large delay for the real device,
say WAITMS 500
Next i
Goto loop
On Interrupt ‘Timer0 interrupt
‘continuously switch between high and
low digit displays
If phase = 0 Then
phase = 1
Gosub show1
phase = 0
Gosub show2
INTCON.T0IF = 0 ‘enable new TMR0
getmask: ‘get appropriate 7-segment
mask for input digit
mask = LookUp(0x3f, 0x06, 0x5b, 0x4f,
0x66, 0x6d, 0x7d, 0x07, 0x7f,
0x6f), digit
show1: ‘show high digit on its
d2enable = False
PORTB = mask1
d1enable = True
show2: ‘show low digit on its display
d1enable = False
PORTB = mask2
d2enable = True

Similar to the previous example, open File > Load Program and select the file 7segment.hex. Select the microcontroller PIC16F877. Go to Options > Change Clock Frequency or click on the box next to Clock Frequency in the main window and enter the value 4.

Select 7-Segment LED Displays Panel from Tools. That will open the 7-segment displays window. In this panel, click on Setup button just below display 2. On the orange field next to Display Enable option, click twice to select the pin that will be used, that is, PORTC and 0. Click on Setup button below display 1 and click twice near Display Enable label as before, and select PORTC,1. Select the Rate to Ultimate. Start simulation by pressing F1.

Now the LED module starts displaying numbers from 0 to 99. The screenshot of this is shown in Fig. 6.

This version of PIC Simulator IDE runs on Evaluation licence. You can start the program 30 times; each session will last for 120 minutes (two hours). After this trial period, a licence needs to be purchased for further use.

Download latest version of the software: click here

The author is a technical correspondent at EFY, Bengaluru


Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components