





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Purdue University Calumet Department of Electrical and Computer Engineering Technology
PIC C Tutorial using “CCS” C Compiler Lab Objective:
Create a step by step tutorial explaining the programming a 16F88 PIC Microprocessor using MPLAB v7.61 and PIC C Compiler.
Procedure
Setup
Writing Program
Now it is time to create a file to put into our project. This can be done one of three ways:
When a new file is created a fresh window will appear that is labeled Untitled. When you save the program it will change to the location of the file.
Type the following code into this window and save in the directory that you created for your program.
#include <16f88.h> //Header file for chip being used
//main body of program void main (void) {
/******************************************************************
//creates endless loop could also have been done with while (1) start:
if (!input(pin_B0)) //is RB0 false / 0 / low {output_bit(pin_B1,0);} //make RB1 false / 0 / low
if (input(pin_B0)) //is RB0 true / 1/ high {output_bit(pin_B1,1);} //make RB1 true / 1 / high
goto start; //repeat loop at start }
After we save this file we need to add it to the project. This program could have been created with any word processing file and saved with a .c extention. If this is done then we just have to add it to the program. Under Project in the menu tool bar select Add files to Project. Select the .c file that you have created and it will be added to your project. You will see that it is loaded under the Source Files in your project window. If you have Header files, Library files, or any other file this is how you would add them. This project does not require any other files so none will be entered.
Selecting Debugger The next thing that we would like to do is simulate our project. Select Debugger from the tool bar. Select he first option, which is Select Tool, then select MPLAB SIM. You will notice that a new tool bar appears. This toolbar will allow us to run, pause, animate, step through and reset a program.
Compiling We are now ready to compile our program. To compile we select Project from the toolbar then select Compile or you can press F10. If there are errors in your program that require attention they will appear in the OUTPUT screen. To view the location of the error in your program, double click on the line displaying the error and it will take you to the spot in the program that contains the error. When your program compiles properly the OUTPUT screen will display:
BUILD SUCCEEDED: date completed
Simulation To check if your program acts as it should, we need to simulate it. BE AWARE the speed at which the computer simulates your program and the actual speed the chip will run will be very different.
First lets find our output so we can view what is happening. Select Special Function Register from under View. We need to look at PORT B, bits 0 and 1. Bit 0 is our input and Bit 1 is our output. When Bit 0 is high then Bit 1 will go high. To make our program act as if it were in the real world we need to have a way to simulate an input. To create this stimulus we select Stimulus Controller – New Scenario from under Debugger. Click on the blue square and a drop down list will appear. Select RB0 from this list. Click the white square next to RB under Action and select Toggle. You should see an arrow appear under Fire. When your program is animated and this arrow is pressed it will simulate an action on RB0.
When you hit the animate button you will see a green arrow go through the program pointing at the instruction it is reading. Look at the SFR window, the Port B specifically. It is all zeros. If you press the fire button to toggle RB0 to high, you see the next program scan Port B is 00000001, indicating that the input RB0 has is high. In the program the first if statement goes false and the second becomes true, causing Port B to become 00000011, indicating that RB1 (output) is now high (light on). Each time that you toggle RB0, RB1 will change to match. You can also step though the program, one instruction at a time. Each time you press the Step into button the scan will move to the next instruction. When you press the Fire button to toggle RB0 no action will take place until the next instruction is called.
Loading Program into PIC chip