Lab 0: Compiling, Running, and Debugging

Similar documents
Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2 Iterative Code Design handout Style Guidelines handout

Adverse Action Letters

REFWORKS: STEP-BY-STEP HURST LIBRARY NORTHWEST UNIVERSITY

COP2800 Homework #3 Assignment Spring 2013

Scroll down to New and another menu will appear. Select Folder and a new

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C

INSTALLING CCRQINVOICE

Campuses that access the SFS nvision Windows-based client need to allow outbound traffic to:

Laboratory Exercise 3 Using the PIC18

Project #1 - Fraction Calculator

Preparation: Follow the instructions on the course website to install Java JDK and jgrasp on your laptop.

TRAINING GUIDE. Lucity Mobile

Word 2007 The Ribbon, the Mini toolbar, and the Quick Access Toolbar

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

Working With Audacity

InformationNOW Letters

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

Web of Science Institutional authored and cited papers

The Reporting Tool. An Overview of HHAeXchange s Reporting Tool

These tasks can now be performed by a special program called FTP clients.

Entering an NSERC CCV: Step by Step

Introduction to Eclipse

Using the Swiftpage Connect List Manager

Relius Documents ASP Checklist Entry

Assignment 10: Transaction Simulation & Crash Recovery

ROCK-POND REPORTING 2.1

Using CppSim to Generate Neural Network Modules in Simulink using the simulink_neural_net_gen command

CSE 361S Intro to Systems Software Lab #2

Manual for installation and usage of the module Secure-Connect

FIT 100. Lab 10: Creating the What s Your Sign, Dude? Application Spring 2002

InformationNOW Letters

Installing and using QGIS

Quick start guide: Working in Transit NXT with a PPF

Municode Website Instructions

TUTORIAL --- Learning About Your efolio Space

InformationNOW Letters

The Login Page Designer

August 22, 2006 IPRO Tech Client Services Tip of the Day. Concordance and IPRO Camera Button / Backwards DB Link Setup

Adobe InDesign: The Knowledge

Xilinx Answer Xilinx PCI Express DMA Drivers and Software Guide

RISKMAN REFERENCE GUIDE TO USER MANAGEMENT (Non-Network Logins)

Element Creator for Enterprise Architect

Exercise 4: Working with tabular data Exploring infant mortality in the 1900s

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Enabling Your Personal Web Page on the SacLink

TRAINING GUIDE. Overview of Lucity Spatial

Managing Your Access To The Open Banking Directory How To Guide

Introduction to GRIN Global Curator Tool Interface

Faculty Textbook Adoption Instructions

Date: October User guide. Integration through ONVIF driver. Partner Self-test. Prepared By: Devices & Integrations Team, Milestone Systems

Proper Document Usage and Document Distribution. TIP! How to Use the Guide. Managing the News Page

Integrating QuickBooks with TimePro

Using the Swiftpage Connect List Manager

TaiRox Mail Merge. Running Mail Merge

Introduction to Adobe Premiere Pro for Journalists:

ClassFlow Administrator User Guide

MySqlWorkbench Tutorial: Creating Related Database Tables

Dashboard Extension for Enterprise Architect

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Lab 5 Sorting with Linked Lists

MOS Access 2013 Quick Reference

Test Pilot User Guide

Lab 4. Name: Checked: Objectives:

Uploading Files with Multiple Loans

Quick Start Guide. Basic Concepts. DemoPad Designer - Quick Start Guide

Tips and Tricks in Word 2000 Part II. Presented by Carla Torgerson

Element Creator for Enterprise Architect

ClubRunner. Volunteers Module Guide

OASIS SUBMISSIONS FOR FLORIDA: SYSTEM FUNCTIONS

SmartPass User Guide Page 1 of 50

PowerTeacher Classroom Management Tool Quick Reference Card

Extended Vendors lets you: Maintain vendors across multiple Sage 300 companies using the Copy Vendors functionality. o

PaperStream Capture change history

OpenSceneGraph Tutorial

