EE 476: Laboratory 1

Introduction to the lab hardware/software.


This assignment introduces you to the software and hardware development tools you will use this semester to work with the 80C196KB microcontroller chip.


The hardware you will be using to support the 80C196KB is the Intel EV80C196KB evaluation board, a small board providing:

A small power supply (+/12v., 5v., appropriately fused) provides power through a 4-pin connector.

After this introductory lab, every lab exercise will involve using the prototype boards from EE 475. The pinouts for the EV80C196KB on the protoboard are given in a handout in the lab or here.


Software support consists of an Embedded Control Monitor (ECM) running on the PC which communicates with the RISM on the board, a cross-assembler (ASM-96), a cross-C-compiler (iC-96), a relocatable linker (RL-96), and a debug monitor (iMON-196) with many more features than the ECM.

ECM-96: You have been provided with several pages from the EV80C196KB Microcontroller Evaluation Board Users Manual describing the use of the ECM. This will be your primary means of downloading programs to the 80C196KB and executing them under debug control. Communication with the ECM is via the PCs serial interface (COM1) at 9600 baud.

ASM-96: After preparing program files in ASM-96 assembler language using a text editor (the filename extension is usually .A96), invoking ASM-96 on the PC will assemble the program and create an object file (.OBJ) and a listing file (.LST).

To run a program (minimally) you will need to:

  1. Produce a text file of the assembler code
  2. At a DOS prompt, assemble it using the assembler command:
    asm96 myprog.a96
    to produce a file myprog.obj
  3. At a DOS prompt, start ECM using the command
    (assuming the EV80C196KB is connected and turned on).
  4. At the ECM prompt, transfer the object file to the EV80C196KB with:
    load myprog.obj
  5. At the ECM prompt, Start the program by typing
  6. At the ECM prompt, Stop the program by typing
Other useful ECM commands include: Please consult the ECM users manual for variants of these commands and for more details.

Before Coming to your Lab Session:

  1. Study the handout on the operation of the ECM to get a good idea of its operation and capabilities.
  2. Complete both programming assignments below, whose code you will run in this lab.
  3. Look over this handout.
The Lab Session

(1) Make sure the evaluation board is connected to power and to the PC as specified in the Evaluation Board Users Manual. Turn on the PC. Turn on the power supply. You should observe the LED bar turn on.

(2) Change directory (CD) to MCS96 and look at the directories there. These are the software tools you will be using. Keep your own programs on your own diskettes. CD to ECM96 and look at the files there. 96KBRISM.A96 is the source of the RISM running in EPROM on the Evaluation board.

(3) Run the demo whose sample session is in the back pages of the Evaluation Board Users Manual. Enter:
ECM96 include demo.log
The ECM will take its instructions from this file and echo them to the screen so you can follow what is happening. Periodically the program will pause for you to observe. You begin execution again by pressing the space bar. Observe what ECM can do for you. Observe the counting behavior of the LED bar during execution of the demo program. Notice how LED 8 dims as the count gets close to the top. It is connected to the Pulse Width Modulator (PWM) pin of the microcontroller.

(4) Run the demo program again, this time typing in the commands to ECM96 yourself. Try some of the commands which were not in the demo.log file. What is the contents of the SP, as found from the SP command? How about the contents of 18H (the SP)? Why are they different (its in the Users Manual)?

(5) CD back to \ and then to \TMP (create TMP if it is missing).

NEVER modify the files in MCS96 and its subdirectories. NEVER add to the files in MCS96 and its subdirectories. ALWAYS use \TMP for temporary storage of your programs on the hard disk. Copy the demo source program \MCS96\ECM96\96KBDEMO.A96 and the include file \MCS96\ECM96\DEMO.LOG to your floppy. The source of this demo program is attached as a sample both of a program written for the 80C196KB and the output from the ASM-96 assembler. Assemble it with:
Run ECM96 again and verify your copy of 96KBDEMO.OBJ performs the same way as the demo. When using ECM96 (but not iMON-196), you do not have to link (with RL-96) an executable consisting of one stand-alone module. Use of the DEBUG feature on the ASM96 command line will allow you to use symbols rather than absolute memory locations when using ECM96 for on-line debugging.

(6) Enter the two programs you have prepared. Copy the register and interrupt definition file \MCS96\ECM96\SETUP.INC (copy attached) to your floppy and $INCLUDE it in your programs. Once you have removed any errors found by ASM96 and recorded in the .LST file, then use ECM96 to download and debug the code itself. Time the amount of time it takes for the LED counter to go from 00H to 0FFH. From your knowledge of the code and the characteristics of Timer1, calculate the state time of the microcontroller. Does your figure agree with the 80C196KB Users Manual?

(7) Have your Lab Instructor verify that each program is doing what it should be doing and prepare a brief report described below to hand in in lab the following week.

