28
LABORATORY MANUAL DEPARTMENT OF ELECTRICAL & COMPUTER ENGINEERING UNIVERSITY OF CENTRAL FLORIDA EEL 4742 Embedded Systems Revised September 2011

DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Embed Size (px)

Citation preview

Page 1: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

LABORATORY MANUAL

DEPARTMENT OF ELECTRICAL & COMPUTER ENGINEERING

UNIVERSITY OF CENTRAL FLORIDA

EEL 4742 Embedded Systems

Revised September 2011

Page 2: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Safety Rules and Operating Procedures 1. Note the location of the Emergency Disconnect (red button near the door) to shut off power

in an emergency. Note the location of the nearest telephone (map on bulletin board).

2. Students are allowed in the laboratory only when the instructor is present. 3. Open drinks and food are not allowed near the lab benches. 4. Report any broken equipment or defective parts to the lab instructor. Do not open, remove

the cover, or attempt to repair any equipment. 5. When the lab exercise is over, all instruments, except computers, must be turned off.

Return equipment to the designated location. Your lab grade will be affected if your laboratory station is not tidy when you leave.

6. University property must not be taken from the laboratory. 7. Do not move instruments from one lab station to another lab station. 8. Do not tamper with or remove security straps, locks, or other security devices. Do not disable

or attempt to defeat the security camera. 9. When touching the development boards, please do not touch the solid-state parts on the board

but handle the board from its edge. 10. ANYONE VIOLATING ANY RULES OR REGULATIONS MAY BE DENIED ACCESS TO THESE FACILITIES.

I have read and understand these rules and procedures. I agree to abide by these rules and procedures at all times while using these facilities. I understand that failure to follow these rules and procedures will result in my immediate dismissal from the laboratory and additional disciplinary action may be taken. ________________________________________ ________________ Signature Date Lab #

i

Page 3: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

ii

Laboratory Safety Information Introduction The danger of injury or death from electrical shock, fire, or explosion is present while conducting experiments in this laboratory. To work safely, it is important that you understand the prudent practices necessary to minimize the risks and what to do if there is an accident. Electrical Shock Avoid contact with conductors in energized electrical circuits. The typical cannot let-go (the current in which a person cannot let go) current is about 6-30 ma (OSHA). Muscle contractions can prevent the person from moving away the energized circuit. Possible death can occur as low 50 ma. For a person that is wet, the body resistance can be as low as 1000 ohms. A voltage of 50 volts can result in death. Do not touch someone who is being shocked while still in contact with the electrical conductor or you may also be electrocuted. Instead, press the Emergency Disconnect (red button located near the door to the laboratory). This shuts off all power, except the lights. Make sure your hands are dry. The resistance of dry, unbroken skin is relatively high and thus reduces the risk of shock. Skin that is broken, wet, or damp with sweat has a low resistance. When working with an energized circuit, work with only your right hand, keeping your left hand away from all conductive material. This reduces the likelihood of an accident that results in current passing through your heart. Be cautious of rings, watches, and necklaces (which increase the conductivity and contact area). Skin beneath a ring or watch is damp, lowering the skin resistance. Shoes covering the feet are much safer than sandals. If the victim isn’t breathing, try to find someone certified in CPR. Be quick! If the victim is unconscious or needs an ambulance, call 911. If able, the victim should go to the Student Health Services for examination and treatment. Fire Transistors and other components can become extremely hot and cause severe burns if touched. If resistors or other components on your proto-board catch fire, turn off the power supply and notify the instructor. If electronic instruments catch fire, press the Emergency Disconnect (red button). These small electrical fires extinguish quickly after the power is shut off. Avoid using fire extinguishers on electronic instruments. Explosions When using electrolytic / tantalum capacitors, be careful to observe proper polarity and do not exceed the voltage rating. Electrolytic and tantalum capacitors can explode and cause injury. A first aid kit is located on the wall near the door. Proceed to Student Health Services, if needed.

Page 4: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

EEL 4742 Lab Grading Policy Page

1. In this lab students will work in group (a group of 2 or 3 members). 2. Groups will be formed on the first day of the lab. 3. Students MUST maintain this group throughout the semester for this lab. 4. Each group will submit ONLY ONE REPORT per lab. 5. Each lab will be completed in 1, 2 or 3 weeks. The EXACT

DURATION of a lab will be decided by the lab instructor prior to the lab.

6. ALL members of a group must be present during the lab experiments and must participate in the lab assignments ACTIVELY.

7. Students can NOT skip the labs. SPECIAL PERMISSION must be taken from the LAB INSTRUCTOR to do so. Otherwise, total marks for that scheduled lab will be DEDUCTED from that student's earned points so far in this lab.

8. Students must follow the SAMPLE REPORT format for submission of lab report.

9. Each lab will be graded out of 100. 10. The deadline for submission of lab reports will be decided by the lab

