18-348 Lab #1

Spring 2016

SEE THIS LINK for the lab demo schedule for all groups

Links to all files referenced in the lab and prelab can be found Files section at the end of this document.

Reminder: Pre-labs are due at 9 PM, with 5% early submission bonus if submitted by 1:30 PM on the due date.

Note: there is a hints section at the bottom of this assignment that applies to both pre-lab and lab. Also, there are links to resources you will probably find helpful there as well. Some of these files have access restricted to the campus network only. Follow the instructions linked to from the class homepage to set up off-site VPN access if you are not on the campus network but need this access

Tip: A local copy of the development studio installer can be found here.

Tip: If you have trouble accessing the data sheets please use the VPN.

Be sure to read the Lab FAQ to find out where to hand in your prelab. If you still need help come to office hours.


Pre-Lab:

Like all pre-labs, this is pre-lab is an individual assignment and you should NOT be getting help from anyone except course staff. We strongly suggest you submit the pre-lab by the early submission time to get an easy bonus and make sure you won't have problems over the weekend.

Goal: Make sure that you can use the microcontroller software environment, including executing a sample program using a simulator.  Become familiar with the MCU datasheet and MCU Reference Manual.

Discussion: Most likely you will be doing some project work on your on computer in addition to work on the lab computers. (You can do everything on the lab computers if you like, but experience has shown most students prefer to be able to work outside the lab at times.) During the pre-lab, you should use whatever computer(s) you expect to be using for other pre-lab activity so you can get problems shaken out up front. The idea of the pre-lab is to get the software installed and working so they are ready to use for subsequent labs. While we can't officially support all possible hardware and software configurations, the TAs will try to help you get your system up and running if you come to office hours.

Procedure:

  1. Study the MCU datasheet, MCU Reference Manual and the Lab Safety Guidelines and answer the questions below.
  2. Obtain a microcontroller module
  3. Install the HC12 software following the procedures given below
  4. Run the program lab1_prog1.c using the simulator.  The phrase "Bert Ernie" should give the value 207 or 0xCF.
  5. Edit the program lab1_prog1.c to have in a unique phrase (for example, your first and last name or complete andrew e-mail address)
  6. Run the program using the simulator and note the final computed value
  7. (optional, but suggested): Run the program lab1_prog2.c to exercise the simulator. You'll be using this program in the lab itself.

Questions:

  1. Briefly describe three things stated in the Lab Safety Guidelines that you should always do before powering up a circuit in the lab.
  2. Answer the following questions based on the LAB FAQ and Admin Info:
  3. Section 2.3.2.1 of the MCU datasheet describes the control registers for the Port T I/O register (PTT).  Describe the setting for the registers below required to make all bits of Port T an input port with disabled pull up, operating at full strength. Give answers as 8-bit binary numbers.
  4. Section 5 of the CPU12 Reference Manual describes the MCU instruction set.  Briefly explain the purpose of the following instructions.  An example is given to explain what we mean by "brief". If a specific register is involved, state which register that is.

Hand-in Checklist: (30 points)

Use the file prelab1_handin.txt as a template for your prelab hand-in.

  1. (5 pts) List of any problems you encountered in the lab, and suggestions for future improvement of this lab. If none, state "none" to receive credit
  2. (10 pts) Answers to the questions above.
  3. (10 pts) List the string you chose and the final computed digest value from lab1_prog1.c .
  4. (5 pts) Turn in the modified program code as-run. Remember to add your andrewid and your name to the program file (both in the filename and as a comment in the header). This means you should submit your C file into your AFS hand-in directory.