College computer labs are notorious for the ease with which computer viruses infect machines and spread from one lab to another. The machines in the Digital Laboratory have virus protection (F-PROT w/VIRSTOP), but the best protection is for you to be certain that no virus is being brought into the lab on your diskettes. In any case, never boot (with the power switch or with CTRL/ALT/DEL) a computer with your diskette (or any other) in a diskette drive. This is the mechanism by which the most infectious viruses (the boot sector viruses) infect hard disks. If a machine fails to complete the boot sequence and freezes, suspect a virus VIRSTOP must often take this action to prevent an infection.


Before peripheral equipment is attached to the 80C196KB evaluation board in later Labs, the external input capabilities are nonexistent, and its output capability consists of a LED bar with 10 LEDs which can be turned on and off under program control (0-7 are connected to Port 1). The code required in the two problems in this assignment is to be written in the assembly language of the 80C196KB. You may use the instruction set of the Intel 8096 as it appears in Appendix B of Peatman or that of the 80C196KB as given in its Users Manual. You may assume that the names declared for the I/O registers of the 8096 in Figure B.7 of Peatman are already known to your program when assembled. All programs are to start at 2080H, and should declare a stack beginning at 100H.

1. Write a program to show LEDs 0-7 counting up in binary from 00H to 0FFH and back down to 00H again. Repeat indefinitely. Program the Pulse Width Modulation (PWM) port to provide a pulse train on the PWM port to LED 8 whose duty cycle goes from 0% (bright) to 100% (dim) as LEDs 0-7 go from 00H to 0FFH. The count interval should be the time it takes Timer1 to overflow twice. This program should wait (poll) for the overflow. The JBC instruction and the fact that the IOSx registers are cleared by reading them allows a one-instruction wait.

2. Write a program to accomplish the same result as in Problem 1, but using interrupts rather than polling. The main program should set up the interrupt and then go on to do anything desired (a branch instruction to itself is sufficient for this problem). The LED counter will be handled by the interrupt routine, whose entry point should be named int00: (to be compatible with the register and interrupt definition file SETUP.INC you should $INCLUDE). As you design this routine, keep in mind you are essentially building a 4-state machine. At each interrupt you need to determine which state you are in and branch to a section of code which sets the next state and output. The prelude and postlude of the interrupt routine should follow the code at the bottom of p. 559 of Peatman. Note that the PWM enable bit and the Timer1 overflow interrupt enable bit share the same IOC register, which is write only you cannot determine from IOCx whether any of its bits are set or not without using the windowing feature of the 80C196KB (nor do you usually need to).

Your report should be brief, answer the questions posed in this handout, and contain listings of your programs. In the comments section you should mention what part of the programming assignment gave you the most trouble, and what kind of additional information would have been helpful in getting up to speed on this processor.

A word about listings You will want to obtain hard copy from time to time of the assemblers .LST file. Please dont waste paper! You will get useful listings with the least waste by making sure the printer is in compressed mode (which will print 132 characters per line and 80 lines per page there are instructions posted by the printer) and assembling with ASM96 96KBDEMO.A96 NOSB PL(80) (which will generate a listing with no Symbol Table and 80 lines per page). Use the $LIST and $NOLIST commands in the source file to turn off the listing of debugged code you dont need to see any more.

Source of SETUP.INC

Read this carefully to see how to set up interrupt symbols in your program and for definitions of the standard i/o and control registers.

