You are on page 1of 10

Dr. D.

Capson Comp Eng 2DP4 19/01/12



1
Us|ng MLA8 IDL w|th the McMaster LCL IC24 board

1hls LuLorlal descrlbes how Lo use Lhe MLA8 luL for each of Lhe followlng:

1. CreaLlng an MLA8 ro[ecL for Assembly Language programs
(source flle names for assembly programs musL have exLenslon .s)

2. CreaLlng an MLA8 ro[ecL for C-language programs
(source flle names for C programs musL have exLenslon .c)

3. 8ooLloadlng code Lo Lhe LCL lC24 hardware module

4. CreaLlng an MLA8 ro[ecL by copylng an exlsLlng pro[ecL
(Lhls ls Lhe fasLesL way Lo creaLe a new pro[ecL)

3. 1ransferrlng your pro[ecLs Lo Lhe lab from your own C

Important: lL ls recommended LhaL you creaLe your pro[ecL folders on Lhe SAML level of Lhe dlrecLory sLrucLure
as your copy of Lhe p|c24_code_examp|es, and on Lhe same drlve, as shown ln Lhe example below.

1hls allows for slmpllclLy ln creaLlng relaLlve paLh names Lo enable MLA8 luL Lo flnd requlred flles when
bulldlng your pro[ecLs. 1hls wlll also allow you Lo easlly copy your enLlre pro[ecL sLrucLure and brlng lL Lo Lhe lab
machlnes. lor Lhe example shown ln llgure 1 below, lf you copy Lhe folder COMPENG2DP4 onLo a uS8 flash
drlve, lL can be saved onLo Lhe lab machlnes and all your work comes wlLh you.

1he p|c24_code_examp|es folder should be downloaded from www.reesemicro.com Lo ensure LhaL you
have Lhe laLesL updaLes. 1hls folder conLalns all of Lhe LexLbook code examples, llnker scrlpL flles, lnclude flles,
C llbrary flles and Lhe booLloader sofLware.



I|gure 1 - ro[ect fo|ders shou|d be created at the same |eve| of the d|rectory
structure as the p|c24_code_examp|es fo|der

Dr. D. Capson Comp Eng 2DP4 19/01/12

2
?ou can have more Lhan one pro[ecL ln a pro[ecL folder, buL noLe LhaL each pro[ecL generaLes several assoclaLed
flles ln addlLlon Lo Lhe source code flle (Lhese lnclude an ob[ecL flle, a map flle, Lhe hex flle, a workspace save
flle, eLc.). 1he folder can become cluLLered.

AlLernaLlvely, you can also organlze your pro[ecLs such LhaL each pro[ecL has lLs own folder as long as Lhey
remaln aL Lhe same level of Lhe dlrecLory sLrucLure such as shown ln llgure 2 below:



I|gure 2 - Lach pro[ect may be saved |n |ts own fo|der


Agaln, for Lhe example of llgure 2, lf you copy Lhe folder COMPENG2DP4 onLo a uS8 flash drlve, lL can be
saved onLo Lhe lab machlnes and all your work comes wlLh you.
Dr. D. Capson Comp Eng 2DP4 19/01/12

3
1. Creat|ng an MLA8 ro[ect for Assemb|y |anguage programs

1o geL you sLarLed, Lhere are Lwo assembly language source code examples avallable on Lhe course web slLe:

1. counter.s - Lhe 4-blL blnary counLer on Lhe lC24 LLus on orL 8
2. sw|tch_echo.s - Lhe swlLch echo program LhaL dlsplays Lhe swlLch paLLern on orL A on orL 8 LLus

uownload Lhese source flles and bulld a pro[ecL for each of Lhem uslng Lhe followlng procedure. 1hese source
flles can be used as a LemplaLe for furLher assembly language programmlng on Lhe LCL lC24 board. noLe LhaL
assembly language source flles use flle a flle name endlng wlLh .s !

Create the pro[ect

SLarL MLA8 luL from Lhe ueskLop Lhen sLarL Lhe new pro[ecL wlzard wlLh ro[ect->ro[ect W|zard. , Lhen cllck
nexL >

Step Cne: SelecL a devlce

choose IC24nI32G202 from Lhe pull down menu (be careful here Lo choose Lhe correcL devlce from
Lhls long llsL!), cllck nexL >

Step 1wo: SelecL a language LoolsulLe

choose M|croch|p C30 1oo|su|te (leave Lhe 1oolsulLe ConLenLs and LocaLlon defaulLs, as Lhey are
glven), cllck nexL >

noLe: we can use Lhe C30 1oolsulLe Lo !""#$%&# programs because lL lncludes Lhe assembler. 1he assembler ls also avallable separaLely and
ls known as Lhe ASM30 1oo|su|te. lor Lhe purposes of CCM LnC 2u4, slmply use Lhe C30 1oolsulLe.

Step 1hree: CreaLe a new pro[ecL

browse Lo a dlrecLory for your pro[ecL and enLer a name for your pro[ecL, cllck nexL >

Step Iour: Add exlsLlng flles Lo your pro[ecL:

selecL Lhe name of your source flle (flle exLenslon musL be .s)
use Add>> Lo puL lL lnLo Lhe llsL wlndow
Lhen cllck on Lhe A beslde Lhe name of Lhe flle 3 Llmes (A becomes C) whlch causes your flle Lo be
copled Lo your pro[ecL dlrecLory (lf lLs noL already Lhere!).

selecL Lhe name of Lhe llnker scrlpL flle (use p|c24_code_examp|es\||b\|kr\p24nI32G202_boot|dr.g|d)
use Add>> Lo puL lL lnLo Lhe llsL wlndow
Lhen cllck on Lhe A beslde Lhe name of Lhe flle (A becomes U) whlch lnserLs a relaLlve paLhname Lo
Lhe llnker scrlpL flle.

cllck nexL >

Cllck llnlsh Lo exlL Lhe Summary.
Dr. D. Capson Comp Eng 2DP4 19/01/12

4



V|ew your pro[ect:

1o see your pro[ecL flles and workspace, use V|ew->ro[ect. 1he pro[ecL wlndow opens LhaL shows a dlrecLory
sLrucLure LhaL conLalns your source flle and Lhe llnker scrlpL flle, added ln SLep lour above. 1o sLarL edlLlng
your source flle, double cllck on Lhe source flle name ln Lhe pro[ecL wlndow. uo nC1 edlL Lhe llnker scrlpL flle!

?ou should see a dlsplay slmllar Lo LhaL shown ln llgure 3 below. 1hls example shows an assembler source flle
(counter.s) and Lhe llnker scrlpL flle (p24nI32G202_boot|dr.g|d) added Lo a pro[ecL named counLer_asm".





I|gure 3 - 1he pro[ect w|ndow show|ng the f||es added to the pro[ect (|n th|s examp|e
the pro[ect name |s "counter_asm")


Dr. D. Capson Comp Eng 2DP4 19/01/12

5

8u||d your pro[ect:

8ulldlng" Lhe pro[ecL assembles Lhe program source flle and creaLes Lhe .hex flle used for booLloadlng. noLe
LhaL Lhe name of Lhe .hex flle LhaL ls creaLed ls Lhe same as Lhe pro[ecL name. Also noLe LhaL several addlLlonal
flles are generaLed ln Lhe folder conLalnlng your pro[ecL.

1o bulld your pro[ecL, use:

ro[ect->8u||d A|| (or Ctr| I10 or by cllcklng on Lhe dedlcaLed buLLon on Lhe ro[ecL Manager Loolbar).

An CuLpuL Wlndow wlll open and you should see a serles of ouLpuL messages as Lhe bulld process proceeds,
flnlshlng wlLh a BUILD SUCCEEDED message ln Lhe CuLpuL Wlndow.

?our .hex flle requlred for booLloadlng has been creaLed (verlfy Lhls by looklng ln Lhe pro[ecL folder).

See secLlon 3 of Lhls documenL for lnsLrucLlons on how Lo booLload Lhe .hex flle. 1hls wlll run your programs!





Notes:

llles can be added Lo a pro[ecL afLer Lhe pro[ecL ls creaLed by rlghL-cllcklng on Lhe folder name ln Lhe dlrecLory
sLrucLure of Lhe pro[ecL wlndow and selecLlng Add Files

llles can be removed from a pro[ecL afLer Lhe pro[ecL ls creaLed by rlghL-cllcklng on Lhe flle name and selecLlng
Remove ln Lhe pro[ecL wlndow.

1he pro[ecL flle name has exLenslon .mcp. 1he workspace flle name has exLenslon .mcw





What |s the d|st|nct|on between a ro[ect and a Workspace?

A !"#$%&' ls Lhe compleLe seL of lnformaLlon you need lncludlng all source flles, llnker scrlpL flles,
header flles (for C programs only), Lhe hex flle generaLed from bullds" and several oLher flles. A
(#")*!+&% ls Lhe currenL sLaLe of Lhe pro[ecL LhaL mlghL lnclude, for example, any open wlndows LhaL
have been used for vlewlng rogram Memory, llle 8eglsLers, eLc.


Dr. D. Capson Comp Eng 2DP4 19/01/12

6

2. Creat|ng an MLA8 ro[ect for C-|anguage programs

1o geL you sLarLed, Lhere are Lwo C-language source code examples avallable on Lhe course web slLe:

1. counter.c - Lhe 4-blL blnary counLer on Lhe lC24 LLus on orL 8
2. sw|tch_echo.c - Lhe swlLch echo program LhaL dlsplays Lhe swlLch paLLern on orL A on orL 8 LLus

uownload Lhese source flles and bulld a pro[ecL for each of Lhem uslng Lhe followlng lnsLrucLlons. 1hese flles
can be used as a LemplaLe for furLher C-language programmlng on Lhe LCL lC24 board. noLe LhaL C-language
source flles use flle a flle name endlng wlLh .c !


Create the pro[ect

SLarL MLA8 luL from Lhe ueskLop Lhen sLarL Lhe new pro[ecL wlzard wlLh ro[ect->ro[ect W|zard. , Lhen cllck
nexL >

Step Cne: SelecL a devlce

choose lC24P!32C202 from Lhe pull down menu (be careful here Lo choose Lhe correcL devlce from
Lhls long llsL!), cllck nexL >

Step 1wo: SelecL a language LoolsulLe

choose Lhe Microchip C30 Toolsuite (leave Lhe 1oolsulLe ConLenLs and LocaLlon defaulLs, as Lhey
are glven), cllck nexL >

Step 1hree: CreaLe a new pro[ecL, or reconflgure Lhe acLlve pro[ecL

browse Lo a dlrecLory for your pro[ecL and enLer a name for your pro[ecL, cllck nexL >

Step Iour: Add exlsLlng flles Lo your pro[ecL:

selecL Lhe name of your source flle ( flle exLenslon musL be .c)
use Add>> Lo puL lL lnLo Lhe llsL wlndow
Lhen cllck on Lhe A beslde Lhe name of Lhe flle 3 Llmes (A becomes C) whlch causes your flle Lo be
copled Lo your pro[ecL dlrecLory (lf lLs noL already Lhere!).

selecL Lhe name of Lhe llnker scrlpL flle (use p|c24_code_examp|es\||b\|kr\p24nI32G202_boot|dr.g|d)
use Add>> Lo puL lL lnLo Lhe llsL wlndow
Lhen cllck on Lhe A beslde Lhe name of Lhe flle (A becomes U) whlch lnserLs a relaLlve paLhname Lo
Lhe llnker scrlpL flle.

cllck nexL >

Cllck llnlsh Lo exlL Lhe Summary
Dr. D. Capson Comp Eng 2DP4 19/01/12

7
V|ew your pro[ect

1o see your pro[ecL flles and workspace, use V|ew->ro[ect. 1he pro[ecL wlndow opens LhaL shows a dlrecLory
sLrucLure LhaL conLalns your source flle and Lhe llnker scrlpL flle, added ln SLep lour above. 1o sLarL edlLlng
your source flle, double cllck on Lhe source flle name ln Lhe pro[ecL wlndow.


Add C-|anguage ||brary f||es as needed to your pro[ect

1he mlnlmum seL Lo be added ls as follows:

8lghL-cllck on Lhe Source I||es folder name ln Lhe pro[ecL wlndow. SelecL Add Files.

8rowse Lo p|c24_code_examp|es\||b\common.

Choose all of Lhe followlng flles (Lhey can be selecLed slmulLaneously) Lo add Lo Lhe Source I||es folder:

p|c24_c|ockfreq.c p|c24_ser|a|.c p|c24_uart.c p|c24_ut||.c

At the bottom of the Add Files to Project window, click the button named:

User: File(s) were created especially for this project, use relative path.

Check the box: Remember this Setting.

Your Project window should now look as shown in Figure 4. 1hls example shows a C source flle
(counter.c), Lhe llnker scrlpL flle (p24nI32G202_boot|dr.g|d), and Lhe four C llbrary flles added Lo a pro[ecL
named LesL1". As you require use of more of the C-libraries later in the course, you can add them to
your projects.




I|gure 4 - 1he pro[ect w|ndow show|ng the f||es added to the pro[ect
Dr. D. Capson Comp Eng 2DP4 19/01/12

8


Set the Inc|ude Search ath

ro[ect->8u||d Cpt|ons->ro[ect , Lhen under ulrecLorles Lab, choose lnclude Search aLh from Lhe pull-down
llsL. Cllck Lhe New buLLon and Lype Lhe followlng relaLlve paLh Lo Lhe include folder:

..\p|c24_code_examp|es\||b\|nc|ude

Cllck Lhe Apply buLLon and Lhen Ck.

noLlce LhaL Lhls ls a relaLlve paLhname LhaL assumes LhaL your pro[ecL folder ls on Lhe SAML level of Lhe
dlrecLory sLrucLure as your copy of Lhe p|c24_code_examp|es (and obvlously, on Lhe same drlve).



8u||d your pro[ect

ro[ect->8u||d A|| (or Ctr| I10 or by cllcklng on Lhe dedlcaLed buLLon on Lhe ro[ecL Manager Loolbar).

8ulldlng" Lhe pro[ecL complles Lhe source flle and creaLes Lhe .hex flle used for booLloadlng. noLe LhaL Lhe
name of Lhe .hex flle LhaL ls creaLed ls Lhe same as Lhe pro[ecL name. Also noLe LhaL several addlLlonal flles are
generaLed ln Lhe folder conLalnlng your pro[ecL.

An CuLpuL Wlndow wlll open and you should see a serles of ouLpuL messages as Lhe bulld process proceeds,
flnlshlng wlLh a BUILD SUCCEEDED message ln Lhe CuLpuL Wlndow.

?our .hex flle requlred for booLloadlng has been creaLed (verlfy Lhls by looklng ln Lhe pro[ecL folder).

See secLlon 3 of Lhls documenL for lnsLrucLlons on how Lo booLload Lhe .hex flle. 1hls wlll sLarL Lhe execuLlon of
your program code.


Dr. D. Capson Comp Eng 2DP4 19/01/12

9

3. 8oot|oad|ng code to the McMaster LCL IC24 hardware modu|e

All programs are loaded lnLo Lhe lC24 board ln Lhe form of .hex flles. 1hese .hex flles are generaLed by Lhe
Assembler and Lhe C-compller based on source code LhaL you wrlLe and bulld uslng an MLA8 pro[ecL as
descrlbed ln Lhe prevlous 2 SecLlons of Lhls documenL.

lug a lC24 hardware module lnLo a uS8 porL (a uS8 Lype A exLenslon cable can be used lf needed).

8un (,-.##'/0"1%2% (found ln Lhe b|n folder) Lo sLarL Lhe lC24 8ully 8ooLloader.

AbouL half way down on Lhe lefL slde, Lhere are 2 pull-down llsLs. SelecL Lhe CCM porL wlLh Lhe hlghesL number
from Lhe lefL pull-down llsL. Make sure Lhe 8aud raLe ls chosen Lo be 37600 ln Lhe rlghL pull-down llsL. Check
Lhe CpenCom box [usL Lo Lhe rlghL of Lhe 2 pull-down llsLs.

8elow Lhe pull-down llsLs, cllck on Lhe nexI||e box and browse Lo your pro[ecL flle and selecL your pro[ecL's .hex
flle (recall lL wlll have Lhe same name as your pro[ecL).


34!#"'+-' 6 "%+0 &+"%78//9:

ress and "%/%+*% Lhe red reseL buLLon on Lhe lC24 board. ?ou now have approxlmaLely 2 seconds Lo cllck
on Lhe rogram buLLon locaLed lmmedlaLely below Lhe nexI||e box. 1hls downloads Lhe program code
conLalned ln your .hex Lo Lhe flash program memory on Lhe lC24P!32C202 mlcroconLroller.


lf Lhe booLload ls successful, you should see a serles of messages ln Lhe (,-.##'/0"1%2% wlndow flnlshlng wlLh:

Done.
Completed in 00:00:05.549977s.

our program |s now runn|ng on the IC24!

CLherwlse, lf you geL a message ln Lhe (,-.##'/0"1%2% wlndow slmllar Lo:

Reading Target Device ID
Exception during serial port read: The operation has timed out.
Unable to connect to device, giving up.

Lhen Lhe booLload has falled. 8evlew Lhe lnsLrucLlons above.

1he McMasLer LCL lC24 boards are sold wlLh booLloader code already programmed. Powever, lf for any
reason Lhe booLloader has become corrupLed or ls mlsslng, lL wlll need Lo be reprogrammed uslng Lhe
Microchip PICkit 2 programmer. 1hese are avallable ln Lhe lab aL each worksLaLlon (8oom l18/143) or ln
Lhe lLLL SLudenL 8ranch offlce (8oom l18/141). lnsLrucLlons Lo do Lhls are provlded ln Lhe documenL:

now_to_|oad_the_boot|oader.pdf

LhaL ls avallable on Lhe course web slLe.
Dr. D. Capson Comp Eng 2DP4 19/01/12

10



4. Creat|ng a new pro[ect by copy|ng an ex|st|ng pro[ect

Cnce you have creaLed a pro[ecL for elLher Assembly or C-language programmlng as descrlbed ln SecLlon 1 or 2
of Lhls documenL, a -%( pro[ecL can be creaLed easlly ln [usL Lwo sLeps:

Step 1: add Lhe name of Lhe new source flle Lo Lhe ro[ecL wlndow (and remove Lhe prevlous one!)

Step 2: 8e-save Lhe pro[ecL wlLh a new name uslng ro[ect->Save ro[ect As.

8emember LhaL Lhe name of Lhe .hex flle LhaL ls creaLed durlng a bulld" ls Lhe same as Lhe
pro[ecL name




S. 1ransferr|ng a pro[ect from your home mach|ne to the |ab


kemember: lL ls recommended LhaL you creaLe your pro[ecL folders on Lhe SAML level of Lhe dlrecLory
sLrucLure as your copy of Lhe p|c24_code_examp|es and on Lhe same drlve.

1hls allows for slmpllclLy ln creaLlng relaLlve paLh names Lo enable MLA8 luL Lo flnd requlred flles when
bulldlng your pro[ecLs. 1hls wlll also allow you Lo easlly copy your enLlre pro[ecL sLrucLure and brlng lL Lo Lhe lab
machlnes. lor Lhe examples shown ln llgure 1 and llgure 2, lf you copy Lhe folder COMPENG2DP4 onLo a
uS8 flash drlve, lL can be saved onLo Lhe lab machlnes and all your work comes wlLh you.


1he p|c24_code_examp|es folder should be downloaded from www.reesemicro.com Lo ensure LhaL you
have Lhe laLesL updaLes. 1hls folder conLalns all of Lhe LexLbook code examples, llnker scrlpL flles, lnclude flles,
C llbrary flles and Lhe booLloader sofLware.


1he opLlons for Lransferrlng your work from a home C Lo Lhe lab are as follows:

1. Copy Lhe enLlre p|c24_code_examp|es sLrucLure and your pro[ecL folders onLo a uS8 flash memory key.
8rlng Lhe flash memory drlve Lo use ln Lhe lab machlnes.

2. use your own lapLop and brlng lL Lo Lhe lab. noLe LhaL you wlll need Lo brlng a uS8 type A exLenslon
cable ln order Lo place Lhe lC24 module onLo Lhe moLherboard ln Lhe lab.

3. use a uS8 flash memory drlve Lo brlng your source flles and sLarL a new pro[ecL on Lhe lab machlnes.


kemember: Lach person should always brlng Lhelr own lC24 hardware module Lo Lhe lab!

You might also like