This tutorial supports is provided to support the book ‘Interfacing PIC Microcontrollers’, and introduces microcontroller circuit design using ISIS schematic capture and simulation. Further details may be found in Chapter 3. This tutorial refers to Proteus v6.8, available from www.labcenter.co.uk.
The circuit to be simulated is shown here, consisting of a PIC 16F877 microcontroller unit (MCU), input push buttons and output LEDs which will display a binary count. An external adjustable CR clock circuit is used. The push buttons are not used in the simple program BIN1.
Make a folder to hold the project files called BIN1.
SCHEMATIC IN PROTEUS:
The ISIS user interface is shown here, consisting of edit, overview and object select windows, with edit toolbars. Components are added to the object list from the libraries provided, dropped onto the schematic, and connected up using virtual wiring. Components can be labelled and their simulation properties modified. Save the schematic as BIN1.DSN in the project folder
Components are found in the libraries accessed via the ‘pick’ button P in the object select window. The MCU is selected from ‘Microprocessors ICs’ category, ‘PIC16 Family’ sub-category. The other components are added to the pick list from the appropriate categories. These are then selected and dropped on the schematic within the blue border.
Save the design file BIN1.DSN in the project folder.
again INCF 06
The MCU needs a program to work as required. From the ‘Source’ menu, select ‘add source file’, ‘new’ and open the source file BIN1.ASM in folder BIN1. Select code generation tool MPASM. Open the source edit window by selecting the new file from the source menu, and enter the source code listed here. It is a minimal program which produces a binary count at Port B (06).
Save the source file code file BIN1.ASM in the project folder.
Save the source code when complete. From the Source menu, select Build All. The message window should confirm build OK. If not, correct syntax errors in the source code by reference to PIC programming rules. A hex file is produced as shown, BIN1.HEX, which contains the MCU machine code.
The machine code program BIN1.HEX is stored automatically in the project folder with the source code.
This hex file must be attached to the MCU in the schematic. Right click, then left click on the PIC chip to open the Edit Component dialogue. Click on the Program File folder tab and select the BIN1.HEX file from the project folder. Set the Processor Clock Frequency to 40kHz. Note that the external components do not affect the simulation clock frequency. The Port B output LEDs should operate when the run/step/pause/stop controls are clicked (the buttons on the schematic have no effect with this program).
Save the completed design file.
Pause the program and from the Debug menu check the PIC CPU Source Code option to display the program with the execution point highlighted. Use the ‘Step Into’ button in the source code window to single step the program. Note that the initialisation instructions are executed once, and the loop then repeats endlessly – this is the usual program operating sequence for control applications. The source code window has buttons to run, single step (into, over and out of subroutines) and set breakpoints.
Correct any logical program errors detected.
To monitor program progress, the MCU registers can be displayed, and other changes monitored, using:
- Special function register display
- RAM register display
- Register watch window
- Execution clock
- Simulation logs
The effect of the program on the registers and status flags, and program timing can thus be checked.
Save the test window arrangement using ‘save preferences’.
When all logical errors have been resolved, the program can be downloaded to the real hardware using the programming tools in MPLAB, for example, using the Mpstart programmer unit. Alternatively, the ICD system allows in-circuit programming and debugging, requiring the purchase of the MPLAB ICD2 module.