SlideShare una empresa de Scribd logo
1 de 14
METU-EEE                                                     EE 494-Engineering Design II

               Tutorial 3: Firmware Debugging with PICKit2


I.   INTRODUCTION

It is a fact that, it does not matter whether you are an engineer or not, everyone does
mistakes in life ☺. We as engineers can skip small details in developing a system for
example. The important thing is that we should figure out and correct those mistakes in
the application we implement. However, sometimes it becomes really frustrating when we
try to find out what the problem really is. We need a procedure more than a “reprogram
and try again” style. That is why “debugging” becomes necessary in our engineering tools.

As you may possibly be familiar from MATLAB programming, you can pause the execution
of your code and investigate the states of each variable you use inside. The debugging
utility you use in MATLAB is a highly featured tool in which you can visually inspect every
item by processing them within functions in the command window or array inspector. With
a step-by-step trace, you can observe and locate the problems in your code and hence fix
them easily. However, you should note that you are using your computer’s resources to
perform this task which includes a highly organized structure when compared to the
hardware limitations of a microcontroller. Therefore, debugging a microcontroller firmware
is usually harder than the software you develop in PC. You need additional components to
perform debugging PICs which is the main subject of this tutorial.

Here, the debugging utility of PICKit2 will be demonstrated with an example using MPLAB
IDE and CCS C compiler. CCS C is a commercial PIC C compiler with very limited 30 day
trial versions; you can buy it if you like. The reason why this compiler is used to
demonstrate the debugging example is to explain also the integration of another compiler
(other than C18 as discussed in tutorial 1) with MPLAB IDE. You can, for sure, use C18 or
other compilers to perform this debugging task.

II. The firmware example

Now let’s implement a simple blinking using PIC16F877. Open MPLAB IDE. Select
Project -> Project Wizard




                                                                                       4-1
METU-EEE                                                   EE 494-Engineering Design II




            Figure 1: Creating a Project in MPLAB with Project Wizard

Click on Next and Select PIC16F877 from the device list.




                 Figure 2: Device selection in creating the Project

Select CCS C toolsuite as the compiler. Check for the directory of the compiler provided
that MPLAB can not locate the toolsuite. Click Next.

                                                                                    4-2
METU-EEE                                                          EE 494-Engineering Design II




                     Figure 3: Selection of the Compiler toolsuite


Create your project directory and the project file. Click Next.




                       Figure 4: Specifying the Project Location



                                                                                          4-3
METU-EEE                                                   EE 494-Engineering Design II



For now, do not add any files to your project; let’s just create an empty project. Click
Next.




                          Figure 5: Addition of existing files

Check your project configuration and finish the wizard.




                                                                                    4-4
METU-EEE                                                      EE 494-Engineering Design II




         Figure 6: Creating an empty project - end of the Project Wizard


Dock your project and output windows. Click on the blank sheet (New File).




            Figure 7: Formatting the Workspace and adding a new file

In the untitled document, copy and paste the following code

                                                                                      4-5
METU-EEE                                                       EE 494-Engineering Design II

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

void main()
{
  int k;
  int j;
  double t;

    for (k = 1;k<10;k++)
    {
            output_high(PIN_D2);
            delay_ms(500);
            output_low(PIN_D2);
            delay_ms(500);
            j = 2*k+1;
            t = j/2;
    }
}

Save your file as main.c in your project directory.




               Figure 8: Saving the main program in the project directory


Now, right click on the Source Files->Add Files. Select the file “main.c” you just created.




                                                                                          4-6
METU-EEE                                                       EE 494-Engineering Design II




           Figure 9: Inclusion of the created “main.c” file in the project


Click on “Build All”, and you will see that new files are created in your project window.




                   Figure 10: Building the code with CCS compiler




                                                                                            4-7
METU-EEE                                                     EE 494-Engineering Design II
Now, let’s program this code to our PIC16F877 device. First of all, you should construct
the programming hardware (with PICKit2) discussed in tutorial 2 (Figure 5 of ICSP
tutorial). You should use the PIC16F877 device as the target microcontroller and place a
resistor (10k) and a LED pair to pin D2 of the microcontroller.

