Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

' THIS IS FOR FUNCTION 2 ' * WE ARE USING CODE WARRIOR IDE HENCE WHY THERE ARE DIFFERENT FILES * In this exercise, you

'THIS IS FOR FUNCTION 2'

*WE ARE USING CODE WARRIOR IDE HENCE WHY THERE ARE DIFFERENT FILES*

In this exercise, you will write two functions. Each function will check bits and control bits on the microprocessor trainer. 1. The first function will use traditional C bit field logic instructions to read and control I/O bits 2. The second function will use modern C bit field structure to read and control I/O bits. The completed project will include header (.h) files you create and add to the program. You will define your own I/O ports in this program, so you will need to remove the MC9S12XEP100.h file from your project. o To do this: Expand Libs in the project explorer and then right-click on MC9S12XEP100.h to remove it from the project. o Then, in the main.c file, (once you remove the MC9S12XEP100.c file) comment out the #include derivative.h file. Otherwise you will get multiple definition errors.

You will write your main logic in the main.c file

Your completed project should have the following files added: o ports.h: file to hold your I/O port assignments o defs.h: file to hold your bit definitions o protos.h; file to hold your prototype definitions o Each of these files should comments, including a commented header and brief comment on file purpose

The program code will check the DIP switches at port B (address 0x01) and according to the state of the switches, will update the LEDs at port C (address 0x04) o You must come up with appropriate names for your port declarations Note: Be sure to make all bits of port C outputs by writing 0xff to its data direction register (address 0x06). Code operation example: if bit 0 of the switches is high, set bit 7 of the LEDs to a high without affecting other LEDS states. If bit 0 of the switches is low, write bit 7 of the LEDs low without affecting other LEDS states. Do the same for the remaining switches (bits 1-7). o The bits should track as follows: Bit 0 Switches => Bit 7 LEDs

Bit 1 Switches => Bit 6 LEDs Bit 2 Switches => Bit 5 LEDs Bit 3 Switches => Bit 4 LEDs Bit 4 Switches => Bit 3 LEDs

Both function versions are called from the endless loop inside of the main function, so it loops continuously, updating LEDs as you flip switches. 1. Write the first function version as instructed in Function Version 1: Traditional C Bit Fields, test it, if it works as instructed, demonstrate to Instructor or TA, then 2. Write the second function version as instructed in Function Version 2: Bitfield Structures, test it, then demonstrate to Instructor or TA. Note: do not delete the code from function version 1, just comment it out. When completed, you should be able to run either function version by commenting out the unnecessary code from the other function version. Both functions should produce identical logic I/O behavior. Test each function version by flipping each switch, and combinations of several switches, to see if the correct LED(s) light. A series of if else statements should be used. Do not use the if else- if statement since multiple switches may be on at the same time. Make sure you understand the previous sentence. Put your bit definitions in a file called defs.h. Put your port declarations in a file called ports.h. Put your function declarations in a file called protos.h For this assignment write your functions in the main.c file and you are required to write these functions below the main function.

Function Version 2: Modern C Bit Fields (bit fields wrapped in a Structure) Do not delete but comment out the unnecessary parts of previous program code. In your defs.h file, define a structure template with fields for all eight bits of a character-sized port. Give each field a generic name such as BIT_0, BIT_1, BIT_2, etc or some similar name. Use a typedef statement to define a variable type for the structure Then use the variable type to Define variables for the Port switches and the Port LEDs Update your other files to reflect the changes/additions for this Version 2 For Function Version 2: Use a similar if - else structure for checking and setting bits. You must use your defined structure variables and structure fields with the dot operator.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago