Tutorial 1: Port Counter 'Smoke Test'

A 'Smoke Test' in electronics is literally that. If you have been playing electronics for long enough you are probably familiar with what happens (rarely..) when you first put power into your newly wired circuit.. if you can see or smell smoke then you probably haven't wired it up correctly! Assumedly because something is short circuited or wired incorrectly. The Port Counter is a great 'Smoke Test' because it is about the simplest program you can write that has external visual cues to indicate your hardware is correctly wired up to the power supply, oscillator, reset circuitry and that your programmer is functioning correctly. The same is true for working with Virtual Breadboard. In this Tutorial we will cover the basics of how to setup MLAB to develop code that will work with a Virtual Breadboard simulation.

Download FEATURE877_Tutorial1.zip and unzip into folder <your path>\Tutorial 1

Filename Version Description
tut1.pjt 1.0 MPLAB Project
tut1.asm 1.0 PIC16F877 Assembler code
tut1.vbb 1.0 Virtual Breadboard simulation
tut1.lst 1.0 Compiled LST* Intentionally out of date - do not rebuild project without following tutorial instructions
tut1.hex 1.0 Compiled HEX* Intentionally out of date - do not rebuild project without following tutorial instructions

 Open tut1.vbb in Virtual Breadboard

Start Virtual Breadboard and open the <your path>\Tutorial 1\tut1.vbb file from Virtual Breadboard.

 Run tut1.vbb in Virtual Breadboard

Click RUN, the simulation begins and the LED attached to PORTB begins to flash on and off. The whole Port flashes on and off, but this is supposed to be a Port Incrementor example? This is intentional, the HEX included with the Tutorial1 download is intentionally out of date, and is the part of this tutorial to teach you one thing and that is how to use MPLAB to update files used in Virtual Breadboard simulations.

Important! Making Changes to the MPLAB file.

An important part of the way you develop using Virtual Breadboard is to understand how to make your latest changes to the MPLAB file available in Virtual Breadboard. It is simple really, after you compile the MPLAB project you need to click the Virtual Breadboard RESET button. This will instruct the PIC16F877 to check to see if there is an updated version of the HEX file which if available it will load before continuing execution or stepping. This takes only a fraction of a second to load the update compared with several minutes for a real PIC16F877. This is the first place you will save time in your Virtual Development Cycle. MPLAB integrates with several C and Basic compilers so no matter your language understanding how to switch between Virtual Breadboard and MPLAB is a simple but important lesson. So lets do it.

Open tut1.pjt in MPLAB

Start MPLAB and open the <your path>\Tutorial 1\tut1.pjt file. The assembler code, tut1.asm, contains the updated code to increment the port correctly. You will notice the PORT toggle code is commented out, this was the code used to create the old HEX file that is currently loaded. Build the project to generate the new HEX file with the incrementing code. Now, switch to Virtual Breadboard, probably using the Virtual Breadboard icon in the taskbar is the easiest way. Now click Virtual Breadboard  RESET. Virtual Breadboard will take a moment to load the new HEX and then (press RUN if it is not already running) it will begin incrementing the PORTB LED as per the new HEX. The ability to setup a test environment in Virtual Breadboard and switch back and forth to MPLAB instantly uploading HEX updates is a critical workflow for developing in Virtual Breadboard using MPLAB.

Features Demonstrated

TRISB

PORTB

Using MPLAB with Virtual Breadboard