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:
- Study the MCU datasheet, MCU Reference Manual and the Lab Safety Guidelines
and answer the questions below.
- Obtain a microcontroller module
- Install the HC12 software following the procedures
given below
- Run the program lab1_prog1.c using the simulator. The phrase
"Bert Ernie" should give the value 207 or 0xCF.
- 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)
- Run the program using the simulator and note the final computed
value
- (optional, but suggested): Run the program lab1_prog2.c to exercise the
simulator. You'll be using this program in the lab itself.
Questions:
- Briefly describe three things stated in the
Lab Safety Guidelines that you
should always do before powering up a circuit in the lab.
- Answer the following questions based on the LAB
FAQ and Admin Info:
- The pre-lab writeup file-naming convention is ??
- The lab writeup file-naming convention is ??
- The file format all non-code files must be submitted in is ??
- One thing you are expected to bring to all exams and labs is ??
- 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.
- DDRT=??
- PERT=??
- PTTST=??
- RDRT=??
- 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.
- Example: MOVB - Copies the 8-bit
value stored in one memory location to another memory location.
- LDAB
- STAA
- CLR
- BEQ
Hand-in Checklist: (30 points)
Use the file prelab1_handin.txt as a
template for your prelab hand-in.
- (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
- (10 pts) Answers to the questions above.
- (10 pts) List the string you chose and the final computed digest value from
lab1_prog1.c .
- (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.
- The LEDs on the module are active-low. That is, writing a
"1" value to the corresponding MCU pin will turn the LED off, while
writing a "0" will turn it on.
- The switches are active-low. When the switch is pressed, it will be
read as a "0". It will be read as a "1" when it is
not pressed.
lab1_prog3.asm uses the LEDs and push button switches on the project
board.
- In contrast to the stand-alone modules, the LEDs on the project board are
active-high. Writing a "1" value to the MCU pin will turn the
LED on.
- Writing a "0" value to the MCU pin will turn the LED off.
Like the buttons on the stand-alone module, the buttons on the project board
are also active-low.
Procedure:
Part 1:
- Use the USB TBDML connector on the APS12C128 module to load lab1_prog2.c
onto the APS12C128 module. (See procedure below)
- Ensure that the USER jumpers are set to enable the onboard buttons and
LEDs.
- Execute lab1_prog2.c on a stand-alone microcontroller module using the USB
TBDML interface. Exercise its functions.
Part 2:
- Connect the APS12C128 module to the board on the J5 connector.
- Wire the push button switches and LEDs according to the instructions in
lab1_prog3.asm.
- Program lab1_prog3.asm using the USB tether on the project board.
- 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:
- 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.
- Use the USB port on the project board to load the modified lab1_prog1.c
that you submitted with your prelab.
- 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):
- Combine the functionality of programs 2 and 3. This part can be
written in C or ASM (your choice).
- 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).
- 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)
- (10 points) Demo to TA lab1_prog2.c on the stand-alone module.
- (10 points) Demo to TA lab1_prog3.asm on the combined module and project
board.
- (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.
- (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.
- (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!
- (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.
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
- Important! Make sure the power jumpers are correct! See
Powering the Project Board for more
information.
- Disconnect all power and USB cables BEFORE changing any jumper
settings.
- On the module, enable BDM_EN jumpers BKG and RST
- On the module, enable PWR_SEL jumper VB. Disable PWR_SEL jumpers VR1 and
VX_EN.
- Open CodeWarrior.
- Click File > New. The HC(S)12(X) Microcontrollers New Project window
should appear.
- On the Device and Connection page: Click HCS12 > HCS12C Family >
MC9S12C128.
- Set the default connection to TBMDL (You will still be able to access
other connections later).
- Click Next.
- On the Project Parameters page: Select C and deselect all other options.
- Name the project and click next.
- On the Add Additional Files page: Click next.
- On the Processor Expert page: Select none. Click next.
- On the C/C++ Options page: Select ANSI, Small, and None for the three
options. Click next.
- On the PC Lint page: Select No. Click next.
- Then, click Finish.
- Add File lab1_prog2.c to the project sources folder on the left.
- Remove File main.c from the project sources folder on the left.
- On the module, check the PWR_SEL jumpers. Make sure jumper VB is connected
and jumper VR1 and VX_EN are not connected.
- Connect USB cable from the computer to the USB TBDML port on the module.
- Verify that the VDD LED and BDM Status LED turns green on the module.
- In the pulldown menu on the left of the Codewarrior window, verify that
the target is TBDML.
- Click the Make icon or select Make from the project menu to make the
project.
- Click the Debug icon or select Debug from the project menu to run/debug
the project.
- 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:
- Create/Modify and/or make the code that you want to download.
- Try to download the code by clicking the debug icon.
- 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
- Important! Make sure the power jumpers are correct! See
Powering the Project Board for more
information.
- Disconnect all power and USB cables BEFORE changing any jumper
settings.
- On the module, disable BDM_EN jumpers BKG and RST
- On the module, enable PWR_SEL jumper VX_EN. Disable PWR_SEL jumpers VR1
and VB.
- Open CodeWarrior.
- Click File > New. The HC(S)12(X) Microcontrollers New Project window
should appear.
- On the Device and Connection page: Click HCS12 > HCS12C Family >
MC9S12C128.
- Set the default connection to P&E USB BDE Multilink (You will
still be able to access other connections later).
- Click Next.
- On the Project Parameters page: Select Absolute Assembly (you need to deselect the C code option to make Absolute Assembly available).
- Name the project and click next.
- On the Add Additional Files page: Click next.
- On the Processor Expert page: Select None and click Finish.
- Add File lab1_prog2.asm to the project under the sources folder on the
left.
- Remove File main.asm form the project sources folder on the left.
- On the MCU, check the PWR_SEL jumpers. Make sure jumper VX_EN is connected
and jumpers VR1 and VB are not connected.
- 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.
- Wire the module to the project board using the information in the comments
at the top of the lab1_prog2.asm file.
- Use the J6 and USER I/O connectors on the project board to do so.
- Connect the USB cable from the PC to the project board.
- Verify that the +3.3 V, +5 V and USB LEDs turn green and the POWER OUT LED
turns orange on the project board.
- Verify that the VDD LED turns green on the MCU.
- In the pulldown menu on the left of the Codewarrior window, verify that
the target is P&E USB BDM Multilink.
- Click the Make icon or select Make from the project menu to make the
project.
- Click the Debug icon or select Debug from the project menu to run/debug
the project.
- 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).
- It would take a thick book (that nobody would want to read) to spell out
all the possible details for getting things working. Most people will do fine
on this lab, but some will get stuck on some part or other. Stay for all of
recitation and make notes about what you see. Ask the TAs (who will be in the
lab during lab and office hours) for help before recitation. Most of all, don't
wait until the last minute!
- Double-check the position of all jumpers, even ones you think you
haven't changed, if you are having problems!
- Pay special attention to the USER jumpers on the microcontroller module.
They will need to be "on" for some programs.
- Easily more than half the time that students tell us their board is
"dead" the problem is simply incorrect jumpers.
- The include files in the IDE can sometimes be an easier-to-use reference to
memory location names than the chip documentation (they list all the memory
location names and their defined addresses)
- If you are denied access to course files, make sure you are using a campus
machine or VPN onto the campus network so your web browser function gets a
campus IP address.
- Make sure you use "start," "halt," and
"reset" functions in the simulator and when running the CPU module to
actually run the program. Figuring out how to get all this working is an
important part of this lab -- ask a TA if you have problems.
- If you are having problems with the CPU module, try these steps:
- Reset the CPU module using the momentary reset button
- Re-load the program via USB
- Try another computer with a different USB port and cables
- If your fingers get sore with the jumpers, carefully use a small set
of needlenose pliers to move jumpers.
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:
- 1/19/16: Removed Cyclone from connection type for assembly (should just be Multilink) -- Milda