instructor. 11. Each lab report must be submitted before or on the scheduled deadline.

Otherwise marks will be deducted.

If required, Lab policy will be modified and will depend solely on the lab instructor.

Page 5: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

EEL 4742 LAB #

Section: _______ Points: _______

Name: ________________________________________________PID:_____________

Name: ________________________________________________PID:_____________

Name: ________________________________________________PID:_____________

Name: ________________________________________________PID:_____________

Objectives: Resources: Procedure: Source Code (.asm code with proper comments): ...Write your .asm code here... .lst code: …Write your .lst code here as obtained from the experiment… Screen shot of output: …Provide your screen shot of output here…

Page 6: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 1 (sim6811), 1 week

Objectives:

The objective is to learn assembly language programming, how to compile, assemble and execute code on sim6811 and to get used to machine language. The goal is that by the end of this lab, you should be able to write assembly code, see it being executed on sim6811 and how it’s being converted to machine instructions, and be comfortable with different options available within sim6811.

Resources:

1. Chapter 3, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

1. Download and unzip sim6811.zip from webcourses (in your local computer C:\Temp). Avoid long file names and spaces.

2. Download the new code "SIMLAB1.ASM” from webcourses. 3. Use “Command Prompt” to assemble your code and execute it using commands below:

AS11 SIMLAB1.ASM –L > SIMLAB1.LST SIM6811 SIMLAB1.S19

4. Run the code (i.e., type go 2030 and hit ENTER), ignore any symbol file errors.

Note: You may have to initialize the stack register value to a smaller number (i.e., Use r sp 00ff) before running the code, in case the stack pointer exceeds its maximum limit (i.e., 00ff).

5. Where would you find help from if you are stuck? Try ‘HELP’ or ‘?’. Experiment with T, GO, R, MD, and other commands available to you in simulator.

6. Open SIMLAB1.asm (using notepad) and go through the code. Pay special attention to keywords like ORG, START, END, SWI, etc. and note the general structure of code.

Program structure Example Program Location Variables Code Starts Code Code Ends

ORG $2000 MEMSTO FCB $00 START LDAA #10 ADDA #48 END

Pay special attention to the spacing which usually is a tab. Notice how subroutines are used.

7. Open LST file and see how each instruction is converted to machine instructions. Try to locate line number, address, and instructions. See how assembly instructions are converted into machine code.

Page 7: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Code

ORG $2000 Reserves space in memory for storing stuff MEMSTO FCB $00 STRING FCC 'The final number is: ' MEMSTO1 FCB $00 MEMSTO2 FCB $00 STRING1 FCC ' in Hexadecimal.' FCB $04 ORG $2030 Reserves memory for the program START LDAA #10 Loads ten in decimal to accumulator A STAA MEMSTO ADDA MEMSTO STAA MEMSTO LDAB #%00001111 ANDB MEMSTO ADDB #48 STAB MEMSTO2 LDAB #%11110000 ANDB MEMSTO LSRB LSRB LSRB LSRB ADDB #48 STAB MEMSTO1 LDX #STRING JSR OUTSTRG SWI OUTSTRG LDAA 0,x THIS ROUTINE OUTPUTS A STRING POINTS TO BY X cmpa #$04 see if we are at the end BEQ done jsr OUTA go write the single character inx point to the next char bra OUTSTRG done RTS Finished go retrun INCHAR PSHB THIS ROUTINE INPUTS ONE CHAR IN A REG RCHR1 LDAB $102e go see if the the receive buffer is empty ANDB #$20 BEQ RCHR1 LDAA $102f source input character in the A reg PULB RTS OUTA PSHB THIS ROUTINE OUTPUTS ONE CHAR IN A REG WCHR1 LDAB $102e go see if the transmit buffer is empty ANDB #$80 BEQ WCHR1 STAA $102f go write the char PULB RTS END

Page 8: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 2 (AxIDE), 1 week

Objectives:

The objective is to learn how to compile, assemble and load M68HC11 code, how to use the EVB monitor commands (BUFFALO) and to get used to assembly language programming. The goal is that by the end of this lab, you should be able to write, understand and modify the assembly code, and also should be able to monitor its execution.

Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 2, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

Part 1

1. Connect your PC to M68HC11EVB Board. Make sure you connect power to the board. Reset the Board.

2. Download Lab2.asm from webcourses or enter the code at the end of this assignment in any editor (e.g., Notepad) and save it as "LAB2.ASM”. Make sure your file is stored at a proper place (i.e., C:\AxIDE or C:\Temp folder, no spaces). This code below performs simple addition, i.e., 10+10 = 20.

3. Open "LAB2.ASM” and try to understand the general structure of code. Pay special attention to the spacing which usually is a tab. Also see the use of keywords like ORG, EQU, FCB, STARTS, END, etc. See example below:

Program structure Example Hardware Defined Constants Program Location Variables Code Starts Code Code Ends

OUTSTRG EQU $FFC7 ORG $2000 MEMSTO FCB $00 START LDAA #10 ADDA #48 END

4. Assemble your code using AxIDE (i.e., Build Button). Shortcut should be on your desktop (or find executable in ‘C:\AxIDE’ folder). Check LST file for any errors. If any errors occur, correct your program and compile it again. If you experience any problems check the communication parameters; they should be:

BAUD RATE PARITY DATA BITS STOP BITS PORT 9600 None 8 1 COM1

Page 9: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

5. Once you have successfully compiled your code, upload your “LAB2.S19” file into the

Microprocessor. You will have to write “>load t” before you upload file. 6. Run your program by writing “>go 2030”. If the program works properly, it displays:

The final number is: 14 in Hexadecimal.

7. Type HELP. Use BR (Break Point) and T (Trace) to break execution and trace your program step by step respectively. It may be useful to observe how a value in Registers A and B and Index Register X change as your program is executed. Experiment with other commands especially MD (Memory Dump), MM (Memory Modify), and RM (Register Modify).

8. Try to understand the assembly language code and correlate the results that you see on screen with the code. Especially try to figure out how string is printed and the addition of two numbers is performed. Try to understand how the conversion of numbers to ASCII is done before you display them. You will extensively use this conversion and printing.

9. Open LST file and see how each instruction is converted to machine instructions. Try to locate line number, address, and instructions. See how assembly instructions are converted into machine code.

10. Compare the code with SIMLAB1.ASM (Lab1) and notice how differently Input Output subroutines are used.

11. Modify the above program to add an additional message display on a new line:

Welcome to EEL 4767.

12. Modify the program to add 20 and 20. 13. Modify your program to subtract two numbers, i.e., 20-10=10.

Part 2

14. Write the assembly code which inputs an uppercase letter (e.g., ‘A’) and prints it in lowercase (e.g., ‘a’).

15. Update your code to echo the (uppercase) input. 16. Show your results to the lab instructor and also take screen shots of all of your

results for the report.

Note: You should remember the following:

• Every program requires using some allocated memory which should be within the range of valid RAM addresses ($0036-$00FF and $E000-$FFFF).

• Every string requires a special number specifying the end of the string (FCB $04). • The only way of communication between you and the board is your program. So

when you are having problem, it most probably has something to do with your program.

• Make sure that you keep log of all your experiments and save your work. You might not find it on same machine next week.

Page 10: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010 Code

*--------------------------------------------------------------------- * Date: * Programmer: * Group members: * File name: * Program description: This is a sample program used for EEL 4767 lab 2. * The program stores decimal ten in accumulator A adds ten to it and * prints it on the screen using a routine stored in ROM. We called the * routine OUTSTRG, it will print a string of ASCII bytes if the pointer * to the string is stored in index register X. The string to be printed * should end with the end of transmission character $04. Other routines * are provided in ROM for public use. See page 141 of MC68HC11 An *Introduction - Software and hardware interfacing for further information. *--------------------------------------------------------------------- * The following routines are described on page 3-3 of the M68HC11EVB * Evaluation Board User's Manual UPCASE EQU $FFA0 OUTA EQU $FFB8 OUTSTRG EQU $FFC7 INCHAR EQU $FFCD ORG $2000 Reserves space in memory for storing stuff MEMSTO FCB $00 STRING FCC 'The final number is: ' MEMSTO1 FCB $00 MEMSTO2 FCB $00 STRING1 FCC ' in Hexadecimal.' FCB $04 ORG $2030 Reserves memory for the program START LDAA #10 Loads ten in decimal to accumulator A STAA MEMSTO ADDA MEMSTO STAA MEMSTO LDAB #%00001111 ANDB MEMSTO ADDB #48 STAB MEMSTO2 LDAB #%11110000 ANDB MEMSTO LSRB LSRB LSRB LSRB ADDB #48 STAB MEMSTO1 LDX #STRING JSR OUTSTRG END SWI *-----------------------------------------------------------------

Page 11: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 3, 1 week

Objectives:

The objective is to learn assembly language programming, how to compile, assemble and execute code on AXIDE and sim6811 and to get used to machine language. The goal is that by the end of this lab, you should be able to write assembly code, see it being executed on AxIDE & sim6811 and how it’s being converted to machine instructions.

Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 3, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

Part 1 (AxIDE)

1. Enter the code at the end of this file in any editor and save it as "LAB3ERR.ASM”. Or you can download "LAB3ERR.ASM” from webcourses. Please read the code and try to understand what’s going on.

2. Try to fix errors in the code. You may have to add or remove few labels. Compile and Run the code to see the result “The final number is: 0A in Hexadecimal”. Don’t forget to check the LST file to ensure that there are no errors.

3. Once you are able to see the output, Open lab3err.lst and see how each instruction is converted to machine code. You may find it useful to have a look at the tables underneath every instruction at the end of your book (page 645).