Even though it is possible to hand in a .txt file to answer these questions, in future labs you will need to have Acrobat (.pdf) files. Therefore, you must hand in .pdf on this lab to make sure there is time to resolve any problems that may crop up for producing those files. (If you have a problem creating .pdf and TAs can't sort it out before the deadline we'll give you slack on this one prelab, but the point is to identify problems so they can get fixed before the next hand-in.

Refer to the LAB FAQ for more information on lab hand-in procedures and file type requirements.  You MUST follow these procedures or we will not accept your submissions. We'll give a little slack for problems if you make a good faith effort, but will only do so on this first "warm-up" assignment.


Lab:

This is a team effort of you and your lab partner, including all preparation work beyond the pre-lab material, the lab demo, and the lab writeup. You should work together for all lab assignments, but not for pre-labs. Your team should only talk to course staff for help on lab assignments.

Goal: Demonstrate that you can use the microcontroller hardware environment, including executing a sample program using both the microcontroller board stand-alone and in conjunction with the project/prototyping board.

Discussion:

This lab is to ensure that you can use the lab hardware and lab stations. You can and should attempt these steps on your own computer to the degree you can. You should also perform all steps necessary for a demo in the actual lab well before your scheduled demo time. There are three programs -- one is the same program as the pre-lab. The second program is one that exercises the buttons and LEDs on the microcontroller module.  The third program is a C program that exercises the buttons and LEDs on the project board. You are expected to understand what the programs do by looking at the listings (they aren't that complicated). You'll be using both the ".c" and ".asm" versions of one program to make sure you can use the development tools with both types of files. Probably most of your effort on this lab will be spent getting started on the learning curve for the various tools. Be sure that you have set all the switches and jumpers to their proper default positions before doing this lab.

lab1_prog2.c uses the LEDs and push button switches on the APS12C128 module.

lab1_prog3.asm uses the LEDs and push button switches on the project board. 

Procedure:

Part 1:

  1. Use the USB TBDML connector on the APS12C128 module to load lab1_prog2.c onto the APS12C128 module. (See procedure below)
  2. Ensure that the USER jumpers are set to enable the onboard buttons and LEDs.
  3. Execute lab1_prog2.c on a stand-alone microcontroller module using the USB TBDML interface. Exercise its functions.

Part 2:

  1. Connect the APS12C128 module to the board on the J5 connector.
  2. Wire the push button switches and LEDs according to the instructions in lab1_prog3.asm.
  3. Program lab1_prog3.asm using the USB tether on the project board.
  4. Execute lab1_prog3.asm. Exercise its functions.  This program is similar to lab1_prog2.c, except that it uses ports T and P for input and output.

Part 3:

  1. Wire the project board according to the instructions in lab1_prog1.c.  Note that this wiring is compatible with the wiring from Part 2, so you should be able to just add the new connections without modifying the existing wiring.
  2. Use the USB port on the project board to load the modified lab1_prog1.c that you submitted with your prelab.
  3. Execute the modified program lab1_prog1.c from the pre-lab on the project board. Observe that the value displayed on the LEDs is the same value you computed using the simulator.

Bonus (optional):

  1. Combine the functionality of programs 2 and 3.  This part can be written in C or ASM (your choice).
  2. Start out with the wiring from Part 2 and make any wiring changes you think necessary. Hints: Stay away from Port M and Port P3 (it has some bits that don't work as you might expect).  
  3. The switches on the APS12C128 module should exercise the LEDs on the project board, while the switches on the project board should exercise the LEDs on the stand-alone module.  The behavior should be the same (i.e. switch 1 should turn on the corresponding LED 1 and switch 2 should turn on the the corresponding LED 2).

Demo Checklist: (40+8 points)

  1. (10 points) Demo to TA lab1_prog2.c on the stand-alone module.
  2. (10 points) Demo to TA lab1_prog3.asm on the combined module and project board.
  3. (20 points) Demo to the TA executing the program on the combined module and project board and displaying the values on the project board's LEDs.
  4. (BONUS: 8 points) Demo to the TA the bonus program on the combined module and project board.

Hand-in Checklist: (10 + 2 points)

Use lab1_handin.txt as a template for your hand-in. Note that hand-in files (except for source code .c, .h, and .asm files) must be in Adobe Acrobat format per the Lab FAQ.

  1. (10 points) List of any problems you encountered in the lab and pre-lab, and suggestions for future improvement of this lab. Please include a brief version of any problems you might have notified us about even if they were fixed. We will use this part of your hand-in for this and all labs next year to make sure we fix as many problems as we can and that they stay fixed!
  2. (BONUS: 2 points) Submit a listing of the code for your bonus module.  Code should be fully commented to receive full credit.

Refer to the LAB FAQ for more information on lab hand-in procedures and file type requirements.  You MUST follow these procedures or we will not accept your submissions.

Tip: Since each lab partner has a stand-alone module, you can use one for the stand-alone module demo and the other for the project board demo. That avoids having to repeatedly insert and remove a module from the project board.


Support material

There are all sorts of documents, help files, on-line tutorials, and so on available on the Web. But, frankly, diving in without a how-to guide can be pretty confusing. So we've put together some step-by-step instructions for doing various parts of the lab. If have problems with these please let us know, but ultimately it is your responsibility to ensure that you can perform the requested operations well before your assigned lab demo time. Walking into the lab with this list and expecting it to work the first time without a trial run is unrealistic.

How to install the Simulator

We officially support running the simulator/development suite on Windows. You are free to try to get the simulator working on whatever OS you prefer, but we won't provide any support or help getting you up and running (though if you get it working, let us know and we'll post whatever help/instructions you have for the rest of the class).

We are using the Special Edition of the CodeWarrior Development Studio for HCS12(X) Microcontrollers. You can access the download to the Windows installer from this page. Run the installer and pick all the defaults, installation should be straightforward.

How to load a program using the Simulator

Follow the below instructions for loading a C or assembly program, with the following exception:  When the wizard prompts you with "Please choose the connections you want" (page 9 for C programs, page 5 for ASM), choose Full-Chip simulator.
Note that you can choose multiple targets, so you can enable both the simulator and to the serial monitor or USB debugger.  To choose which target is used, use the Project > Select Default Target menu item in the Codewarrior IDE

How to load and run a C program on the stand-alone microcontroller module using the USB TBDML interface on the APS12C128 module

  1. Important! Make sure the power jumpers are correct! See Powering the Project Board for more information.
  2. Disconnect all power and USB cables BEFORE changing any jumper settings.
  3. On the module, enable BDM_EN jumpers BKG and RST
  4. On the module, enable PWR_SEL jumper VB. Disable PWR_SEL jumpers VR1 and VX_EN.
  5. Open CodeWarrior.
  6. Click File > New. The HC(S)12(X) Microcontrollers New Project window should appear.
  7. On the Device and Connection page: Click HCS12 > HCS12C Family > MC9S12C128.
  8. Set the default connection to TBMDL (You will still be able to access other connections later).
  9. Click Next.
  10. On the Project Parameters page: Select C and deselect all other options.
  11. Name the project and click next.
  12. On the Add Additional Files page: Click next.
  13. On the Processor Expert page: Select none. Click next.
  14. On the C/C++ Options page: Select ANSI, Small, and None for the three options. Click next.
  15. On the PC Lint page: Select No. Click next.
  16. Then, click Finish.
  17. Add File lab1_prog2.c to the project sources folder on the left.
  18. Remove File main.c from the project sources folder on the left.
  19. On the module, check the PWR_SEL jumpers. Make sure jumper VB is connected and jumper VR1 and VX_EN are not connected.
  20. Connect USB cable from the computer to the USB TBDML port on the module.
  21. Verify that the VDD LED and BDM Status LED turns green on the module.
  22. In the pulldown menu on the left of the Codewarrior window, verify that the target is TBDML.
  23. Click the Make icon or select Make from the project menu to make the project.
  24. Click the Debug icon or select Debug from the project menu to run/debug the project.
  25. The debugger window will open. Click the Start/Continue icon or select Start/Continue from the Run menu to run the program.

    If another window containing the HC(S)12 Connection Manager settings appears, simply click Connect(Reset).

To download code after already downloading code:

  1. Create/Modify and/or make the code that you want to download.
  2. Try to download the code by clicking the debug icon.
  3. The debugger window will open. Click the Start/Continue icon or select Start/Continue from the Run menu to run the program.

How to load and run an assembly language program on the project board via USB connection

  1. Important! Make sure the power jumpers are correct! See Powering the Project Board for more information.
  2. Disconnect all power and USB cables BEFORE changing any jumper settings.
  3. On the module, disable BDM_EN jumpers BKG and RST
  4. On the module, enable PWR_SEL jumper VX_EN. Disable PWR_SEL jumpers VR1 and VB.
  5. Open CodeWarrior.
  6. Click File > New. The HC(S)12(X) Microcontrollers New Project window should appear.
  7. On the Device and Connection page: Click HCS12 > HCS12C Family > MC9S12C128.
  8. Set the default connection to P&E USB BDE Multilink (You will still be able to access other connections later).
  9. Click Next.
  10. On the Project Parameters page: Select Absolute Assembly (you need to deselect the C code option to make Absolute Assembly available).
  11. Name the project and click next.
  12. On the Add Additional Files page: Click next.
  13. On the Processor Expert page: Select None and click Finish.
  14. Add File lab1_prog2.asm to the project under the sources folder on the left.
  15. Remove File main.asm form the project sources folder on the left.
  16. On the MCU, check the PWR_SEL jumpers. Make sure jumper VX_EN is connected and jumpers VR1 and VB are not connected.
  17. Plug the module J1 pins into the MCU Port connector J5 on the project board. Make sure the pins on the module plug into the proper places on the J5 connector, i.e. their numbers match.
  18. Wire the module to the project board using the information in the comments at the top of the lab1_prog2.asm file.
  19. Use the J6 and USER I/O connectors on the project board to do so.
  20. Connect the USB cable from the PC to the project board.
  21. Verify that the +3.3 V, +5 V and USB LEDs turn green and the POWER OUT LED turns orange on the project board.
  22. Verify that the VDD LED turns green on the MCU.
  23. In the pulldown menu on the left of the Codewarrior window, verify that the target is P&E USB BDM Multilink.
  24. Click the Make icon or select Make from the project menu to make the project.
  25. Click the Debug icon or select Debug from the project menu to run/debug the project.
  26. The debugger window will open. Click the Start/Continue icon or select Start/Continue from the Run menu to run the program.

    If another window containing the HC(S)12 Connection Manager settings appears, simply click Connect(Reset).

Hints and Suggestions:

FILES for this lab:

prelab1_handin.txt - template for prelab hand-in. Note that hand-ins are required to be in Adobe Acrobat format, so you'll need to convert this file to Acrobat format before submitting.

lab1_handin.txt - template for the lab hand-in. Note that hand-ins are required to be in Adobe Acrobat format, so you'll need to convert this file to Acrobat format before submitting.

lab1_prog1.c - sample assembly program; check comments and be sure to change the data string.

lab1_prog2.c - sample c program; check comments in this file for program description and wiring information.

lab1_prog3.asm - sample assembly program; check comments in this file for program description and wiring information.

Relevant reading:

Alternate information:

See the course materials repository page.


Change notes for 2014: