Intro
Intro
Laboratory Manual
Vpp Vpp
+5V 8
+5V 1N4003
6N139
800Ω 2 1kΩ coil
6 1 2
7405
Computer 3
3 IRF540
5
Fall 2001
Jonathan W. Valvano
Electrical and Computer Engineering
University of Texas at Austin
email: valvano@[Link]
web: [Link]
how to program: [Link]
Embedded Microcomputer Systems: Lab Manual Page 2
This laboratory manual accompanies the book, Embedded Microcomputer Systems: Real Time Interfacing, by
Jonathan W. Valvano, published by Brooks-Cole, copyright © 2000.
Responsibility grade
Quiz 20+
Preparation 10*
Printout of software, due at the start of lab
Edited and compiled with no syntax errors
Not handwritten, hard copy printout, but not necessarily debugged
Hardware circuit diagram, due at the start of lab
Chip numbers, pin numbers, resistor/capacitor types and tolerances
Connections to computer,
Procurement of all necessary parts
Preliminary hardware circuit diagrams but not necessarily built or debugged
Report 45*
(5) Final hardware circuit diagrams (handwritten drawings are OK)
(25) Software quality
Documentation, the comments, choice of good variable names
Interface to the human operator, menus, error messages
Style, organization, top down structure, local variables, careful use of the stack
(15) Results printout, performance/data graphs (handwritten drawings are OK)
Checkout, demonstration to TA
Performance, correctness of the program function 15*
Oral understanding of engineering tradeoffs 10+
Penalty Late Checkout -5/day*
Late Report -5/day*
Total 100 +
+ partners receive a separate grade
* partners receive the same grade
Since there will be times when students will work other than the regularly scheduled lab sections, it is
necessary that certain regulations be observed for the convenience and safety of all. Since the possibility of lethal
shock exists in those circuits utilizing low potentials, the following should always be observed:
3. Work benches must be clear of all coats, knapsacks and extraneous materials. Coat racks are desired for
those desiring this convenience. Otherwise all materials must be stored under the work area or out of
the way.
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 3
4. Shoes must be worn in the lab at all times. Shoes represent a significant protection against electrical
shock.
5. Smoking, food and beverages (e.g., coffee) are not permitted anywhere in the lab area.
Turn off power, do not move the injured. Start artificial respiration if breathing has stopped. Have someone
else call 911 or 9-911 if CPR is needed.
IN CASE OF FIRE:
Turn off the power, call 911 or 9-911, fight fire with available extinguisher, have someone clear the
building.
LAB PARTNERS: Every student is required to have a lab partner. You will perform all labs with a partner.
Students choose their own lab partners during the first week.
LAB EQUIPMENT USAGE: Lab hours are posted in the laboratory. There are no sign-up sheets, but cooperation
is expected. If you start debugging on a station, you may stay as long as you like, with three exceptions:
You must leave when the second floor labs are closed for the day;
You must leave during the first hour of the other regularly scheduled lab periods;
You may not leave the station unattended for more than 15 minutes.
If you would like to use a station that has been left unattended for more than 15 minutes:
1) Carefully disconnect the hardware and eject any floppy disks;
2) Do not save any software files;
3) Return all materials (hardware, disks, paper) to the front desk;
4) Leave a note on the station with your name and time;
5) Write a note to the TA describing exact times listing what you turned in.
LAB QUIZ: The purpose of the lab quiz is to encourage students to prepare for the lab. The scope of the quizzes
will be material relevant to the lab preparation. The quiz will be conducted during the first 10-15 minutes of each
lab session.
LAB PRE PARATION : Lab preparation must be performed prior to the regularly scheduled lab period. All software
must be written, edited and designed before coming to the lab. Hardware must be designed down to the pin
numbers. Label all resistance and capacitance values and types. For example, 1kΩ 5% carbon, or 0.01µF 5%
ceramic. In this way, the lab period may be spent in debugging your system with the TA’s help. The preparation is
due at the start of the lab. Preparation includes gathering all the physical components required to perform the lab.
LAB REPORT: Each lab report is bound separately (you should not put them together.) No purpose, methods, or
analysis required. Every lab report should include the following items:
1. Detailed hardware designs with pin numbers.
Include all external devices used (chips, R’s C’s values and types)
Show connections to the 6812 board.
2. Source code listings: Document your software so that what you did and why you did it could be easily
understood by the TA (and by you a year from now.)
Make it clear how the individual files are compiled together.
3. Data/Results: Whenever appropriate, use the printer to get a hardcopy listing of your results. Include
graphs and figures as specified in the assignment.
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 4
CHECKOUT : A rough draft of your hardware diagrams and hard copy printout of your source code listings must be
given to the TA before you demonstrate. If your experiment works you will be assigned a good score on the
performance part. The TA will ask the partners oral questions that test your “understanding” of the computer
engineering concepts of the lab. The partners will answer separate questions and receive separate “understanding”
grades. You must get your rough draft software listings signed and dated by a TA to prove that the lab was
completed in a satisfactory manner. Late checkouts will result in lost points.
I.4. PROJECT DEVELOPMENT
H2
MODB
RS485 Run Boot 0
unregulated 0 reset pin 1
MODA
power J5
MC68HC812A4
optional
DB9 to PC ADAPT812
COM2 1997(c) Techological Arts
H1
pin 1
green BDM TOP DB9 to PC
J4
MAX232 COM1
red PIC16
reset ON
1234
BDM Interface
Copyright(c) Kevin Ross
Each of the stations is equipped with the following:
- The PC COM1 is connected to a serial port 2-to-1 switch box
one serial port is connected to a Kevin Ross BDM-12 module
the other serial port is connected to a Motorola MC68HC912B32 EVB (pod mode)
- The PC COM2 is connected to your Adapt812 SCI0 port (optional)
- A Kevin Ross BDM-12 background debug module
you will connect this BDM-12 to the BDM port of your Adapt812
- An unregulated power supply
you will connect this power to the power connector of your Adapt812
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 5
of this introduction chapter. With Windows NT or 95, you will run Kevin Ross’s DOS-level [Link] program
using the batch file we wrote called [Link]. You can purchase your own BDM-12 board in kit form for about $48
from Kevin Ross at "Kevin Ross" <kevinro@[Link]> Identity yourself as a student.
The proper DIP settings on the Kevin Ross BDM-12 board are
1 ON for 38400 bits/sec
2 OFF for debugger mode
3 OFF for 8 MHz 6812
4 OFF for 8 MHz 6812
The 6-pin ribbon cable between the Kevin Ross BDM-12 and the Technological Arts Adapt812 should be attached
so that Pin 1 is connected to Pin 1. It is possible to reverse the polarity so be careful. The power lights come on
(but the system doesn't work) if the cable is reversed. There are two versions of the Adapt812 board1. The
Technological Arts APAPT812 Rev1 settings are
Run/Boot switch (SW2) should be in the Run position (bypass the on-chip boot loader)
MODA/MODB jumpers should both be in the 0 position (single chip mode.)
The Technological Arts APAPT812 Rev2 settings are
Run/Boot switch (SW2) should be in the Run position (bypass the on-chip boot loader)
Exp/Sgl switch (SW3) should be in the Sgl position (for single chip mode)
Rterm jumper (W12) should be inserted (enables resistor for RS485 network)
MODA jumper (JB2) should be inserted
MODB jumper (JB1) should both be in the 0 position (single chip mode.)
1
Rev1 and Rev2 have different H1 connector pin assignments for PS5 PS6, PS7
2
You could write assembly programs by creating file.s assembly source files
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 6
I.4.2.2. Interrupts, vectors, and Dealing with the COP on the Adapt812
In ICC12, the steps required to initialize an interrupt handler are illustrated in the following example.
When the Adapt812 software is started with the reset button, it is in normal single chip mode with Computer
Operating Properly (COP) enabled. You must either disable COP as is done in this example or periodically refresh
it as is done in the second example. Notice how the reset vector is defined at the end of the program. After reset on a
software system created with ICC12, the 6812 will begin at _start, which initializes RAM and calls your main()
program. In ICC12, the entry point _start is defined in the file crt12.s.
In any mode, your software can disable the COP feature with:
COPCTL=0x00; // disable COP reset
This first example disables the COP. The Red LED (PT6) on the Adapt812 will flash on/off.
// *********LED1.C****************
// PT6 LED flashes on and off
#include "HC12.H"
void init(void){
COPCTL=0x00; // disable COP
DDRT|=0x40;} // PortT bit 6 is output to LED
void main(void){ int i;
init(); // initialize COP, Port T
while(1){ i++;
if(i>0)
PORTT |= 0x40; // LED is on
else
PORTT &= ~0x40;}} // LED is off
extern void _start();
#pragma abs_address:0xfffe
void (*reset_vector[])() = { _start };
#pragma end_abs_address
In this second example, a background TOF interrupt is requested every time the TCNT register overflows from
0xFFFF to 0x0000. The ritual TOFinit() will activate TOF periodic interrupts. The software interrupt handler will
keep the COP happy. This TOF interrupt also toggles bit 6 of Port T, flashing the red LED. The TOF interrupt
vector is right after the interrupt service routine, and the reset vector is defined right after the main program.
// *********LED2.C*********************
// PT6 LED flashes on and off
#include "HC12.H"
void TOFinit(void){
DDRT|=0x40; // PortT bit 6 is output to LED
TSCR=0x80; // TEN(enable)
TMSK2=0xA5; // TOI arm, TPU(pullup) timer/32 (4us)
CLKCTL=0x00;
asm(" cli");} // enable interrupts
#pragma interrupt_handler TOFhandler
void TOFhandler(void){
TFLG2=0x80; // TOF interrupt acknowledge
PORTT^=0x40; // toggle bit 6
COPRST=0x55; // make COP happy
COPRST=0xAA;}
#pragma abs_address:0xffde
void (*TOF_vector[])() = { TOFhandler };
#pragma end_abs_address
void main(void){
TOFinit(); // Enable TOF interrupt to make COP happy
while(1){
}
};
extern void _start(); /* entry point in crt12.s */
#pragma abs_address:0xfffe
void (*reset_vector[])() = { _start };
#pragma end_abs_address
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 7
Normally we will start our Adapt812 software by pushing the reset vector, which runs our software in normal single
chip mode. When our Adapt812 software is started with the BDM-12 module, then it is possible to run software in
special single chip mode. We can run our software in special single chip mode by typing the following lines using
the BDM-12 debugger.
reset
load LED2.S19
g F000
I.4.2.3. ICC12 options menu for developing software for the Adapt812
On the ICC12 development system, we use the options_compiler_linker menu command to specify where
the start of globals (the data section grows towards higher addresses), and the start of the object code (the text
section grows towards higher addresses). The initial stack pointer (stack grows towards lower addresses), is specified
in options_compiler_linker menu. On our Adapt812 system,
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 8
We use the options_compiler_compiler dialog to specify that C source code be added to the Asm Output On our
Adapt812 system,
Check the “Emit Interspersed C Source in Asm Output” button.
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 9
We use the options_compiler_preprocessor dialog to specify that C++ comments can be used. On our Adapt812
system,
the Include path is set to e:\mc6812\include (ask you TA about this field)
Check the “Accepts C++ Comments” button.
When you execute [Link], it will copy files from the hard drive back to your floppy disk. During software
development you should rotate at least 3 floppy disks, so that you can return to previous states when you get a
computer crash, when one file becomes corrupted, or when you make a software modification you wish to undo.
Notice how the three floppy disks are used in a rotation. In each case, you load the files from the newest floppy, edit
the files on the hard drive, then save the files onto the oldest floppy disk. When you have a software system that
runs enough to allow a partial credit demonstration to the TA, put that disk aside and entire new floppy disk into
the rotation. The following table shows the contents of the disks after each software development session.
time session disk A disk B disk C
1 create new programs, save on A session 1 blank blank
2 load from A, edit, save on B session 1 session 2 blank
3 load from B, edit, save on C session 1 session 2 session 3
4 load from C, edit, save on A session 4 session 2 session 3
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 10
The following assembly program is embedded into the above high level C program. The double colon,
::, specifies the label as external and will be available in the *.map file. The .area text is the standard place for
programs, and the .area bss is the standard area for globals. Assembly level functions (e.g., _lowSub) and
variables (e.g., _lowGlobal) are defined beginning with an underscore, “_”. To access a C function, the assembly
program simply calls it (the name begins with an underscore.) The assembly program has full access to high level
global variables (the name begins with an underscore.)
Again, parameter passing with both functions (the assembly calls to the C and the C calls to the assembly) must
adhere to the standard ICC12 parameter passing rules:
If you are writing an assembly language function that is to be called from C, one method to get the parameter
passing correct is to write a simple C function that simply passes the parameters. Compile this simple C function
with your other C code, and observe the assembly language created by the compiler for the simple C function. Next
draw a stack picture that exists at the start of the function. The C compiler will do some weird things within the
function (like pushing register D on the stack, and shifting some 8 bit parameters around), which you do not have to
duplicate. One difficulty with mixing the assembly with C is that when the compiler is upgraded, this compatibility
matching must be redone. For more information on parameter passing see
[Link]
All source files used with ICC12 must end in a carriage return (ENTER.) We have noticed that the following error
means the last character in this file is not a carriage return.
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 11
An interrupt vector tells the computer what interrupt service routine to execute on a hardware or software
interrupt. Normally, we define the interrupt vector right after the interrupt service routine itself. For example,
#pragma interrupt_handler TOFhandler
void TOFhandler(void){
TFLG2=0x80; // TOF interrupt acknowledge
PORTT^=0x40; // toggle bit 6
}
#pragma abs_address:0xffde
void (*TOF_vector[])() = { TOFhandler };
#pragma end_abs_address
There is a ICC12 Version 5 bug, such that two #pragma abs_address commands can not follow each
other. For example this code will not compile under ICC12 V5 (you get a very weird error)
#pragma interrupt_handler TOFhandler
void TOFhandler(void){
TFLG2=0x80; // TOF interrupt acknowledge
PORTT^=0x40; // toggle bit 6
}
#pragma abs_address:0xffde
void (*TOF_vector[])() = { TOFhandler };
#pragma end_abs_address
On the other hand, this code will compile (I moved the #pragma)
#pragma interrupt_handler TOFhandler
void TOFhandler(void){
TFLG2=0x80; // TOF interrupt acknowledge
PORTT^=0x40; // toggle bit 6
}
#pragma abs_address:0xffde
void (*TOF_vector[])() = { TOFhandler };
#pragma end_abs_address
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 12
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 13
with the limited-version of Hiware. For a sense of how large a program you can develop with the limited-version,
look at the Hiware 6812 examples in the Hiware12 folder of the TExaS application (after TExaS is installed.)
I.6.2. Power Adapter
To run the Adapt812, you will need 5.5 to 9 VDC unregulated power source with a current of at least 100
mA, plus the additional current your external circuits need. A good choice is a +6V AC adapter at 300 to 500 mA.
If the voltage is too high then the regulator on the Adapt812 will get hot. Test your power source while attached to
the Adapt812 to guarantee the supply voltage is less than +9 V, and the Vcc power on the H1 connector is about
+5.0 V.
Connect the 32K RAM to the 68HC812A4 like figure 9.60, except use CSP0 inplace of CSD. The memory bus is
available on the Adapt812 H2 connector:
6812 Ports A, B contain the 16-bit address A15-A0,
6812 Port C contains the bidirectional 8-bit data bus,
6812 Port E contains the E clock and R/W,
6812 Port F contains the built-in chips selects.
In narrow mode the data is on PORTC, but is labeled as D15-D8 on the Adapt812. The jumpers MODA and
MODB are on the Adapt board (change MODA from off to on), remember to put MODA back before you turn the
board in. Within ICC12, change the text (program) option from F000 to 8000. You now have 32K of program
space. If you need to download, and untether the system from the PC power, then power the Adapt board with
batteries (6V into the power connector) or 5V directly into the 6812.
I.7. Web sites
cool web site: [Link]
Jonathan W. Valvano
Embedded Microcomputer Systems: Lab Manual Page 14
Jonathan W. Valvano