Part 2 (Simulator)

4. Run the code above on sim6811. Don’t forget our friendly subroutines!

Part 3 (AxIDE and Simulator)

5. Write a program that inputs a string of characters until ‘+’ symbol is hit. At that time print the whole string. Please ensure that sim6811 result is similar to the AxIDE version of the code (i.e., echo input string and print output string on new line)

6. Show your results to the lab instructor and also take screen shots of all of your results for the report.

Page 12: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Note: If you have finished first three labs (Lab 1, 2 and 3):

You should be able to do the following: 1. How to write basic assembly code, compile/build and run it for sim6811 and

AxIDE (MC68HC11). Also different between compiling code in board and simulator.

2. How assembly code is translated to LST file. 3. How to find help? Use G, BR, T, MD, MM, RM commands 4. Make and Print a number/variable and string, and of course conversion to ASCII

format.

Useful References:

1. ASCII Table is provided on Page 603 of the textbook. 2. Complete Instruction Set is available on Page 645 of the textbook. 3. Table with list of different available subroutines is available on Page 154 of the textbook. 4. Table with explanation of different symbols is available on Page 13 of the textbook.

Page 13: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Source Code (lab3err.asm)

*--------------------------------------------------------------------------------------------------- * Date: * Programmer: * Group members: * File name: * Program description: This is a sample program used for EEL 4767 lab 3. * This program contains some errors which the student needs to fix. The * Program should add decimal 5 two times and store it in memory location * "MEM". Soon after, the program will convert the number stored in "MEM" * to ASCII and display it on the screen using the ROM routine OUTSTRG. * The program "masks" out the high nibble from the number stored in memory * location "MEM" converts it and stores it in memory location "MEM1. * Similarly, then takes the low nibble of the number stored in "MEM", * converts it, and stores it in "MEM2". * The convention is done by the subroutine "CONVERT". The final display should read: * The final number is: 0A in Hexadecimal *--------------------------------------------------------------------------------------------------- OUTSTRG EQU $FFC7 BUFFALO EQU $C030 ORG $2000 MEM FCB $00 STRING FCC 'The final %^&*%# is: ' MEM2 FCB $00 STRING1 FCC ' in Hexadecimal.' FCB $04 ORG $E000 START LDAA #5 STAA MEM ADDA MEM STAA MEM LDAB #%11100000 ANDB MEM LSRB LSRB LSRB LSRB BSR CONVERT STAB MEM1 LDAB #%00001111 ANDB MEM BSR CONVERT STAB MEM2 LDX #STRINGG JSR OUTSTRG JMP BUFFALO END ***** SUBROUTINES ***** *This subroutine converts numbers stored in accumulator B to ASCII *characters that represent the number in HEX *---------------------------------------------------------------- CONVERT CMPB #9 BHI LETTER ADDB #48 Add decimal 48 to convert numbers to ASCII BRA DONE LETTER ADDB #55 Add decimal 55 to convert letters to ASCII DONE RTS *-----------------------------------------------------------------

Page 14: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 4, 1 week

Objectives:

The objective is to learn how to write assembly program, compile, assemble and execute code on MC68HC11 and sim6811. The goal is that by the end of this lab, you should be able to write assembly code, see it being executed and converted to machine instructions.

Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 3, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

Binary Coded Decimal (BCD): A BCD representation of a decimal digit is equivalent to its 4-bit, unsigned integer representation. A single byte can store two BCD digits, referred to as the packed BCD number. On the other hand, the unpacked BCD number requires that each decimal digit be represented by a byte, where the high-order nibble of the byte is 0 and the low-order nibble of the byte is occupied by the BCD representation of the digit.

1. Write a program to transfer 20 unpacked BCD numbers stored at $00--$13 into 10 packed BCD numbers stored at $14--$1D. For example, two unpacked BCD numbers $08 and $02 can be transferred into a packed BCD number as $82. Save your file as "LAB4.ASM”. Assemble and Run using AxIDE.

Tip: Your first step should be to check if you have your unpacked values at proper locations in the memory. Make sure you are reading values from the correct location and are storing them at the correct locations. It will be easier to pack the first set of numbers before you start working on the loop.

2. Print the unpacked numbers. Also output the resulting packed numbers on the screen.

3. Make necessary changes to run the program on sim6811. 4. Show your results to the lab instructor and also take screen shots of all of your results

for the report.

Page 15: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 5, 2 weeks

Objectives:

The objective is to I/O manipulation of characters in assembly language programming and familiarity with different numbering systems. You already should know how to compile, assemble and execute code on MC68HC11 and sim6811 and how machine language is generated. The goal by the end of this lab is that you should be able to get input from the keyboard and display it, with complete understanding of the conversion process.

Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 3, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

Part 1

1. Write a program with 68HC11 assembly language to read, from keyboard, two numbers 0 to 9 in decimal form and add them. Output your result on the screen. Assemble your code using AxIDE. Make sure your results are correct.

2. Write a program that expands on step 1 by allowing two 0-9 BCD numbers per input to be entered in via the keyboard. This expands the range of each input from 0-9 to 0 to 99. Please pack these two BCD number per input into one byte of data per input. Store each BCD input into the locations VAR1 and VAR2. Next, add the BCD number in VAR1 and VAR2 storing the result in the location RESULT. Finally, output the decimal result store in the location RESULT to the screen in decimal format. You will need to use the Decimal-Adjust Accumulator instruction to correctly format the resulting output in decimal format. Example: Let input 1 be 2 BCD digits of 99 stored in VAR1. Let input 2 be two BCD digits of 22 stored in VAR2. The decimal addition yields 121. So we need three BCD numbers. LDAA VAR1 ADDA VAR2

Page 16: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Note: This addition is a binary addition and produces the result of $99+$22=$BB which is not 121 in BCD format. The DAA instruction will correctly convert the binary result into 3 BCD digits in the A acc and the carry bit. After executing the DAA instruction whatever will be stored in the A acc will be the BCD digits of 21 and the carry will be set to one. The carry bit is the most significant BCD number followed by the 2 BCD numbers in the A acc.

3. Modify your code (Step 1) to input two hexadecimal numbers and show the result after their addition (in both hexadecimal and decimal formats).

4. Modify your code to input two 8-bit binary numbers and show the result after their addition (in binary, hexadecimal and decimal formats). Also display the carry bit.

5. Modify your code to input two 8-bit binary numbers and show the result after their subtraction (in binary, hexadecimal and decimal formats). Also display the carry bit.

Part 2

6. Make necessary changes to run the programs on sim6811. 7. Show your results to the lab instructor and also take screen shots of all of your results

for the report.

Page 17: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 6, 1 week

Objectives:

The objective is to learn I/O programming and parallel interfacing with 68HC11. You already should know how to compile, assemble and execute code on MC68HC11 and sim6811 and how machine language is generated. The goal by the end of this lab is that you should be able to communicate with I/O interfaces.

Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 3, Han-Way, Huang, (1996) MC68HC11 An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Procedure:

1. Write a program with 68HC11 assembly language to control the LED. Your program should turn the LED ‘ON’ for 2 seconds and it should turn it ‘OFF’ for 1 second. The program should run forever. Assemble your code using AxIDE and show your results to the lab instructor.

Resistors to Use: Please use the appropriate resistors to connect the LED to Port A. Use Ohm’s Law to calculate the resistor value. Assume the Vcc of 5V (High) and 0.2V (Low), VLED of 1.5V and ILED of 5 mA.

You can use any output pin of Port A (e.g., PA3-PA6). An example diagram is shown in Figure 7.18 (page 300 of text book) which explains how to connect the LED to the appropriate pins of the Port.

Note: A simple load and store instruction can be used to perform the I/O operation. For example, the following instructions will write $16 to Port A.

LDAA #%00010110 STAA $1000

Time Delay: Please ensure that the program runs for the required amount of time. A delay loop can be written to run for given time based on the number of clock cycles. An example delay loop can be found in Example 2.25 (page 81 of textbook).

Page 18: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 7, 2 weeks

Objectives: The objective is to use 7-segment LCD in order to display numbers. This lab will use your knowledge of software (i.e., assembly language) and basic circuits in order to introduce you to the hardware side of the world. The goal by the end of this lab is that you should be able to create your own circuit, write your software and make your display system work (after necessary troubleshooting if needed). Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 7, Han-Way, Huang, (1996) MC68HC11: An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Specification: Design and assemble ‘Lab7.asm’ in order to display hex numbers on a 7-segment LCD display. The program should read the binary representation for digits 0-F from memory and display them in ascending and descending order on the 7-segment display provided.

The first number displayed should be "0". It should be shown for 1 second. Use the timer to achieve this 1 second delay. The same delay should be used for all numbers displayed.

After the first delay, number "1" should appear followed by number "2" continuing in ascending order until an "F" is displayed. Now continue this to display numbers in descending order.

After displaying "0", have an "E" representing end of your program displayed.

You may use RTI (Real-Time Interrupt) to implement the time delay. Your program should use both ports A and D (Not Port B) which are located at $1000 and $1008 respectively. See pin diagram of the EVB interconnection to familiarize yourself with different pins. Only use the desired pins for the interconnections.

Note: Some pins in ports are multi-purpose. They can be input, output or bi-directional. See board’s schematic diagram on page 6 or Table 7.2 (Rev D.) in textbook. Normally we use output pins. Also note that Port D MUST be initialized before being used. You can do that by writing $3F to memory location $1009.

On the following diagram, the student annotates how each segment is mapped to each bit of ports A and D. See 7-segment LED port mapping diagram (Figure 1) below as

Page 19: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010 example. Make sure you are using correct LED segment display, so use appropriate data sheet. Search the web to find the datasheet.

Procedure: Part 1: using Port A and Port D only

1. Draw a circuit diagram in which the display is shown with its segments and the necessary connections to the M68HC11 ports. Remember to include pull-up resistors (100 ohm), buffer and power connections too. Don’t forget that not all bits from Ports A and D can be used for output. (Hint: See Fig 7.20 and 7.21)

2. On the Figure above, map each LED segment to the specific bit that will turn the segment on. For example, if Port A bit ‘0’ is going to turn the segment "a" on; a "1" should be written in the corresponding box for bit ‘0’. Do it for all segments.

3. Find out what hex number should be written at Port A and D for displaying any digit. Remember that some pins are not used (i.e., “0”). Map ports correctly and double check your work.

4. Wire-up your connections to the EVB board. Make sure that the Power is OFF! Caution: You must use the buffer with appropriate resistors. Without that you could easily damage the equipment.

5. Once you know that all connections to the HC11's I/O Ports are correct, you can power up the EVB board. Start testing your connections using the "BUFFALO" monitor (i.e., on AxIDE). By using Memory Modify (MM) command, you can write test bits directly to the ports and check that your segments are hooked correctly. e.g., if a specific bit is written to a port, the corresponding segment connected to it should turn on. Remember a ‘hanging’ pin can either be ‘1’ or ‘0’.

6. Write your program and make sure to add comments to your code. You program should display every number as described above (i.e., by writing hex numbers assigned in Step 3 at corresponding Ports) with proper delay.

Note: You may access the datasheet for buffer online. Don’t forget that pins generally named 1A1 are input and 1Y1 are usually output pins. One LCD Display connections can be seen below (Figure 2). Make sure you are using the correct datasheet if you are using some other LCD. Also don’t forget that each chip must be connected to VCC and GND properly before it can be used. In some cases you may need more than one GND (use Common Ground). Tips to avoid problems or delays:

1. In order to avoid problems, please test the ports, 7-segment display and buffer individually and collectively. Also ensure that the breadboard is used properly (Please see the wiring pattern below).

2. You can start by testing the outputs of the port using an LED (similar to Lab6). A simple MM (w/ LED) can verify if Ports are working fine.

Page 20: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

3. Test your 7-segment to ensure that it is working fine. You could try connecting ‘VCC’ to each pin one by one (through a resistor) and see if all sides lit up. Don't forget to provide ‘GND’ the appropriate pin. Note: Hanging pins (pins not connected to anything) may be 1 or 0.

4. Once the display is working, try connecting it with the buffer. Make sure that the appropriate buffer pins are grounded. Once connected, check the LCD display with the buffer by giving ‘VCC” to different pins of the buffer.

5. If buffer and LCD display are both working well together connect them with ports. You can individually check ports by MM command to see if your connections are ok. If you see something wrong please try to check your connections again.

Figure 1: MC68HC11 Ports

Hint: If you decide to use PA4 then you must change the fifth bit of Port A ($1000) to ‘1’. This can be done by a simple OR operation. Note: It’s best to avoid input and bidirectional ports (marked as X above).

Figure 2: 7-segment LCD display

Page 21: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Figure 3: Breadboard and its Wiring Pattern

Part 2: Using Port B

1. Repeat Part 1 for Port B. Use Single-Chip mode. 2. Write a program to simulate the "Knight Rider" effect (in a circle). Start on the left

side of the LCD display, and turn on one LCD segment. Then wait, and turn the next LCD segment to the right on and the leftmost one off. Continue moving the lighted LED to the right. After the LED just before the first one is on, start moving the lighted LED in the opposite direction. Repeat this forever. Never have all the LEDs off at any time. Use only Port B.

3. Please make sure that the board is configured to expanded mode once you are done.

Hints:

• Configure your board to work in Single-Chip mode. In order to do that you will need to change MOBA jumper on the board. Please refer to table 6.4 (page 253) of textbook.

• Single-chip mode is different than expanded mode that we have been using so far. We now have only a limited amount of ROM available for our program. Try to use ORG $100 or less.

Page 22: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 8, 1 week

Objectives: The objective is to use a temperature sensor (LM34) in order to display the temperature via the 68HC11. This lab will combine your knowledge of software (i.e., assembly language) and hardware. The goal by the end of this lab is that you should be able to interface your own circuit, with your software. Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 7, Han-Way, Huang, (1996) MC68HC11: An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Specification: Design and assemble ‘Lab8.asm’ in order to display the temperature of the room on AxIDE screen. The program will use LM34 and A/D conversion in order to convert the output voltage to Fahrenheit degrees. Procedure:

1. Connect the LM34 to EVB board using appropriate connections.

2. Write your code to read the output voltage from LM34 and convert it to integer representation. Display the values on AxIDE using OUTA. Note: You should use OUTA subroutine provided for simulator in order to avoid printing extra CRLF.

Figure 1

Page 23: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010 How do LM34 and A/D Conversion work? The LM34 produces an output voltage of 0.01 volts per degrees Fahrenheit and the A/D produces 256 counts in the voltage range of 0 to 5 volts. To convert the binary count from the A/D to degrees Fahrenheit the following conversion must be used: Degrees Fahrenheit = (A/D conversion result) * 5 volts / 256 counts

* 1 / (.01 degrees Fahrenheit / volt) Degrees Fahrenheit = (A/D conversion result) * 1.953125 Degrees Fahrenheit / count Configuration: To turn on the A/D two things are required. First the hardware pins for VRL and VRH must be connected to VRL = ground and VRH = +5 volts and the LM34 tepmerature sensor must be connected (please see Figure 1 above). Second the software must be configured using the OPTION register and the ADCTL register. The results of the A/D conversion are returned in the ADR1-ADR4 registers.

• A/D is powered on by setting the ADPU bit (7) of the OPTION register ($1039) to a 1. CSEL should be set to 0.

OPTION REG - $1039 ADPU CSEL IRQE DLY CME - CR1 CR0 $1030

0 0 0 1 0 0 0 0 1039 1 0 0 1 0 0 0 0 $90

• The ADCTL register ($1030) controls the operation of the A/D. The channel is

selected by writing the number to bits 0 - 3 (0000 = PAD0 = PE0). The SCAN bit (5) selects either continuous conversion (1) or a single conversion (0). The MULT bit (4) selects either four conversion of the same channel (0) or 4 sequential conversions starting at (CD, CC, CB, CA).

• An A/D conversion is started when CCF in the ADCTL register is written to with a 0. An A/D conversion is complete when the CCF bit equal to 1. The results are written to registers ADR1-ADR4 ($1031-$1034).

ADCTL REG - $1030

CCF - SCAN MULT CD CC CC CA $1030 0 0 X X X X X X reset 0 0 0 0 0 0 0 0 $00

Page 24: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010 The following subroutines can be used for A/D initialization and conversion. ADINIT PSHA

LDAA #$90 Turns on A/D converter STAA $1039 PULA RTS

ADCONV LDAA #$00 go write out A/D configuration STAA $1030 set the CCF bit to zero also to start LP LDAA $1030 Go see if the CCF bit one ANDA #$80 CMPA #$80 BEQ LP Yes it is go read conversion LDAA $1031 All results the same channel RTS A/D conversion return in the A reg

Example: For a temperature of 78 degree Fahrenheit, The A/D conversion will return a result of about 40 counts. To perform this conversion, a binary multiplication is needed. Note: In the 68HC11, the MUL instruction takes the value in the A register and multiplies it with the value in the B register and stores the result in the D register. To perform this multiplication the conversion factor of 1.953125 must be represented in binary. The problem is that this value does not easily fit into a eight bit number with the binary point either all the way to the right or the left. The binary point needs to be between bits 6 and 7.

1.953125 D7 . D6 D5 D4 D3 D2 D1 D0 1 . 1 1 1 1 0 1 0 $FA

A better approach is to multiply by half of the conversion factor of 1.953125 / 2 = 0.9765625 and then multiply by 2 which is just a shift left operation. This way the binary point is all the way to the left in either the A or B registers prior to the multiply.

0.9765625 . D7 D6 D5 D4 D3 D2 D1 D0 . 1 1 1 1 1 0 1 0 $FA

Page 25: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010 Assuming the A/D conversion result is in the A register, the following set of code performs the conversion from A/D counts to Degrees Fahrenheit: LDAB #$FA MUL LSLA After the multiply, the binary point is located between the A register and the B register. For example, let the A/D counted be equal to 40 (around 78 Degrees Fahrenheit).

40 binary D7 D6 D5 D4 D3 D2 D1 D0 . 0 0 1 0 1 0 0 0 . $28

After the MUL instruction

A Register D7 D6 D5 D4 D3 D2 D1 D0 . 0 0 1 0 0 1 1 1 . $28

B Register

. D7 D6 D5 D4 D3 D2 D1 D0

. 0 0 0 1 0 0 0 0 $10 Since we are only interested in displaying integer temperature values, the fractional result in the B register can be ignored. The integer part in the A register needs to multiplied by 2 since the multiplication was performed with the conversion factor of 0.9765625 which is a factor of 2 smaller than required.

A Register after the LSLA D7 D6 D5 D4 D3 D2 D1 D0 . 0 1 0 0 1 1 1 0 . $4E

The value of $4E hexadecimal is simply 78 decimal which is the initial temperature given in this example. The last step required to display the temperature to the screen (JSR OUTA) is to extract out each digit one by one from the result in the A register using division by 10 and then adding $30 to convert the result to an ASCI number symbol ($30-$39 = '0' - '9'). After building the hardware and writing the software run the temperature program and observe the temperature on the screen. The value displayed should be close to the room temperature of the lab. By changing the temperature the LM34, the temperature value on the screen should accordingly. What is the minimum increment in temperature that can be observed? How can this minimum increment be improved?

Page 26: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

EEL 4742 (Computer System Design I) Laboratory Assignment 9, 2 weeks

Objectives: The objective is to use interrupts in assembly language programming to implement 5-digit stop watch. You already should know how to compile, assemble and execute code on M68HC11 Board (and/or sim6811). The goal by the end of this lab is that you should be comfortable with interrupts. Resources:

1. Motorola Inc., (1990) M68HC11 Reference Manual. Phoenix, Arizona: Motorola Literature Distribution.

2. Chapter 6, Han-Way, Huang, (1996) MC68HC11: An Introduction - Software and hardware interfacing. Minnesota: West Educational Publishing.

Specification: The output of the stopwatch should have five digits to display in format of vwx.yz, where v, w, x, y and z represent 100’s 10’s, 1’s, 1/10th and 1/100th of seconds, respectively. Use an external interrupt (IRQ*) pin to start/stop/reset the timer. Your program should start the timer from 000.00 and should increment to 999.99. The stop watch should run forever. Program Details: The program consists of three parts namely ISR, Main program, and Display function.

1. Interrupt Service Routine: When IRQ* pin is pulled down to low (by connecting IRQ* Pin 19 to ground briefly), the external interrupt occurs. Your ISR should be executed upon receiving the interrupt. The routine should change the value of CNTRL (0, 1 or 2) and then display the time. To make your life simpler, think of an external interrupt just as a JMP statement. Make sure you use the correct JMP address (See Table 6.6). Note: CNTRL variable represents the state of your stop watch. You only have START, STOP and RESET. Also, you should ground the IRQ pin for a short period of time only. 2. Main Program: It can be broken into three main segments namely Initialization, Waiting Loop and Display Loop. For your simplicity a step-by-step breakdown of main segments of your program is provided below:

Page 27: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

1.1. Define and Initialize the control variable (e.g., CNTRL) and timer variables (e.g., V, W, X, Y, and Z).

1.2. Program: 1.2.1. Enable interrupts. 1.2.2. Waiting loop: Keep checking the control variable CNTRL to wait for

occurrence of the interrupt and changing its value. If CNTRL=0, jump to the timer loop.

1.2.3. Timer loop: The timer increments different digits using a delay loop of 10ms. The 1/100th digit is incremented after every 10 ms and then checked to see if it has reached 9. If so then the 1/10th digit is incremented and the 1/100th digit is reset to 0. When the 1/10th digit reaches 9, it is also reset to 0, and the 1’s digit is incremented. When the 1’s digit reaches 9, it is reset and the 10’s digit is incremented and so on. During this loop, the program should display the time every 100ms to the screen. The timer should be stopped by an external interrupt and then current time should be displayed. When the interrupt occurs, let the program jump to the waiting loop after CNTRL is changed to 1 (stop) or 2 (reset).

3. Display Function: The display function can use OUTA routine from the buffalo program. Display the time in the format like ###.## to the screen.

Procedure: Part 1

1. Write your timer loop and see if it works without any interrupt. 2. Write your ISR. Check if your ISR is working by printing value of CNTRL after

each external interrupt. Make sure your CNTRL variable values are 2, 0, 1, 2, 0, and so on (after the few interrupts). Note: Make sure that the interrupt are enabled and also your program should be waiting for the interrupt in an infinite loop.

3. Combine Part 1 and 2 so that your timer loop now works when the external interrupt is provided. Make sure that the CNTRL variable is checked during each iteration of your timer loop. Also use CLI or RTI properly (i.e., we neither want to ignore any interrupt nor service a single interrupt twice).

4. The expected outputs are as following: At the start of the run, program displays 000.00 and waits for the interrupt. After the first interrupt, your stop watch starts incrementing and each value is displayed until next interrupt is received. At that time the stop watch stops. Another interrupt will reset the stop watch to 000.00. If you wait long enough to see 999.99, your stop watch should automatically reset to 000.00 and keep incrementing until the next interrupt.

Note: It may take some time for your external interrupt to reach your software. A small delay in ISR may be useful.

Page 28: DEPARTMENT OF ELECTRICAL - University of Central … 4742 Lab Manual_older.pdf · DEPARTMENT OF . ELECTRICAL & COMPUTER ENGINEERING . ... If electronic instruments catch fire,

Updated: Spring 2010

Part 2

5. Modify your code to implement PAUSE in your stop watch. 6. Implement a stop watch which has both RESET and PAUSE. You will need to

use a second interrupt to know if user wants to RESET or PAUSE.

Hint: You should use XIRQ for PAUSE and IRQ for RESET (or vice versa).