0% found this document useful (0 votes)
26 views40 pages

MicroControllers & Embedded Systems Lab Manual

The document is a lab manual for Microcontrollers and Embedded Systems (BCO601) prepared for BE-VI semester students at Rajarajeswari College of Engineering. It provides an introduction to embedded systems, focusing on ARM microcontrollers, their features, and programming using Keil MDK. The manual includes a syllabus, experiments, and assessment details for the course, emphasizing practical applications and interfacing with various components.

Uploaded by

knpavithra.95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views40 pages

MicroControllers & Embedded Systems Lab Manual

The document is a lab manual for Microcontrollers and Embedded Systems (BCO601) prepared for BE-VI semester students at Rajarajeswari College of Engineering. It provides an introduction to embedded systems, focusing on ARM microcontrollers, their features, and programming using Keil MDK. The manual includes a syllabus, experiments, and assessment details for the course, emphasizing practical applications and interfacing with various components.

Uploaded by

knpavithra.95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

;l/

MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

RAJARAJESWARICOLLEGEOFENGINEERING
No:14,RamohalliCross,Kumbalgodu,MysoreRoad,Bangalore-560074

AMANUALFOR

MICROCONTROLLERS&EMBEDDEDSYSTEM
(BCO601)

BE–VISemester

PREPAREDBY

Mrs.SUPRAJAM
AssistantProfessor
Dept.ofComputerScience&EngineeringR.R.C.
E,Bangalore

DEPARTMENTOFCOMPUTERSCIENCE&ENGINEERING
[IoT,CybersecurityincludingBlockchainTechnology]
2024-25

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:1


;l/

MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Introduction:
Anembeddedsystemisanelectronic/electromechanicalsystemdesignedtoperformaspecificfunctionan
disacombinationofbothhardwareandfirmware(software).Anembeddedsystemcombinesmechanical,
electrical,andchemicalcomponentsalongwithacomputer,hiddeninside,toperformasinglededicatedpu
rpose.
Therearemorecomputersonthisplanetthantherearepeople,andmostofthesecomputersaresingle-
chipmicrocontrollersthatarethebrainsofanembeddedsystem.Embeddedsystemsareaubiquitouscomp
onentofoureverydaylives.Weinteractwithhundredsoftinycomputerseverydaythatareembeddedintoo
urhouses,ourcars,ourbridges,ourtoys,andourwork.Asourworldhasbecomemorecomplex,sohavethec
apabilitiesofthemicrocontrollersembeddedintoourdevices.Therefore,theworldneedsatrainedworkfor
cetodevelopandmanageproductsbasedonembeddedmicrocontrollers.

Ageneral-purposecomputingsystemisacombinationofgenerichardwareandgeneral-
purposeoperatingsystemforexecutingavarietyofapplication,whereasanembeddedsystemisacombinat
ionsystemisacombinationofspecialpurposehardwareandembeddedOS/firmwareforexecutingaspecif
icsetofapplications.

TheARMmicrocontrollerstandsforAdvanceRiskMachine;itisoneoftheextensiveandmostlicensedpro
cessorcoresintheworld.ThefirstARMprocessorwasdevelopedintheyear1978byCambridgeUniversity
,andthefirstARMRISCprocessorwasproducedbytheAcornGroupofComputersintheyear1985.
Theseprocessorsarespecificallyusedinportabledeviceslikedigitalcameras,mobilephones,homenetw
orkingmodulesandwirelesscommunicationtechnologiesandotherembeddedsystemsduetothebenefits
,suchaslowpowerconsumption,reasonableperformance,etc.ThisarticlegivesanoverviewofARMarchi
tecturewitheachmodule’sprincipleofworking.

KeilMDKisthecompletesoftwaredevelopmentenvironmentforawiderangeofARMCortex-
Mbasedmicrocontrollerdevices.MDKincludestheµVisionIDEanddebugger,ArmC/C++compiler,an
dessentialmiddlewarecomponents.Itsupportsallsiliconvendorswithmorethan6,000devicesandiseasyt
olearnanduser.

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:2


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

FeaturesofARMProcessor
AIM:TostudyofARMprocessorsystemanddescribethefeaturesofarchitecture

FeaturesofARMDEVELOPMENTKITProcessor:

• 16-bit/32-bitARM7TDMI-SmicrocontrollerinatinyLQFP64package.8kBto40kBofon-
chipstaticRAMand32kBto512kBofon-chipflashmemory.128-
bitwideinterface/acceleratorenableshigh-speed60MHzoperation.InSystem/In-
ApplicationProgramming(ISP/IAP)viaon-chipbootloadersoftware.
• Singleflashsector/fullchiperasein400msandprogrammingof256bytesin1ms.USB2.0
Full-
speedcompliantdevicecontrollerwith2kBofendpointRAM.TheLPC2146/48provides8kB
ofon-chipRAMaccessibletoUSBbyDMA.
• Oneortwo(LPC2141/42vs.LPC2144/46/48)10-
bitADCsprovideatotalof6/14analoginputs,withconversiontimesaslowas2.44µsperchannel
.Single10-bitDACprovidesvariableanalogoutput(LPC2142/44/46/48only).Two32-
bittimers/externaleventcounters(withfourcaptureandfourcomparechannelseach),PWMun
it(sixoutputs)andwatchdog.
• LowpowerReal-
TimeClock(RTC)withindependentpowerand32kHzclockinput.Multipleserialinterfacesincl
udingtwoUARTs(16C550),twoFastI2Cbus(400kbit/s),SPIandSSPwithbufferingandvariab
ledatalengthcapabilities.
• VectoredInterruptController(VIC)withconfigurableprioritiesandvectoraddresses.Upto45
of
5VtolerantfastgeneralpurposeI/OpinsinatinyLQFP64package.Upto21externalsinterruptp
insavailable.
• 60MHzmaximumCPUclockavailablefromprogrammableon-
chipPLLwithsettlingtimeof100µs.On-
chipintegratedoscillatoroperateswithanexternalcrystalfrom1MHzto25MHzPowersaving
modesincludeIdleandPowerdown.
• Individualenable/disableofperipheralfunctionsaswellasperipheralclockscalingforaddition
al.Poweroptimization.Processorwake-upfromPower-
downmodeviaexternalinterruptorBOD.SinglepowersupplychipwithPORandBODcircuits
:CPUoperatingvoltagerangeof3.0Vto3.6V(3.3V±10%)with5VtolerantI/Opads.

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:3


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

GeneralBlockDiagram:

PowerSupply:
• TheexternalpowercanbeACorDC,withavoltagebetween(9V/12V,1Aoutput)at230VAC
input.
TheARMboardproduces+5VusinganLM7805voltageregulator,whichprovidessupplytothe
peripherals.
• LM1117Fixed+3.3Vpositiveregulatorusedforprocessor&processorrelatedperip
herals.
FlashProgrammingUtility
• NXP(Philips)NXPSemiconductorsproducearangeofMicrocontrollersthatfeaturebotho
n-chipFlashmemoryandtheabilitytobereprogrammedusingIn
SystemProgrammingtechnology.
PINDIAGRAM
• On-boardPeripherals:
• 8-Nos.ofPointLED’s(DigitalOutputs)
• 8-Nos.ofDigitalInputs(slideswitch)
• 2LinesX16CharacterLCDDisplay

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:4


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

• I2CEnabled4DigitSeven-segmentdisplay
• 128x64GraphicalLCDDisplay
• 4X4Matrixkeypad
• StepperMotorInterface

• 2Nos.RelayInterface
• TwoUARTforserialportcommunicationthroughPC
• SerialEEPROM
• On-chipRealTimeClockwithbatterybackup
• PS/2Keyboardinterface(Optional)
• TemperatureSensor
• Buzzer(AlarmInterface)
• TrafficLightModule(Optional)

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:5


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

SYLLABUS

Microcontrollers&EmbeddedSystems Semester 6
CourseCode BCO601 CIEMarks 50
TeachingHours/Week(L:T:P:S) 3:0:2:0 SEEMarks 50
TotalHoursofPedagogy 40hoursTheory+8-10Labslots TotalMarks 100
Credits 04 ExamHours 3
Examinationnature(SEE) Theory/practical
Sl.NO Experiments
1 Developaprogramtomultiplytwo16bitbinarynumbers.

2
Writeaprogramtofindthesumoffirst10integernumbers.
3
Writeaprogramtofindfactorialofanumber.
4
Writeaprogramtoaddanarrayof16bitnumbersandstorethe32bitresultininternalRAM
5
Writeaprogramtofindthesquareofanumber(1to10)usinglook-uptable.
6
Writeaprogramtofindthelargest/smallestnumberinanarrayof32numbers.
7
Display“HelloWorld”messageusingInternalUART.
8
InterfaceaSteppermotorandrotateitinclockwiseandanti-clockwisedirection
9 DisplaytheHexdigits0toFona7-segmentLEDinterface,withanappropriatedelayin
between
10 Interfacea4x4keyboardanddisplaythekeycodeonanLCD.

Courseoutcomes(CourseSkillSet):
Attheendofthecourse,thestudentwillbeableto:

● ExplainthearchitecturalfeaturesandinstructionsofARMmicrocontroller

● ApplytheknowledgegainedforProgrammingARMfordifferentapplications.

● DemonstrateInterfacingofexternaldevicesandI/OwithARMmicrocontroller.

● Interpretthebasichardwarecomponentsandtheirselectionmethodbasedonthecharacteristicsa
ndattributesofanembeddedsystem.

● Developthehardware/softwareco-designandfirmwaredesignapproaches.

AssessmentDetails(bothCIEandSEE)
TheweightageofContinuousInternalEvaluation(CIE)is50%andforSemesterEndExam(SEE)is50%.Theminimu
mpassingmarkfortheCIEis40%ofthemaximummarks(20marksoutof50)andfortheSEEminimumpassingmarkis
35%ofthemaximummarks(18outof50marks).Astudentshallbedeemedtohavesatisfiedtheacademicrequirement
sandearnedthecreditsallottedtoeachsubject/courseifthestudentsecuresaminimumof40%(40marksoutof100)int
hesumtotaloftheCIE(ContinuousInternalEvaluation)andSEE(SemesterEndExamination)takentogether.

CIEforthetheorycomponentoftheIPCC(maximummarks50)
IPCCmeanspracticalportionintegratedwiththetheoryofthecourse.
Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:6
MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

● CIEmarksforthetheorycomponentare25marksandthatforthepracticalcomponentis25marks.
● 25marksforthetheorycomponentaresplitinto15marksfortwoInternalAssessmentTests(Two
Tests,eachof15Markswith01-
hourduration,aretobeconducted)and10marksforotherassessmentmethods mentionedin22OB4.2.Thefirsttestattheend
of40-50%coverageofthesyllabusandthesecondtestaftercovering85-90%ofthesyllabus.
Scaled-
downmarksofthesumoftwotestsandotherassessmentmethodswillbeCIEmarksforthetheorycomponentofIPCC(thatisfor25
marks).
Thestudenthastosecure40%of25markstoqualifyintheCIEofthetheorycomponentofIPCC.

CIEforthepracticalcomponentoftheIPCC
● 15marksfortheconductionoftheexperimentandpreparationoflaboratoryrecord,and10marksforthetesttobe
conductedafterthecompletionofallthelaboratorysessions.
● Oncompletionofeveryexperiment/programinthelaboratory,thestudentsshallbeevaluatedincludingviva-
voceandmarksshallbeawardedonthesameday.
● TheCIEmarksawardedinthecaseofthePracticalcomponentshallbebasedonthecontinuousevaluationofthelab
oratoryreport.Eachexperimentreportcanbeevaluatedfor10marks.Marksofallexperiments’write-
upsareaddedandscaleddownto15marks.
● Thelaboratorytest(duration02/03hours)aftercompletionofalltheexperimentsshallbeconductedfor50mark
sandscaleddownto10marks.
● Scaled-downmarksofwrite-
upevaluationsandtestsaddedwillbeCIEmarksforthelaboratorycomponentofIPCCfor25marks.
● Thestudenthastosecure40%of25markstoqualifyintheCIEofthepracticalcomponentoftheIPCC.
SEEforIPCC
TheorySEEwillbeconductedbyUniversityasperthescheduledtimetable,withcommonquestionpapersforthecour
se(duration03hours)
1. Thequestionpaperwillhavetenquestions.Eachquestionissetfor20marks.
2. Therewillbe2questionsfromeachmodule.Eachofthetwoquestionsunderamodule(witha maximum
of3sub-questions),shouldhaveamixoftopicsunderthatmodule.
3. Thestudentshavetoanswer5fullquestions,selectingonefullquestionfromeachmodule.
4. Marksscoredbythestudentshallbeproportionallyscaleddownto50Marks
ThetheoryportionoftheIPCCshallbeforbothCIEandSEE,whereasthepracticalportionwillhaveaCIEcomp
onentonly.QuestionsmentionedintheSEEpapermayincludequestionsfromthe
practicalcomponent.

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:7


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

CONTENTS

1. INTRODUCTION 1
2. LABORATORYSESSION1–KEILINTRODUCTION 5
Experiments PageNo
SlNo.
PARTA
Writeaprogramtomultiplytwo16bitbinarynumbers. 11
1.
Writeaprogramtofindthesumoffirst10integernumbers. 13
2.
Writeaprogramtofindfactorialofanumber. 15
3.
Writeaprogramtoaddanarrayof16bitnumbersandstorethe32bitr 17
4.
esultininternalRAM
Writeaprogramtofindthesquareofanumber(1to10)usinglook- 19
5.
uptable.
Writeaprogramtofindthelargest/smallestnumberinanarrayof32 21
6.
numbers
PARTB

Display“HelloWorld”messageusingInternalUART. 28
7.
InterfaceaSteppermotorandrotateitinclockwiseandanti- 30
8.
clockwisedirection.
Interfacea4x4keyboardanddisplaythekeycodeonanLCD. 31
9.
DisplaytheHexdigits0toFona7- 33
10.
segmentLEDinterface,withanappropriatedelayinbetween.

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:8


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

PART-A

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:9


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

KEILUVISION4IDEINSTALLATION:
InstallationofkeiluVision4asfollows.
1. GotoEXEfolderandthenuvision4.2intheCDandrunKeil4Arm.exefile.
2. Next
3. Clickontheoption“Iagreetoallthetermsof...”andthengiveNext
4. Next
5. Givenameandthemailid(itmightbeanymailid)andthenNext
6. ClickFinishtocompletetheinstallation.

PROJECTCREATIONINKEILUV4IDE:

7. CreateaprojectfolderbeforecreatingNEWproject.
8. OpenKeiluVision4IDEsoftwarebydoubleclickingon“KeilUvision4”icon.
9. Goto“Project”thento“NewuVisionProject”andsaveitwithanameint
herespectiveprojectfolder,alreadyyoucreated.
10. Selectthedeviceas“NXP”Inthat“LPC2148”thenpressOK
andthenpress“YES”buttontoadd“startup’s”file.
11. InstartupfilegotoConfigurationWizard.InConfigurationWizard
windowuncheckPLLSetupandcheckVPBDIVSetup.
12. Goto“File”Inthat“New”toopenaneditorwindow.Createyoursourcefil
eandusetheheaderfile“lpc21xx.h”inthesourcefileandsavethefile.Col
oursyntaxhighlightingwillbeenabledoncethefileissavedwithaextens
ionsuchas“.C“.
13. Rightclickon“SourceGroup1”andselecttheoption“AddExistingF
ilestoGroupSourceGroup1“addthe*.csourcefile(s)/.SAssemblyf
iletothegroup.
14. AfteraddingthesourcefileyoucanseethefileinProjectWindow.
15. RightclickonTarget1andselectoptionsforTarget
1. Thengotooption“Linker”

DeSelect“UseMemoryLayoutforTargetDialog”.Tocomeoutofthiswindowpress
OK.
16. Goto“Project”inthat“BuildTarget”forbuildingallsourcefilessucha
s“.C”,”.ASM”,“.h”,files,etc…Thiswillcreatethe
*.HEXfileifnowarnings&noErrors.CheckouttheBuildoutputwindow.

Dept.ofCSE[IC], R.R.C.E 2024-25 Page No:10


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program1

Writeaprogramtomultiplytwo16bitbinarynumbers.

Aim:Towriteaprogramtomultiplytwo16bitbinarynumbersusingARM7TDMI/LPC2148usinganevaluationboard/
simulatorandtherequiredsoftwaretool.

SourceCode

AREAMULTIPLY,CODE,READONLY

ENTRY ;MARKFIRSTINSTRUCTIONTOEXECUTESTART

MOVR1,#6400 ;STOREFIRSTNUMBERINR1
MOVR2,#3200 ;STORESECONDNUMBERINR2
MULR3,R1,R2 ;MULTIPLICATION

STOPBSTOP

END ;MARKENDOFFILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:11


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:12


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program2

Write aprogramtofindthesumoffirst10integernumbers.

Aim:Towriteaprogramtofindthesumoffirst10integernumbersusingARM7TDMI/LPC2148usinganevaluationb
oard/simulatorandtherequiredsoftwaretool.

SourceCode

AREASUM,CODE,READONLY

ENTRY

MOVR1,#10 ;LOAD10TOREGISTER

MOVR2,#0 ;EMPTYTHEREGISTERTOSTORERESULT

LOOP

ADDR2,R2,R1

;ADDTHECONTENTOFR1WITHRESULTATR2SUBSR1,#0X0

1 ;DECREMENTR1BY1

BNELOOP ;REPEATTILLR1GOES0

STOPBSTOP ;JUMPSBACKTOCCODE

END

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:13


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:14


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program3
Writeaprogramtofindfactorialofanumber.

Aim:TowriteaprogramtofindfactorialofanumberusingARM7TDMI/LPC2148usinganevaluationboard/simulat
orandtherequiredsoftwaretool.

SourceCode

AREAFACTORIAL,CODE,READONLY

ENTRY

;MARKFIRSTINSTRUCTIONTOEXE

CUTESTART

MOVR0,#4 ;STOREFACTORIALNUMBERINR0
MOVR1,R0 ;MOVETHESAMENUMBERINR1

