C programming

profileAyamen2345
Homework32.pdf

EECS 3100 Embedded Systems Homework #3

Instructions – General

 There are 5 questions on this assignment. Answer all for full credit. Questions or their subparts are not necessarily equally weighted.

 You may work in groups of two but you must formulate your own responses, answers or solutions for each question or problem. Formulating one answer or solution and copying from each other is not permissible.

 Provide rationale, explanation, trace of solution or reasoning for your answers where applicable. Simply and magically providing responses or answers for those questions or problems that require reasoning may not receive any

credit.

 Submission must be in hardcopy and delivered by the student in person. Use blank and letter size typing (printer) paper and in portrait layout.

 You may use handwriting or word processor or combination for your submission. However, it must be organized, legible and presentable.

 Write your full name, rocket ID and your group member’s name on the top right of the first page of your submission. For multiple sheets, staple them at the top left.

--------------------------------------------------------------------------------------------------

Instructions – Special

 You must use Keil/uVision to develop code for embedded applications.

 For programming questions, you will need to verify the correctness of your code using the Keil/uVision debugger. Accordingly, you are expected to capture snapshots (as screen captures) of relevant debug windows to demonstrate

the correctness of your code during execution. Annotate your screen captures to explain as needed, which must be

included in your submission.

 Capture and include in your submission the compiler/linker output window that shows that your code compiles and links without error or warnings for each programming question.

 Provide the source code in your submission with proper indentation, label use, commenting and layout for each programming question.

 For programming tasks that is not fully functional, provide a detailed explanation for what is functional.

Questions

For all questions, use the TM4C123GH6PMI microcontroller as the target to test and verify the port

initialization procedure in simulation mode. Please note that you will need to use the LaunchPadDLL.dll to

simulate various ports referred to in this homework for simulation. A second option for testing and verification

is to use the target debug (through Stellaris ICDI). This will not require any DLL file.

For electrical circuit schematics, you will need to clearly show the connections to relevant pins of the

TM4C123GH6PM microcontroller.

Create a separate void function, which does not have any arguments passed, for each port for initialization, and

name them as initPortA(), initPortB(), initPortC() and initPortD(). Call the init functions within the main()

function which should enter a forever/dead/endless loop upon completing the initialization and the other

functionality required.

You may use lab project #3 C template to implement the initialization procedure for each port as well other

functionality prescribed in each of the programming questions.

Page 2 of 3

Use the “Peripherals  System Viewer  GPIO  GPIOX” window in debugger to verify, demonstrate and

document the correctness of initialization routine for a given port. Capture the Port X register values in Port X

Window before and after initialization as well as after a write-access. Explain by annotating if the registers were

set correctly. Below screen capture shows an example of the Port F windows (on the far right) prior to and right

after initialization:

Page 3 of 3

1. Design the interface for a positive logic switch to TM4C123GXL Port A pin 7. Show formulas and

calculations for each circuit element. Draw the circuit schematics with components labelled with their names

and values. Write the C code as a function to initialize the port for interfacing the switch. Write a function

to read the data value of Port A pin 7. Comment your code to explain each initialization step clearly.

2. Design the interface for a negative logic switch to Port B pin 0. Show formulas and calculations for each

circuit element. Draw the circuit schematics for each case with components labelled with their names and

values. Write the C code as a function to initialize the port for interfacing the switch. Write a function to

read the data value of Port B pin 0. Comment your code to explain each initialization step clearly.

3. Design the interface for a positive-logic LED to Port C pin 6 of TM4C123GXL. The LED parameters

(forward bias operating point) are 1.1 V and 0.9mA. Assume the microcontroller output voltage VOH is 3.2V.

Show all formulas and calculations. Draw the circuit schematics with all components labeled with their

names and values. Write the C code as a function to initialize the port for interfacing the LED. Write a

function to write the data value of 1 to Port C pin 6. Comment your code to explain each initialization step

clearly.

4. Design the interface for a negative-logic LED to Port D pin 4 of TM4C123GXL. The LED parameters

(forward bias operating point) are 1.9V and 9mA. Assume the microcontroller output voltage VOH is 3.3V.

Show all formulas and calculations. Draw the circuit schematics with all components labeled with their

names and values. Write the C code to initialize the port for interfacing the LED. Write a function to write

the data value of 1 to Port C pin 4. Comment your code to explain each initialization step clearly.

5. Write C code that initializes TM4C Port A, so pins 5, 4 and 3 are output. Comment your code to explain

each initialization step clearly. Make the initialization friendly. Write a C function that takes a parameter

(valued in the range 0 to 7 and thus emulating a 3-bit value) and writes to these three pins. Use bit-specific

addressing for the output. Testing this function will require you to write a separate driver function or code

fragment.