2. Number Systems and printf

2.1. Purpose

This activity is intended to provide a hands-on demonstration of number systems as used by a processing platform. This activity also serves to give an introduction to printing text and variable values from the microcontroller to the serial terminal; a skill useful in debugging systems throughout the course.

2.2. Hardware and Tools

  • None

OR

  • MSP-EXP432P401R Launchpad Development Board, OR

  • TI-RSLK Robotic Car

2.3. Description

This activity is composed of two parts:

  1. Programming tasks towards understanding of how numbers are handled by the microcontroller and how to use printf() statements in C.

  2. A set of number conversion tasks given on Gradescope.

2.4. Instructions

You have two options for completing this Activity:

  1. [Preferred] Perform all steps within CCS; which will require being connected to a Launchpad Board or RSLK, or

  2. Perform all steps within an online (or local) C IDE/compiler. This will not require hardware but will of course be a different environment than CCS.

2.4.1. CCS Option

  1. Download the CCS project from here: activity_numsys.zip, and import into CCS. For instructions on how to do so, see 3. Test Project.

  2. Once imported, open the main.c file and read the comments and code within the file thoroughly. When done reading, connect either the RSLK or the Launchpad Board to your computer and start a serial terminal connection.

  3. Verification of Correct Project Operation:

    1. Compile the current project by pressing on the “hammer” icon, hammer, on the top toolbar, or by selecting Project → Build Project. No errors should result from this; if there are, ask for some help!

    2. Load the project onto the MSP432 (the microcontroller on the RSLK or Launchpad Board) by pressing the “debug” icon, bug, on the top toolbar (green beetle) or by selecting Run → Debug.

    3. This should bring up the Debug Perspective, perspectives.

    4. Run the code by clicking the “Resume” button, run, or by selecting Run → Resume.

    5. This should cause output to be generated on the terminal window. Make sure this is the case.

  4. Continue the activity with the Shared Instructions.

2.4.2. Online Option

  1. Download the template code from here: Activity-NumberSystems.c. Open the file, copy the contents of the file and paste it into an online C IDE/compiler. Three examples of these are given below; however, there are many to choose from if you search “online c compiler”.

  2. Verification of Correct Project Operation: Test the online compiler and the pasted code by telling the compiler to compile and run the code. This is typically done by clicking a “Run” or “Execute” button. A simplistic output should be generated in the “Output” or “Result” panes. If an error is reported, ensure that the code was pasted properly and try again.

  3. Continue the activity with the Shared Instructions.

2.4.3. Shared Instructions

  1. Once set up, read the comments and code within the template file thoroughly.

  2. Modify the comments at the top of the code to give your name and RIN.

  3. Modify the printf() statement such that the value of a is printed in both hexadecimal and decimal. See printf for how to do that. Compile and run to verify correct.

  4. Modify the value set for variable a (Line 50) to be hexadecimal with the same value. Remember that a hexadecimal number must start with 0x. Compile and run the modified code.

  5. Change the value of a to the following list of values. First, calculate the expected output and then run the code after each and record the output value. Which ones agree, which ones do not? Note: you may also simply copy lines 60 and 67 for each value to test and run the program only once.

    Inputs

    Calculated (DEC)

    Output (HEX)

    Output (DEC)

    0x00

    0b00000000

    0x10

    0x0C

    0x70

    0xFF

    0b11111111

    0x0100

    0xFFFF

  6. Repeat testing all of the variables above except use variables b and c instead of a. You’ll need to either add printf statement(s) to print the values or you may modify the current one. You’ll notice that some values for b are very different as compared to what you may expect. Think about why the results might be different. The reason for the differences will be discussed in the next lecture.

  7. Finally, set the value of c to your RIN at the end of the code, just prior to the End of Program print. Add a printf such that your name is printed followed by your RIN, where your name is part of the printf string and the RIN is printed from variable c.

  8. Save your final modified code as a .c file. Upload this file as part of the Gradescope portion of the activity (last question). You do not need to submit your answers to the tables and questions above.

    Hint

    The modified .c file (usually main.c unless renamed) is not located in the .zip for the project you downloaded, that archive is not modified. The file is located within the workspace folder that is selected upon CCS startup.

    An easy way to find the file’s location is from within CCS: Right click the file in the CCS Project Explorer pane, and select Properties. The location will be listed under Resources. Additionally, there is a button after the location listing that will open the file location in the file manager.