FACT SUBSR1,R1,#1
;SUBTRA
CTIONCMPR1,#1
;COMPA
RISONBEQSTOP
MULR3,R0,R1; ;MULTIPLICATION
MOV R0,R3 ;RESULT
BNEFACT ;BRANCHTOTHELOOPIFNOTEQUAL
STOP

STOPBSTOP

END ;MARKENDOFFILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:15


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:16


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program4

Writeaprogramtoaddanarrayof16bitnumbersandstorethe32bitresultininternalRAM

Aim:Towriteaprogramtoaddanarrayof16bitnumbersandstorethe32bitresultininternalRAMusinganevaluationboar
d/simulatorandtherequiredsoftwaretool.

SourceCode

AREAADDITION,CODE,READONLY
ENTRY ;MARKFIRSTINSTRUCTIONTOEXECUTE

START

LOOP

MOVR5,#6 ;INTIALISECOUNTERTO6(I.E.N=6)
MOVR0,#0 ;INTIALISESUMTOZERO
LDRR1,=VALUE1 ;LOADSTHEADDRESSOFFISTVALUE
LDRR2,[R1],#2 ;WORDALIGNT0ARRAYELEMENT
LDRR3,MASK ;MASKTOGET16BIT
ANDR2,R2,R3 ;MASKMSB
ADDR0,R0,R2 ;ADDTHEELEMENTS
SUBSR5,R5,#1 ;DECREMENTCOUNTERCMPR5,#0
BNELOOP ;LOOKBACKTILLARRAYENDS
LDRR4,=RESULT ;LOADSTHEADDRESSOFRESULT
STRR0,[R4] ;STORESTHERESULTINR1

XSSBXSS

MASKDCD0X0000FFFF ;MASKMSB

VALUE1DCW 0X1111,0X2222,0X3333,0XAAAA,0XBBBB,0XCCCC

;ARRAYOF16BITNUMBERS(N=6)

AREADATA2,DATA,READWRITE ;TOSTORERESULTINGIVENADDRESS

RESULTDCD0X0

END ;MARKENDOFFILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:17


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:18


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program5
Write a program to find the square of a number(1to10) using look-uptable.

Aim: To write a program to find the square of a number(1to10) using lookup table. Using
ARM7TDMI/LPC2148 using an evaluation board/simulator and there quired software tool.

SourceCode

AREA SQUARE, CODE, READONLY


ENTRY ;MARKFIRSTINSTRUCTIONTOEXECUTE

START

LDR R0, = TABLE1 ;LOADSTARTADDRESSOFLOOKUPTABLE


LDR R1,= 3 ; LOAD NO WHOSE SQUARE IS TO BE FIND
MOVR1,R1,LSL#0X2 ;GENERATEADDRESSCORRESPONDINGTOSQUAREOFGIVENNO
ADDR0,R0,R1 ;LOADADDRESSOFELEMENTINLOOKUPTABLE
LDRR3, [R0] ;GETSQUAREOFGIVENNOINR3

STOPBSTOP

;LOOKUPTABLECONTAINSSQUARESOFNOSFROM0 TO 10 (IN HEX)

TABLE1 DCD 0X000 ;SQUAREOF 0=0


DCD 0X00000001 ;SQUAREOF
DCD 0X00000004 ;SQUAREOF 2=4
DCD 0X00000009 ;SQUAREOF 3=9
DCD 0X00000010 ;SQUAREOF4=16
DCD 0X00000019 ;SQUAREOF5=25
DCD 0X00000024 ;SQUAREOF6=36
DCD 0X00000031 ;SQUAREOF7=49
DCD 0X00000040 ;SQUAREOF8=64
DCD 0X00000051 ;SQUAREOF9=81
DCD 0X00000064 ;SQUARE OF 10=100

END ;MARKENDOFFILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:19


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:20


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Program 6
Write a program to find the largest/smallest number in an array of 32numbers.

Aim: To write a program to find the largest/smallest number in an array of 32 numbers usingARM7TDMI/LPC2148
using an evaluation board/simulator and the required software tool.

SourceCode

ARELARGEST,CODE,READONLY

ENTRY ;MARKFIRSTINSTRUCTIONTOEXECUTE

START
MOVR5,#6 ;INTIALISECOUNTERTO6(I.E.N=7)
LDRR1,=VALUE1 ;LOADSTHEADDRESSOFFIRSTVALUE
LDRR2,[R1],#4 ;WORDALIGNT0ARRAYELEMENT
LOOP
LDRR4,[R1],#4 ;WORDALIGNT0ARRAYELEMENT
CMP R2,R4 ;COMPARENUMBERS
BHILOOP1 ;IFTHEFIRSTNUMBERIS>THENGOTOLOOP1

