Documentation::Microchip PIC 16F84 Microcontroller

This component is the heart of the simulator. It allows simulation of Microchip's microcontroller PIC 16F84. For full specifications of this microcontroller, have a look at the datasheet found on Microchip's website.

How to program and use PIC 16F84 is out of the scope of this document. Search for a tutorial on the net.

Contents

  • Getting started with PIC 16F84
  • PIC 16F84 workspace windows
  • Assembling source code
  • Debugging
  • Programming the real device
  • List of implemented features

Getting started with PIC 16F84
When you create a project only contains a PIC 16F84 Microcontroller you will get a whole bunch of windows in your workspace.

A template file is loaded so you can start coding immediately in the Program Memory window. To the right four debugging window appear, Special Function Registers Debug, File Register Debug, EEPROM Debug, and Stack Debug. In the middle a window containing a picture of the PIC 16F84 that shows the pins current state and if they are inputs or output.

A tab containing commands is added at the top of the application labelled PIC Microcontroller.


PIC 16F84 workspace windows

Program Memory window
This window contains a simple editor used when writing the assembler code. If the included editor doesn't satisfy your needs, you can use an external. Just save before clicking on Build.

Program Memory window is used for both editing and debugging. In the picture above in editing mode.

Click on this button to switch to source editing mode.
Click on this button to switch to debugging mode.

Special Function Registers Debug window
Shows some the more important registers that have special functions in the PIC 16F84. The content of the registers are shown in hexadecimal, binary and decimal format. Z and C flag are extracted from the STATUS register to ease the debugging process.

Click on this button to hide/show Special Function Register Debug

 

 

File Register Debug window
Shows all the registers available in PIC 16F84 in hexadecimal format.

By clicking on a register's value you get a Register Watch window. Using the watch window you can alter the register's value, easy follow the register's changes and break at a given value.

Note: A maximum of six Register Watch windows can be used.

Click on this button to hide/show the File Register Debug window.
Click on this button to show hidden Register Watch windows. If all are visible, a new Register Watch window is created.

EEPROM Debug window
Show the content of the inbuilt EEPROM memory.

To set the content of the EEPROM memory use this method in your source code:

  org 0x2100
  dw 0,0,0,0,0

To change a value, click on it and a Modify memory window appears.

Click on this button to hide/show the EEPROM Debug window.

 


 

Stack Debug
The PIC 16F84 has an 8-level deep hardware stack. 8 levels are not much and a stack overflow easily occurs when call is extensively used.

Tip: Click on a stack level label to start simulation. The simulation automatically stops when a return instruction is executed. This is an easy way to step out of a procedure.

Click on this button to hide/show the Stack Debug window.

Breakpoints window
Shows the list of used breakpoints

Tip: Clicking on a breakpoint shows it in the Program Memory window.

Click on this button to hide/show the Breakpoints window.

Assembling source code
After the source code has been written in the Program Memory editor, the source code has to be assembled before simulation can be performed. By clicking on the Build button in the PIC Microcontroller tab you assemble the source code.

   
PIC Development Studio doesn't have an inbuilt assembler. It uses GPASM, which is part of the GPUTILS package provided by Craig Franklin and Scott Dattalo. The assembler is included and integrated so no hassle with that.

Build errors are show at the bottom of the Program Memory window:


Debugging
The debugging capabilities is the reason way one use a simulator. After the source code is assembled it is now possible to step through the code, instruction by instruction. It's also possible to run the simulation as fast as the computer can achieve. Using a 1 GHz PC it should able to achieve 500000-1000000 instructions per second.

By clicking on the Mem button you switch Program Memory window to debugging mode. This is also done automatically if clicking on the step or run button.

The blue arrow shows where execution currently takes place. The red dot indicated that a breakpoint is placed on that line.


Debug buttons
Step into
Normal step. If the current instruction is call, it steps into that sub procedure
Step over
If the current instructions is call, it runs that procedure and halts on the instruction after call.
Step out
Runs until a return is reached and then halts.
Reset
Power-on-reset performed on PIC 16F84
Skip next instruction
Don't execute the next instruction

Right-click menu
By right clicking on the selected line pops up this menu.

Run here
Adds a breakpoint and runs until this line is reached. When the line is reach the simulation is stopped and breakpoint removed.

Jump here
Move the program counter to this address

Toggle breakpoints
If no breakpoint exists on this line, a breakpoint is added. If a breakpoint already exists, it is removed.


Tool-tip hovering
By holding the mouse still over a line a few seconds pops up a tool-tip. The tool-tip contains the symbols found on that line and the content of the register with the same address as the value of the equ.

Note: It does not understand the difference between register definitions and bit definition. Therefore it may show nonsense if symbol is a bit definition. It also doesn't work on registers located in Bank 1.

Watchdog Timer
The PIC 16F84 has a watchdog timer to help the program out of infinite loops. This can be enabled and disabled by the watchdog timer button. It is disabled by default. Do not enable the watchdog timer if you are not sure how it works.

Watchdog timer is currently used
Watchdog timer is currently not used

Programming the real device
After you have developed and simulated the program you probably want to test it with a real PIC 16F84 to make sure it work. To do this you have to own a programmer. By clicking on the Program button IC-Prog by Bonny Gijzen, a great freeware PIC programming software, is launch with the hex file loaded. Then you only have to configure the fuses and program the device.

Launches IC-Prog by Bonny Gijzen.


List of implemented features
These features of the PIC 16F84 have been implemented and should be working correctly

  • All 35 instructions
  • Bank0 and Bank1
  • 13 programmable bi-directional pin
  • All interrupts (INTF,RB Change,TMR0 and EEPROM write)
  • Watchdog timer (with prescaler)
  • Timer 0 (with prescaler and increment on instruction/RA4)
  • Internal EEPROM read and write (with interrupt)
  • Indirect addressing (INDF / FSR)
  • Status bits Z, C and DC
  • Sleep (and wake-up on interrupt / watchdog timeout)

Not yet implemented

  • Computed gotos (writing to program counter)