; This program segment provides much of the initialization required to develop
; programs for the EV80C196KB evaluation board run under the control of its
; Reduced Instruction Set Monitor (RISM). It is included in a program module
; with the Assembler Control statement
; The RISM uses the following resources, which are therefore not available to
; the user:
;       The NMI (Non Maskable Interrupt) and its vector
;       Two words in the system stack
;       The TRAP instruction and its vector
;       External memory partitions (0000H-00FFH),
;                                  (1D00H-1EFFH), and
;                                  (2014H-202FH)
;               ( Note that all of these partitions, (except 1D00H-1EFFH and 
;                 2018H), are reserved by the MCS-96 architecture. )
;       Nine bytes of registers in the partition  (30H-38H).  The
;       user must ensure that no registers in this partition are used
;       by code which is to operate with the RISM. One way of doing
;       this is to generate an ASM-96(tm) module which declares an
;       RSEG at 30H which is nine bytes long. Code is included in this
;       file declaring these registers.
; This segment defines symbols for the register mapped I/O locations
; (Special Function Registers - SFC) in 00H to 18H.
; This segment defines several utility macros.
; This segment defines symbols for the interrupt vectors at 2000H-200EH and
; 2030H-203CH.  The interrupt vectors point to default interrupt routines in
; high memory. To use an interrupt, use the same symbol (intxx) and delete
; the symbol in the default interrupt section (*don't* comment out the line!).
; Define symbols for the register mapped I/O locations
; ----------------------------------------------------
R0              equ   00H:word      ; R/W   Zero Register
ad_command      equ   02H:byte      ;   W   A to D command register
ad_result_lo    equ   02H:byte      ; R     Low byte of result and channel 
ad_result_hi    equ   03H:byte      ; R     High byte of result
hsi_mode        equ   03H:byte      ;   W   Controls HSI transition detector
hsi_time        equ   04H:word      ; R     HSI time tag
hso_time        equ   04H:word      ;   W   HSO time tag  
hsi_status      equ   06H:byte      ; R     HSI status register (reads fifo)
hso_command     equ   06H:byte      ;   W   HSO command tag
sbuf            equ   07H:byte      ; R/W   Serial port buffer
int_mask        equ   08H:byte      ; R/W   Interrupt mask register
int_pending     equ   09H:byte      ; R/W   Interrupt pending register
watchdog        equ   0AH:byte      ;   W   Watchdog timer
timer1          equ   0AH:word      ; R     Timer 1 register
ioc2            equ   0BH:byte      ;   W   I/O control register 2
timer2          equ   0CH:word      ; R/W   Timer 2 register
baud_rate       equ   0EH:byte      ;   W   Baud rate register
port0           equ   0EH:byte      ; R     I/O port 0
port1           equ   0FH:byte      ; R/W   I/O port 1
port2           equ   10H:byte      ; R/W   I/O port 2
sp_con          equ   11H:byte      ;   W   Serial port control register 
sp_stat         equ   11H:byte      ; R     Serial port status register
int_pend1       equ   12H:byte      ; R/W   Interrupt mask register 1
int_mask1       equ   13H:byte      ; R/W   Interrupt pending register 1
wsr             equ   14H:byte      ; R/W   Window Select Register
ioc0            equ   15H:byte      ;   W   I/O control register 0 (HSI/O)
ios0            equ   15H:byte      ; R     I/O status register 0
ioc1            equ   16H:byte      ;   W   I/O control register 1 (Port2)
ios1            equ   16H:byte      ; R     I/O status register 1
ios2            equ   17H:byte      ; R     I/O status register 2
pwm_control     equ   17H:byte      ;   W   PWM control register 
sp              equ   18H:word      ; R/W   System stack pointer
; This section defines utility macros non-specific to this program
; ----------------------------------------------------------------
DEFINE_BIT      macro   name,bitnum
                name    equ bitnum

SET_BIT         macro   regnum,bitnum
                orb     regnum,#( 1 SHL (bitnum mod 8)  )

CLR_BIT         macro   regnum,bitnum
                andb    regnum,#not( 1 SHL (bitnum mod 8) )

BL              macro   label
                bnc     label
; This space MUST be reserved for RISM registers
; ----------------------------------------------
	rseg at 30H
;	-----------
RISM_USE:       dsb     9               ; Reserved for RISM use
; Set up the interrupt vector table
        cseg at 2000H
;       -------------
timer_overflow: 	dcw     int00
ad_done:		dcw	int01
hsi_data:		dcw	int02
hso_event:		dcw	int03
hsi_zero:		dcw	int04
software_timer:		dcw	int05
serial_port:		dcw	int06
external_int:		dcw	int07
	cseg at 2030H
;	-------------
serial_txd:		dcw	int08
serial_rxd:		dcw	int09
hsi_entry_4:		dcw	int10
timer2_capture:		dcw	int11
timer2_overflow:	dcw	int12
external_int_pin:	dcw	int13
hsi_fifo_full:		dcw	int14
; Set up default interrupt routines which loop forever for debugging
        cseg at 7FE2H
;       -------------
int00:	br	$
int01:	br	$
int02:	br	$
int03:	br	$
int04:	br	$
int05:	br	$
int06:	br	$
int07:	br	$
int08:	br	$
int09:	br	$
int10:	br	$
int11:	br	$
int12:	br	$
int13:	br	$
int14:	br	$

Short program related to the first assignment

lab1related module main
;This program increments the port1 LEDs, while blinking the pwm over a small
	rseg at 20H
count:	dsb	1
pwm:	dsb	1
	cseg at 2080H
start:	ld	sp, #100	;init the stack pointer
cl1:	clrb	count		;clear a counter
cl2:	ldb	pwm, #0D0H	;set a pwm output variable
top:	bbc	ios1,5, $	;wait for a timer1 overflow
	incb	count		;increment the count
	incb	pwm		;increment the pwm variable
	stb	count, port1	;count --> LEDS
	stb 	pwm, pwm_control;pwm variable --> pwm output
	cmpb	pwm, #0ffH	;if max then reset
	be	cl2		;
	cmpb	count, #0FFH	;if max then reset
	bne	top		;otherwise keep counting
	br	cl1

Copyright Statement