MOVR2,R4 ;IFTHEFIRSTNUMBERIS<THENMOVCONTENTR4TOR2
LOOP1
SUBSR5,R5,#1 ;DECREMENTCOUNTER
CMP R5,#0 ;COMPARECOUNTERTO0
BNELOOP ;LOOPBACKTILLARRAYENDS

LDRR4,=RESULT ;LOADSTHEADDRESSOFRESULT
STR R2,[R4] ;STORESTHERESULTINR2

XSSBXSS ;ARRAYOF32BITNUMBERS(N=7)

VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999

AREA DATA2,DATA,READWRITE
;TOSTORERESULTINGIVENADD
RESS RESULT DCD 0X0

END ;MARKENDOFFILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:21


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result:

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:22


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

SmallestNumber
SourceCode

AREASMALLEST,CODE,READONLY

ENTRY ;MARKFIRSTINSTRUCTIONTOEXECUTE

START
MOVR5,#6 ;INTIALISECOUNTERTO6(I.E.N=7)
LDRR1,=VALUE1 ;LOADSTHEADDRESSOFFIRSTVALUE
LDRR2,[R1],#4 ;WORDALIGNT0ARRAYELEMENT
LOOP
LDRR4,[R1],#4 ;WORDALIGNT0ARRAYELEMENT
CMP R2,R4 ;COMPARENUMBERS
BLS LOOP1 ;IFTHEFIRSTNUMBERIS<THENGOTOLOOP1

MOVR2,R4 ;IFTHEFIRSTNUMBERIS>THENMOVCONTENTR4TOR2
LOOP1
SUBSR5,R5,#1 ;DECREMENTCOUNTER
CMP R5,#0 ;COMPARECOUNTERTO0
BNELOOP ;LOOPBACKTILLARRAYENDS

LDRR4,=RESULT ;LOADSTHEADDRESSOFRESULT
STR R2,[R4] ;STORESTHERESULTINR2

XSSBXSS ;ARRAYOF32BIT NUMBERS(N=7)

VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X8888888
DCD 0X99999999

AREA DATA2,DATA,READWRITE
;TOSTORERESULTINGIVE
NADDRESS RESULT DCD 0X0
END ;MARKENDOF FILE

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:23


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Result

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:24


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

PART-B

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:25


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

PROCEDURE:PROJECTCREATIONINKEILUV4IDE:
1. CreateaprojectfolderbeforecreatingNEWproject.
2. OpenKeiluVision4IDEsoftwarebydouble clickingon“KeilUvision4”icon.
3. Goto“Project”thento“NewuVisionProject”andsave it withaname intherespectiveproject
folder, already you created.
4. Select thedeviceas“NXP”Inthat “LPC2148”thenpressOK andthenpress “YES”buttontoadd
“startup.s” file.
5. InstartupfilegotoConfigurationWizard.InConfigurationWizardwindowuncheckPLLSetup
andcheckVPBDIVSetup.
6. Goto“File”Inthat“New”toopenaneditorwindow.Createyoursource fileand usetheheaderfile
“lpc21xx.h” inthesourcefileandsavethe file. Colorsyntaxhighlighting willbeenabledoncethefile is
saved with a extension such as “.C “.
7. Right clickon“SourceGroup1”andselecttheoption“Add ExistingFilestoGroupSourceGroup
1“add the *.C source file(s) to the group.
8. AfteraddingthesourcefileyoucanseethefileinProjectWindow.
9. Thengoto“Project”inthat“Translate”tocompiletheFile(s).CheckouttheBuild outputwindow.
10. RightclickonTarget1andselectoptionsforTargetTarget1. Thengotooption“Target”inthat
1. Xtal12.0MHz
2. Select“UseMicroLIB”.
3. SelectIROM1(starting0x0size0x80000).
4. Select IRAM1(starting0x40000000size0x8000).

1. Thengotooption “Output”
1. Select“CreateHexfile”.
2. Thengotooption“Linker”

Select“UseMemoryLayoutforTargetDialog”.TocomeoutofthiswindowpressOK.

11. Goto“Project”inthat “BuildTarget”forbuildingallsourcefilessuchas“.C”,”.ASM”,“.h”,files,


etc…This will create the *.HEX file if no warnings & no Errors. Check out the Build output
window.

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:26


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

FLASHMAGIC:

Options->Advancedoptions->HardwareConfig
Enabletheseoptionsonly
UseDTRandRTSto controlRST
andISPpinKeepRTSassertedwhileCOMportopen Press OK then do the
below settings

Step1. Communications:
1. Device: LPC2148
2. ComPort:COM1
3. BaudRate:9600
4. Interface:None(ISP)
5. Oscillator: 12MHz

Step2. ERASE:
1.Select“EraseBlocksUsed ByHexFile”.

Step3.Hexfile:

1.BrowseandselecttheHexfilewhichyouwanttodownload.

Step4. Options
1. Select“Verifyafter programming”.

Step5.Start:
2. ClickStarttodownloadthehexfiletothe controller.

Afterdownloadingthecodetheprogramstartsexecutinginthe hardware, thenremovethe


ISP jumper JP7.

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:27


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual
LabPrograms

7.Display “Hello World” message using Internal UART.

Sourcecode
#include<lpc214x.h>
voiduart_interrupt(void)irq;

unsignedchar temp;
unsignedcharrx_flag=0,tx_flag=0;

intmain(void)
{
PINSEL0=0X0000005; //selectTXD0andRXD0 lines
U0LCR=0X00000083; //enablebaudratedivisorloadingand
U0DLM=0X00; //selectthedataformat
U0DLL = 0x13; //selectbaudrate9600bps
U0LCR= 0X00000003;
U0IER=0X03; //selectTransmitandReceiveinterrupt

VICVectAddr0=(unsignedlong)uart_interrupt; //UART0 INTERRUPT


VICVectCntl0= 0x20|6; //AssigntheVICchanneluart-0tointerruptpriority0
VICIntEnable=0x00000040; //Enabletheuart-0interrupt

rx_flag=0x00;
tx_flag=0x00;

while(1)
{
while(rx_flag==0x00); //wait forreceiveflagtoset
rx_flag=0x00; //cleartheflag
while(tx_flag==0x00); //waitfortransmitflagtoset
tx_flag= 0x00; //cleartheflag
}
}

//Dothisforever
voiduart_interrupt(void)irq
{
temp= U0IIR;
temp=temp&0x06;

if(temp== 0x02)
{

tx_flag = 0xff;
VICVectAddr=0;
}

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:28


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

elseif(temp==0x04)
{
U0THR = U0RBR;
rx_flag = 0xff;
VICVectAddr=0;
}
}

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:29


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

8.Interface a stepper motor and rotate it in clockwise and anti-closewise


direction

Sourcecode

#include<LPC214X.h>v

oiddelay();

voiddelay()//DelayRoutine

inti,j;for(i=0;i<0xff;i++

)for(j=0;j<0x25;j++);

intmain()

{
IO0DIR=0x000F0000;//Portselectionwh

ile(1)

{//Anticlockwiserotation.

IO0PIN=0x00010000;//ForClkwisesend1,2,4,8insteadof8,4,2,1delay();

IO0PIN=0x00020000;

delay();IO0PIN=0x00040

000;

delay();IO0PIN=0x00080

000;

delay();

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:30


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

9. Display theHexdigits0toFona7Segmant LED interface,with an appropriate


delay in between.

SourceCode

#include<LPC214x.h>vo

iddelay()

unsignedinti,j;for(i=0;i<0xFF;i

++)

for(j=0;j<0xFF;j++);

voidmain()

unsignedintnumber=0x00;IO0DIR=0x0000007C;//

P0.2,3,4,5,6ASI/OPINS

IO0SET=0x0000007C;//SETALLI/OPINSTOHIGH

while(1)

IO0CLR=0x0000003C;//CLEARONLYDATAPINSNOTCONTROLPINIO0SET=IO0SET|(n

umber<<2);//SETP0.2TO0

delay();

delay();

while(IO0PIN&0x00008000);//IFP0.15ISPRESSEDwhile(!(IO0PIN&

0x00008000));//IFP0.15ISRELEASEDnumber++;//INCREMENTTHE

NUMBER

if(number>9)//NUMBERCROSSES9

number=0x00;//MAKENUMBERTO0

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:31


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:32


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

10.Interfacea4*4keyboardanddisplaythekeycodeonanLCD.

Sourcecode

#include<LPC214x.H>/*LPC214xdefinitions*/#include

"LCD.H"

voidlcd_command_write(unsignedcharcommand);voidl

cd_data_write(unsignedchardata);

#defineLCD_DATA_DIRIO0DIR#defi

neLCD_DATA_SETIO0SET#defineLC

D_DATA_CLRIO0CLR#defineLCD_C

TRL_DIRIO0DIR#defineLCD_CTRL_

SETIO0SET#defineLCD_CTRL_CLRI

O0CLR#defineLCDEN(1<<2)

#defineLCDRS(1<<3)

//scale31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,09,08,07,06,05,04,03,02,01,0
0

#defineLCD_DATA_MASK0x007F8000

/****************************************************************************F

unctionName:delay()

Description:

Input:

Output:void

********************************************************************************/voi

ddelay(unsignedintcount)

intj=0,i=0;for(j=0;j<count;j++)

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:33


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