Assignment #5: Rootkit. ECE 650 Fall 2018

WorldShip PRE-INSTALLATION INSTRUCTIONS: INSTALLATION INSTRUCTIONS: Window (if available) Install on a Single or Workgroup Workstation

Ascii Art Capstone project in C

Paraben s Phone Recovery Stick

BI Publisher TEMPLATE Tutorial

Qualtrics Instructions

STIDistrict AL Rollover Procedures

INFOCUS Enrollment by Count Date

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Acclaim Solaria 5.31 Release Notes

BANNER BASICS. What is Banner? Banner Environment. My Banner. Pages. What is it? What form do you use? Steps to create a personal menu

Guide to getting started in J2ME for the Motorola A780 phone

Reading and writing data in files

Chapter 2 Basic Operations

Importing data. Import file format

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture2 Functions

Procedures for Developing Online Training

Using the Turnpike Materials ProjectSolveSP System (Materials & ProjectSolveSP Admin)

Using MeetingSquared as an Administrator

Access the site directly by navigating to in your web browser.

Project 4: System Calls 1

Procurement Contract Portal. User Guide

Using SPLAY Tree s for state-full packet classification

IBM SPSS Interviewer Setting up Data Entry Supervisor machines for Synchronization

CLIC ADMIN USER S GUIDE

Transcription:

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 0: Cmpiling, Running, and Debugging Intrductin Reading This is the first lab in CMPE13. Here we will demnstrate the basics f running a C prgram. We will als explre the tls we will use and sme f their features fr debugging prblems yu might encunter. The supplemental n cmpilatin steps The supplemental n cmpiler errrs/warnings The supplemental n frmatting The supplemental n the cde style checker K&R Preface and Intrductin K&R Chapter 1 thrugh sectin 1.2 Prvided Files part1.c This file cntains all the cde necessary t display a single blinking light. Yu will need t cmplete the setup prcedures listed belw, cmpile, and run this cde t demnstrate t a TA r Tutr that yu have cmpleted part ne fr a check ff. part2.c This file cntains cde t display a simple message t the terminal, as well as varius cmpiler errrs and warnings. Again, yu will need t cmplete the setup prcedures listed belw, fix the cmpiler errrs, and demnstrate t a TA r Tutr that the message is crrectly displayed t the terminal fr a secnd check ff. part3.c This file cntains cde that perfrms a simple srting algrithm n five randmly generated numbers. Again, fllw the setup prcedures listed belw, add the requested dcumentatin, and frmat the cde t fllw the prvided style guidelines. part4.c This file cntains an empty main() t be filled with the exercises frm sectin 1.2 f K&R. Detailed steps are listed belw. Assignment requirements

Part One: Receive a check ff frm a lab TA r Tutr fr part ne by demnstrating crrect functinality. Cmplete setup prcedures Cmpile and run Part Tw: Receive a check ff frm a lab TA r Tutr fr part tw by demnstrating crrect functinality. Cmplete setup prcedures Fix cmpiler errrs and warnings Cmpile and run Part Three: Cmplete the requested mdificatins t this cde. Cmplete the setup prcedures Add the requested dcumentatin Frmat the cde t fllw the prvided style guidelines Part Fur: Cmplete the temperature cnversins tables frm the exercises in chapter ne. Create the standard cnversin table frm page 12 f K&R Mdify this cde t als display the header and additinal cnversin table frm exercises 1-3 & 1-4 Frmat the cde crrectly accrding t the style guidelines Submissin Parts 1 & 2 nly require TA check ff fr cmpletin. Parts 3 & 4 d nt require a check ff, but instead require cde submissin via ecmmns. If yu d nt have a check ff fr parts 1 and 2 yu will receive a 0. Submit part3.c & part4.c via ecmmns befre the due date (duble check that it was accepted, again BEFORE the due date). Grading This assignment cnsists f 10 pints: The checks-ffs fr parts 1 and 2 are wrth 1 pint each, but yu will receive 0 pints fr the entire lab if yu fail t receive either check ff. Fur pints are fr the cmments yu add t part3.c Tw pints fr the style changes t part3.c

