Lab Exercise 15: Arrays of Structures
Objective
This lab introduces you to the syntax used to work with arrays of structures. For this exercise, we have defined a structure to hold the real and imaginary parts of a complex number. You will then need to modify the real and imaginary parts of each element of an array of complex numbers.
Software Tools
Tool | About | Installers |
Installation
Instructions |
||
---|---|---|---|---|---|
Windows | Linux | Mac OSX | |||
MPLAB® X
Integrated Development Environment |
| | | | |
MPLAB® XC16
C Compiler |
| | | | |
Exercise Files
File | Download |
Installation
Instructions |
||
---|---|---|---|---|
Windows | Linux | Mac OSX | ||
Project and Source Files
|
| | | |
Procedure
1
Open the Project
Start MPLAB® X IDE, then click on the Open Project
Navigate to the folder where you saved the exercise files for this class.
Click on the Lab15.X folder.
Select Open Project
3
Edit Source File
STEP 1:
Multiply the real (re) part of each array element by 10. (HINT: Use *=)
STEP 2:
Multiply the imaginary (im) part of each array element by 5 (HINT: Use *=)

4
Debug Project
Once you finish writing the code:
Click on the Debug Project
Click on the Continue

Click on the Halt

Results
5
End Debug Session
End the Simulation Session by clicking the Finish Debugger Session
Clear out the UART 1 Output window (Ctrl + L)
Close the Project.
Conclusions
- Arrays of structures allow groups of related structures to be referenced by a common name.
- Individual structures may be referenced by the array index.
- Individual structure members may be referenced by the dot notation, in conjunction with the array name and index.