for(i=0;i<120;i++);

/*********************************************************************************
***********

FunctionName:lcd_command_write()D

escription:

Input:

Output:Void

**********************************************************************************
***********/

voidlcd_command_write(unsignedcharcommand)

inta=0;

a=command|0xFFFFFF0F;IO0

CLR|=0x00003C00;a=a<<6;

IO0CLR=0x20400000;IO0SE

T=0x10000000;

IO0SET=(IO0SET|0x00003c00)&a;

delay(1000);

IO0CLR=0x10000000;

a=0x0;command=command<<

4;

a=command|0xFFFFFF0F;IO0

CLR|=0x00003C00;a=a<<6;

IO0CLR=0x20400000;

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:34


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

IO0SET=0x10000000;

IO0SET=(IO0SET|0x00003C00)&a;

delay(1000);

IO0CLR=0x10000000;

/*********************************************************************************
*************

FunctionName:lcd_data_write()Descrip

tion:

Input:

Output:Void

**********************************************************************************
***********/

voidlcd_data_write(unsignedchardata)

intb=0;

b=data|0xFFFFFF0F;IO0CLR|

=0x00003C00;b=b<<6;

IO0SET=0x10400000;

IO0SET=(IO0SET|0x00003C00)&b;

delay(1000);

IO0CLR=0x10000000;

b=0x0;data=data<<4;

b=data|0xFFFFFF0F;

IO0CLR|=0x00003C00;b=b<<

6;

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:35


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

IO0SET=0x10400000;

IO0SET=(IO0SET|0x00003C00)&b;

delay(1000);

IO0CLR=0x10000000;

/*********************************************************************************
*************

FunctionName:lcd_clear()Des

cription:

Input:

Output:Void

**********************************************************************************
***********/

voidlcd_clear(void)

lcd_command_write(0x01);

/*********************************************************************************
*************

FunctionName:lcd_gotoxy()D

escription:

Input:

Output:Void

**********************************************************************************
***********/

intlcd_gotoxy(unsignedcharx,unsignedchary)

unsignedcharretval=TRUE;if((

x>1)&&(y>15))

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:36


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

retval=FALSE;

else

if(x==0)lcd_command_write(0x80+y);elseif(x=

=1)lcd_command_write(0xC0+y);

returnretval;

/*********************************************************************************
*************

FunctionName:lcd_putchar()D

escription:

Input:

Output:Void

**********************************************************************************
***********/

voidlcd_putchar(unsignedcharc)

lcd_data_write(c);

/*********************************************************************************
*************

FunctionName:lcd_putstring()De

scription:

Input:

Output:Void

**********************************************************************************
***********/

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:37


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

voidlcd_putstring(char*string)

while(*string!='\0')

lcd_putchar(*string);strin

g++;

/*********************************************************************************
*************

FunctionName:lcd_putstring16()Descri

ption:

Input:

Output:Void

**********************************************************************************
***********/

voidlcd_putstring16(unsignedcharline,char*string)

unsignedcharlen=16;lcd_gotox

y(line,0);while(*string!='\0'&

&len--)

lcd_putchar(*string);strin

g++;

/*********************************************************************************
*************

FunctionName:init_lcd()

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:38


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

Description:

Input:

Output:Void

**********************************************************************************
***********/

voidinit_lcd(void)

{IO0DIR=0x30403C00

delay(100);

lcd_command_write(0x02);//cursorhomecommandlcd_command_write(0x01);/

/cleardisplaycommandlcd_command_write(0x28);//4-

bitmodeentrycommand(0x38for8bitmode)lcd_command_write(0x06);//entrym

odecommandlcd_command_write(0x0C);//displayoncursoroffcommand

//cmd(0xC0);delay(1000)

intmain(void)
{
init_lcd();

lcd_clear();lcd_putstring("Hello,laks")
;lcd_gotoxy(1,0);lcd_putstring("LPC
2148LCD");

while(1);

return0;
}

LCD.H
//LCDHEADERFILE//

#ifndef_LCD_H#

define_LCD_H

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:39


MICROCONTROLLERS & EMBEDDED SYSTEM Lab Manual

#defineTRUE1

#defineFALSE0#defin

eLINE10x80#defineLI

NE20xC0

#defineCONTROL_REG0x00

#defineDATA_REG0x01voidd

elay(unsignedintcount);voidinit

_lcd(void);

voidlcd_putstring(char*string);

voidlcd_putstring16(unsignedcharline,char*string);void

lcd_clear(void);

intlcd_gotoxy(unsignedcharx,unsignedchary);voidlcd

_putchar(unsignedcharc);

#endif

Dept.ofCSE[IC], R.R.C.E 2024-25 PageNo:40

You might also like