One pint fr part a) & b) f part4.c One pint fr part c) f part4.c Yu will lse pints fr the fllwing: -10: n check ff fr part 1 r part 2-10: part3.c r part4.c desn t cmpile -2: Yu dn t submit exactly part3.c and part4.c (including using the crrect file names) via ecmmns Part 1 Hell Wrld 1. Open MPLAB X. This can be fund by searching fr mplab x in the Windws 7 Start Menu. Otherwise it is available in the class prgrams flder linked t frm the desktp. 2. Set the editr use tabs instead f spaces by unchecking "Tls"->"Optins"->"Editr"- >"Frmatting"->"Expand Tabs t Spaces". 3. Create a new prject in MPLAB X (Select File New Prject ) using the standard Micrchip Embedded Standalne Prject. 4. Select the PIC24FJ128GA010 device 5. Ignre the Debug Header prmpt 6. Leave the Tl the default ICD3 7. If the C30 cmpiler is nt selected, click n s that it's highlighted. If this isn't an ptin yu mst likely failed t install the C30 cmpiler. 8. Fr the prject name use Lab 0 Part 1 (this is a requirement fr check ff) 9. Select a Prject Lcatin t be the parent directry fr this prject (such as "CMPE13\Lab0". The prject directry will be created fr autmatically by MPLAB X. 10. Check the Set as main prject ptin. The main prject will be highlighted in bld in the prjects listing. The main prject is what is built when yu select the Build cmmand. 11. Add part1.c t the prject (Right-click n the "Surce Files" flder in the prject windw btainable frm View Prject)

12. Remember fr future reference that nly ne file with a main() functin can be added t yur prject at a time. 13. Specify that the prject shuld be cmpiled int a COFF file (this is just a different binary frmat required by ISIS t allw fr debugging). Set "Run" "Set Prject Cnfiguratin" "Custmize..." "C30 (Glbal Optins)" "Output file frmat" t COFF. 14. Build the prject fr debugging by clicking the arrw next t the hammer and selecting "Build fr Debugging". This will result in a "Lab_0_Part_1.X.debug.cf" file under "\Lab 0 Part 1.X\dist\default\debug" 15. Yu shuld see black BUILD SUCCESSFUL text at the end f a successful build. A failed build will shw a red BUILD FAILED message. See us if yur build fails 16. Nw launch the ISIS 7 Dem simulatr prgram.

This can be fund by searching fr ISIS in the Windws 7 Start Menu. Otherwise it is available in the class prgrams flder linked t frm the desktp. 17. Lad the Explrer 16.DSN file int ISIS that is available n the Curses website by selecting the File Open Design menu ptin. 18. Right-click n the beige grid within the simulatr and select 2. PIC24 Prcessr Mdule 19. Duble click n the prcessr mdule and set the Prgram File: directry t the lcatin f COFF file yu generated in step 4. 20. G back t 1. Interactive Elements by right clicking n the backgrund again and selecting "1. Interactive Elements". 21. Run the prject in debugging mde (Debug Start/Restart Debugging, Ctrl+F12). Yu shuld see tw new windws pp ne. The smaller windws named "PIC24 CPU Variables - U1" shws the single variable that is used in this prgram (it has the value '\0'). The larger windw "PIC24 CPU Surce Cde - U1" shws the part1.c file and indicates that the prgram is currently paused at the start f main(). The brwn Pause buttn and the green Play buttn indicate this state as well. 22. Clicking the green Play buttn in the bttm-left crner will cntinue executin f the prgram. Thse additinal tw windws will disappear and yu shuld see LED D3 flashing. 23. If yu pause the prgram again by clicking the Pause buttn in the bttm-left crner f ISIS (r via Debug Pause, Pause) yu will see what line the prgram is currently n and the current value f _cunter and _i. 24. Pressing the Stp buttn will end the simulatin and reset the prcessr s that the prgram can be simulated again. 25. Part 1 is nw cmplete. Cntinue n t part tw befre calling fr a TA r tutr t check yu ff. Once yu are ready fr check ff yu shuld: Demnstrate that the cde cmpiles by rebuilding the prject with the Clean and Build Prject fr Debugging cmmand (Under the Hammer and Brm).

Shw the cde executing prperly by reselecting the.cf file in ISIS and starting it running again. Part 2 Cmpilatin errrs 1. Create a new MPLAB prject fllwing the same prcedures as dne in Part 1, but this time naming the prject "Lab 0 Part 2". 2. Add "part2.c" frm ecmmns t this new prject 3. Fix all cmpilatin errrs and warnings. Cmpiler errrs and warnings shuld be used as hints n hw t fix the prblems, nt slutins themselves. Mst cmpiler messages are vague, but becme mre understandable with experience. The best way t fix these prblems is t read what the cmpiler tells yu and then lk at yur cde at the apprpriate lines r just abve. Lk fr patterns in the syntax that dn t match up as yu will nt understand all f the cde right nw. Fr example ntice that mst lines usually end in semiclns and that mst braces cme in pairs. Refer t sectins 1.1-1.2 in K&R fr mre examples f gd C cde. 4. Yu can see the line where the errr/warning ccurred by duble-clicking n the blue text describing said errr/warning. 5. Smetimes errrs are hidden by ther errrs, s be sure t recmpile after fixing a few errrs as thers may have been expsed. 6. Once all errrs have been fund and fixed, lad the resulting "Lab_0_Part_2.X.debug.cf" file int ISIS like yu did in Part 1. 7. The prgram utput shuld be visible in the ISIS virtual terminal windw that will appear when yu run the prgram. If the Virtual Terminal Windw desn t appear, display it via the Debug 5. Virtual Terminal menu ptin. 8. Replace the cmment n line 45 abve the call t putsuart2() with the text that actually appears in the virtual terminal windw in ISIS. 9. Add a multiline cmment abve main() specifying the amunt f flash memry used by this prgram (Windw Dashbard). 10. Part 2 is nw cmplete. Yu may call a TA/tutr ver t check yu ff fr bth Part 1 and Part 2. Fr Part 2 demnstrate everything yu needed t d fr Part 1, but als shw them the cmments yu made t the cde in part2.c. Part 3 Debugging and cde style

1. Create a new MPLAB prject fllwing the same prcedure as in part 2 and add "part3.c" t this prject. 2. Build the prgram fr debugging like yu have dne fr Part 1 and 2 and pen it within ISIS. 3. Start the prgram using the Ctrl+F12 shrtcut s that the prgram starts running and pauses at the start f main(). 4. Set a breakpint at the start f the uter fr-lp. A breakpint can be created by duble clicking n a line f cde. Duble-clicking again remves it. Breakpints can nly exist n lines with cde that aren t nn-initializing variable declaratins r pening braces. Yu can tell easily by if the left-mst clumn has a teal hex value indicating that the line executes cde r dashes. 5. Make sure the CPU Variables windw is pen (Debug PIC24 CPU Variables U1) and expand the "A" array by clicking the icn next t "_A" s that all 5 elements are visible. 6. Set the A array t display as a signed integer by selecting all 5 f the elements f A (using shift and clicking) and then right-clicking and selecting "Signed Integer". 7. Start running yur prgram and watch it stp at the breakpint yu set at the beginning f the fr-lp. There shuld be a red arrw t the left f the line the prcessr is abut t execute. Yu can fllw the executin f cde by stepping thrugh each line f cde. The Step Int buttn will execute the line f cde that the prgram cunter (the red arrw) is currently pinting t and then increment the prgram cunter t the next line f cde t be executed. The Step Over buttn will execute the line f cde pinted t by the prgram cunter and then increment the prgram cunter t the next line f cde t be executed; hwever, Step Over will ignre stepping int functins r any cde within a file ther than the current surce file being stepped thrugh.

The Step Out buttn returns the prgram cunter t the cde that called the cde currently being lked at while executing any cde necessary t get there. If yu understand the Stack then this will just mve ne frame up the call stack. 8. Recrd the value f all the elements in A while it s stpped at this breakpint. 9. Place anther breakpint at the last line f the fr-lp. Cntinue t hit the Run buttn t execute anther iteratin f the fr-lp. After it breaks at the breakpint press the Step-ver buttn t finish executing the lp. Then recrd the value f A. Cntinue t d this fr every iteratin (there shuld be 5 ttal). 10. Cmplete Task 1 - Add dcumentatin Add a cmment directly abve the srting fr-lp that states the value f the A array initially, after every iteratin f the fr-lp, and after the array has been srted. Add a cmment abve the OpenUART2() functin call that specifies n what line yu can find its functin declaratin in uart2.h. This can be dne by right-clicking n the functin name and selecting "Navigate" "G T Implementatin" 11. Cmplete Task 2 - Crrect frmatting part3.c des nt cnfrm t the dictated style guidelines. Fix everything in main() t cnfrm t these standards (recrding hw many changes yu make). Yu may use the prvided StyleChecker.exe prgram if yu want t. Remember that this tl is nt 100% accurate s yu'll als want t cnsult the style guidelines. Please remember that single-line cmments // are acceptable and dn t need t be changed. Cunt fixing a single issue, such as the spacing arund an peratr, as a single change, even if it includes mre than ne space. Hint: There are between 5 and 15 style errrs that need fixing. Hint: All f the earlier parts f this lab all cnfrmed t this standard. 12. Cmplete Task 3 - Add dcumentatin Add the number f cde style changes yu made t yur cmments abve main(). Please make sure that yur style changes d nt prevent yur part3.c frm cmpiling! If it desn t cmpile yu will nt get any credit fr this lab. 13. Submit yur part3.c using ecmmns t the Lab 0: Hell Wrld assignment by attaching part3.c and clicking Submit.

Part 4 Temperature Cnversin a) Standard Cnversin Table 1. Create a new MPLAB prject fllwing the same prcedure as in Part 3 and add part4.c t it. 2. Implement the example n page 12 f K&R. T d this, simply cpy the cde frm the bk (all f the cde within main()) and paste it between the cmments that say Yur cde ges in between this cmment and... in yur part4.c file. 3. Cmpile and run yur cde and verify that the table runs crrectly and lks like the partial table at the tp f page 13 f K&R. 4. Make an additinal change t this example cde f setting the Fahrenheit value t print the same way the Celsius value des by changing the %3.0f t %6.1f. See the last 2 paragraphs in sectin 1.2 f K&R fr an explanatin f these frmat specifiers. b) Header 1. Mdify yur table by cmpleting Exercise 1-3 frm K&R (page 13), adding a header t the tp f yur temperature table with the letters F and C spaced nicely. This header shuld be printed nce befre any f the cnversins take place. 2. Cmpile and run yur prject t cnfirm that the utput is as expected. c) Celsius t Fahrenheit Table 3. Nw mdify this cde again by adding a blank line with a printf( \n ); t the end f yur table frm Part B abve. 4. Cmplete Exercise 1-4 in K&R by fllwing that blank line with a crrespnding Celsius t Fahrenheit cnversin table. This can be dne with nearly the same cde that prduced the first table. 5. Nte that a cmpiler errr will ccur if tw variables f the same name are declared. Yu need t have unique names fr all variables within a single scpe (scpe will be explained later). Yu can reuse yur variables frm the first table fr generating the secnd table, just make sure that the flat fahr and int lwer, lines nly appear nce at the tp. 6. Als give this table a header like yu did in Part B. 7. Finally run the style checker ver this file and check the frmatting by hand as well t cnfirm that it fllws the prvided style guidelines. 8. If parts a) & b) are als dne submit yur part4.c using ecmmns t the Lab 0: Hell Wrld assignment by attaching part4.c and clicking Submit.

Final Output (Part 4)