Plug your PICKit2 device to one of the USB ports of your PC and connect your application
circuit and PICKit2 with the ICSP cable (an ordinary cable with 6 independent lines). Now,
we will first program the device from MPLAB. In MPLAB, click on “Programmer”, choose
“Select Programmer” and select PICKit2 (Figure 11).




      Figure 11: Programming the target device from MPLAB with PICKit2

Note that your PICKit2 device is identified by MPLAB (in PICKit2 tab, see Figure 12




                                                                                      4-8
METU-EEE                                                       EE 494-Engineering Design II




                   Figure 12: Identification of PICKit2 in MPLAB

Click on the “program the target device” icon (in Figure 13)




                 Figure 13: Using programming toolbar for MPLAB

Once the programming is verified, you can use your PICKit2 as a debugger.



                                                                                       4-9
METU-EEE                                                        EE 494-Engineering Design II




                 Figure 14: Verification of the programmed device


Select “Debugger”, click on “Select Tool” and select PICKit2.




                     Figure 15: Switching PICKit2 to a debugger




                                                                                       4-10
METU-EEE                                                   EE 494-Engineering Design II
You will be reminded that “a programmer and a debugger can not be used at the same
time” and asked to switch to the debugger. Click OK.




                Figure 16: Configuration of PICKit2 as a debugger

Now, your PICKit2 serves as a debugger. Place a breakpoint on line 19 by double clicking
on the gray bar including the line numbers (Figure 17)




                                                                                   4-11
METU-EEE                                                EE 494-Engineering Design II




                         Figure 17: Placing a breakpoint

Click on the “Run” (play) icon on the debugging toolbar to go to line 19. You may be
asked to recompile the code for the debugger as in Figure 18. Select “Yes” for that
message.




           Figure 18: Configuring the firmware for debugging utilities.



                                                                               4-12
METU-EEE                                                EE 494-Engineering Design II
Now, you can see that the operation is halted at line 19 and you can analyze every
variable by placing your mouse on the variables.




                Figure 19: Investigation of variables in debugger

You can also see every variable and physical memory values (including stack, EEPROM
etc.) from “View”->”Program Memory”, “View”->”Locals” etc.




                                                                               4-13
METU-EEE                                         EE 494-Engineering Design II




   Figure 20: Using “Program Memory”, “Locals” and “Watch” windows in
                               debugger




                                                                        4-14

Más contenido relacionado

Destacado

Programmation pic 16F877
Programmation pic 16F877Programmation pic 16F877
Programmation pic 16F877Mouna Souissi
 
Microchip's PIC Micro Controller
Microchip's PIC Micro ControllerMicrochip's PIC Micro Controller
Microchip's PIC Micro ControllerMidhu S V Unnithan
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...manishpatel_79
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESDr.YNM
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 

Destacado (9)

Programmation pic 16F877
Programmation pic 16F877Programmation pic 16F877
Programmation pic 16F877
 
Chapitre 3 robotique
Chapitre 3 robotiqueChapitre 3 robotique
Chapitre 3 robotique
 
Pic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guidePic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guide
 
Microchip's PIC Micro Controller
Microchip's PIC Micro ControllerMicrochip's PIC Micro Controller
Microchip's PIC Micro Controller
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTES
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Esp with thepic16f877
Esp with thepic16f877Esp with thepic16f877
Esp with thepic16f877
 

Similar a Firmware Debugging with PICkit2

Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfIsmailkhan77481
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORESguest296013
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfWiseNaeem
 
Embedded c lab and keil c manual
Embedded  c  lab  and keil c  manualEmbedded  c  lab  and keil c  manual
Embedded c lab and keil c manualHari K
 
Practical work 1
Practical work 1Practical work 1
Practical work 1wkhairil80
 
ARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfvidhya1806
 
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdf
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdfPic16f877a microcontroller based projects list _ PIC Microcontroller.pdf
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdfIsmailkhan77481
 
xapp744-HIL-Zynq-7000
xapp744-HIL-Zynq-7000xapp744-HIL-Zynq-7000
xapp744-HIL-Zynq-7000Umang Parekh
 
Creating first project in mikroC PRO for 8051
Creating first project in mikroC PRO for 8051Creating first project in mikroC PRO for 8051
Creating first project in mikroC PRO for 8051inovabrasil
 
Advanced view pic microcontroller projects list pic microcontroller
Advanced view pic microcontroller projects list   pic microcontrollerAdvanced view pic microcontroller projects list   pic microcontroller
Advanced view pic microcontroller projects list pic microcontrollerWiseNaeem
 
Pic programming gettingstarted
Pic programming gettingstartedPic programming gettingstarted
Pic programming gettingstartedAjit Padmarajan
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfWiseNaeem
 
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardProgramming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardGaurav Verma
 
Tutorial dec0604(print24) Programming a PIC
Tutorial dec0604(print24) Programming a PICTutorial dec0604(print24) Programming a PIC
Tutorial dec0604(print24) Programming a PICMuhammad Khan
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfWiseNaeem
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxransayo
 
Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005PVS-Studio
 

Similar a Firmware Debugging with PICkit2 (20)

Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
 
Altera up1
Altera up1Altera up1
Altera up1
 
Cp e 214_appendix_c
Cp e 214_appendix_cCp e 214_appendix_c
Cp e 214_appendix_c
 
Embedded c lab and keil c manual
Embedded  c  lab  and keil c  manualEmbedded  c  lab  and keil c  manual
Embedded c lab and keil c manual
 
Practical work 1
Practical work 1Practical work 1
Practical work 1
 
ARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfARM-ES MANUAL.pdf
ARM-ES MANUAL.pdf
 
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdf
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdfPic16f877a microcontroller based projects list _ PIC Microcontroller.pdf
Pic16f877a microcontroller based projects list _ PIC Microcontroller.pdf
 
xapp744-HIL-Zynq-7000
xapp744-HIL-Zynq-7000xapp744-HIL-Zynq-7000
xapp744-HIL-Zynq-7000
 
Creating first project in mikroC PRO for 8051
Creating first project in mikroC PRO for 8051Creating first project in mikroC PRO for 8051
Creating first project in mikroC PRO for 8051
 
Advanced view pic microcontroller projects list pic microcontroller
Advanced view pic microcontroller projects list   pic microcontrollerAdvanced view pic microcontroller projects list   pic microcontroller
Advanced view pic microcontroller projects list pic microcontroller
 
Pic programming gettingstarted
Pic programming gettingstartedPic programming gettingstarted
Pic programming gettingstarted
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
 
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardProgramming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
 
Tutorial dec0604(print24) Programming a PIC
Tutorial dec0604(print24) Programming a PICTutorial dec0604(print24) Programming a PIC
Tutorial dec0604(print24) Programming a PIC
 
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdfAdvanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
Advanced View Pic Microcontroller Projects List _ PIC Microcontroller.pdf
 
Impl installation manual
Impl installation manualImpl installation manual
Impl installation manual
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docx
 
Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005
 

Último

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Último (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Firmware Debugging with PICkit2

  • 1. METU-EEE EE 494-Engineering Design II Tutorial 3: Firmware Debugging with PICKit2 I. INTRODUCTION It is a fact that, it does not matter whether you are an engineer or not, everyone does mistakes in life ☺. We as engineers can skip small details in developing a system for example. The important thing is that we should figure out and correct those mistakes in the application we implement. However, sometimes it becomes really frustrating when we try to find out what the problem really is. We need a procedure more than a “reprogram and try again” style. That is why “debugging” becomes necessary in our engineering tools. As you may possibly be familiar from MATLAB programming, you can pause the execution of your code and investigate the states of each variable you use inside. The debugging utility you use in MATLAB is a highly featured tool in which you can visually inspect every item by processing them within functions in the command window or array inspector. With a step-by-step trace, you can observe and locate the problems in your code and hence fix them easily. However, you should note that you are using your computer’s resources to perform this task which includes a highly organized structure when compared to the hardware limitations of a microcontroller. Therefore, debugging a microcontroller firmware is usually harder than the software you develop in PC. You need additional components to perform debugging PICs which is the main subject of this tutorial. Here, the debugging utility of PICKit2 will be demonstrated with an example using MPLAB IDE and CCS C compiler. CCS C is a commercial PIC C compiler with very limited 30 day trial versions; you can buy it if you like. The reason why this compiler is used to demonstrate the debugging example is to explain also the integration of another compiler (other than C18 as discussed in tutorial 1) with MPLAB IDE. You can, for sure, use C18 or other compilers to perform this debugging task. II. The firmware example Now let’s implement a simple blinking using PIC16F877. Open MPLAB IDE. Select Project -> Project Wizard 4-1
  • 2. METU-EEE EE 494-Engineering Design II Figure 1: Creating a Project in MPLAB with Project Wizard Click on Next and Select PIC16F877 from the device list. Figure 2: Device selection in creating the Project Select CCS C toolsuite as the compiler. Check for the directory of the compiler provided that MPLAB can not locate the toolsuite. Click Next. 4-2
  • 3. METU-EEE EE 494-Engineering Design II Figure 3: Selection of the Compiler toolsuite Create your project directory and the project file. Click Next. Figure 4: Specifying the Project Location 4-3
  • 4. METU-EEE EE 494-Engineering Design II For now, do not add any files to your project; let’s just create an empty project. Click Next. Figure 5: Addition of existing files Check your project configuration and finish the wizard. 4-4
  • 5. METU-EEE EE 494-Engineering Design II Figure 6: Creating an empty project - end of the Project Wizard Dock your project and output windows. Click on the blank sheet (New File). Figure 7: Formatting the Workspace and adding a new file In the untitled document, copy and paste the following code 4-5
  • 6. METU-EEE EE 494-Engineering Design II #include <16F877.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) void main() { int k; int j; double t; for (k = 1;k<10;k++) { output_high(PIN_D2); delay_ms(500); output_low(PIN_D2); delay_ms(500); j = 2*k+1; t = j/2; } } Save your file as main.c in your project directory. Figure 8: Saving the main program in the project directory Now, right click on the Source Files->Add Files. Select the file “main.c” you just created. 4-6
  • 7. METU-EEE EE 494-Engineering Design II Figure 9: Inclusion of the created “main.c” file in the project Click on “Build All”, and you will see that new files are created in your project window. Figure 10: Building the code with CCS compiler 4-7
  • 8. METU-EEE EE 494-Engineering Design II Now, let’s program this code to our PIC16F877 device. First of all, you should construct the programming hardware (with PICKit2) discussed in tutorial 2 (Figure 5 of ICSP tutorial). You should use the PIC16F877 device as the target microcontroller and place a resistor (10k) and a LED pair to pin D2 of the microcontroller. Plug your PICKit2 device to one of the USB ports of your PC and connect your application circuit and PICKit2 with the ICSP cable (an ordinary cable with 6 independent lines). Now, we will first program the device from MPLAB. In MPLAB, click on “Programmer”, choose “Select Programmer” and select PICKit2 (Figure 11). Figure 11: Programming the target device from MPLAB with PICKit2 Note that your PICKit2 device is identified by MPLAB (in PICKit2 tab, see Figure 12 4-8
  • 9. METU-EEE EE 494-Engineering Design II Figure 12: Identification of PICKit2 in MPLAB Click on the “program the target device” icon (in Figure 13) Figure 13: Using programming toolbar for MPLAB Once the programming is verified, you can use your PICKit2 as a debugger. 4-9
  • 10. METU-EEE EE 494-Engineering Design II Figure 14: Verification of the programmed device Select “Debugger”, click on “Select Tool” and select PICKit2. Figure 15: Switching PICKit2 to a debugger 4-10
  • 11. METU-EEE EE 494-Engineering Design II You will be reminded that “a programmer and a debugger can not be used at the same time” and asked to switch to the debugger. Click OK. Figure 16: Configuration of PICKit2 as a debugger Now, your PICKit2 serves as a debugger. Place a breakpoint on line 19 by double clicking on the gray bar including the line numbers (Figure 17) 4-11
  • 12. METU-EEE EE 494-Engineering Design II Figure 17: Placing a breakpoint Click on the “Run” (play) icon on the debugging toolbar to go to line 19. You may be asked to recompile the code for the debugger as in Figure 18. Select “Yes” for that message. Figure 18: Configuring the firmware for debugging utilities. 4-12
  • 13. METU-EEE EE 494-Engineering Design II Now, you can see that the operation is halted at line 19 and you can analyze every variable by placing your mouse on the variables. Figure 19: Investigation of variables in debugger You can also see every variable and physical memory values (including stack, EEPROM etc.) from “View”->”Program Memory”, “View”->”Locals” etc. 4-13
  • 14. METU-EEE EE 494-Engineering Design II Figure 20: Using “Program Memory”, “Locals” and “Watch” windows in debugger 4-14