Sei sulla pagina 1di 13

VIT

UNIVERSITY
(Estd. u/s 3 of UGC Act 1956)

Vellore 632014, Tamilnadu.India www.vit.ac.in

School of Electronics Engineering M.Tech Sensor System Technology


I year [II semester]

Microcontrollers Architecture and Organization

LAB manual

Faculty: Prof. M. Shanmugasundaram. Prof. B.Karthikeyan

VIT: A place to learn; A chance to grow

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

INDEX
Exp. No. Date Program Mark Signature

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

Date: Time:

Exercise 1

8051 IDE [KEIL]

OBJECTIVES: To learn KEIL IDE. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 2, Appendix G. MATERIALS: KEIL version 3 or KEIL version 2 WEB SITES: www.keil.com for Keil Corporation for downloading Evaluation software

Program 1 Write and assemble a program to move value 99H to register A. Then from register A move it to all registers R0 - R7. Use the simulator to single-step the program and examine the registers. Program 2 Write and assemble a program to add all the single digits of your ID number and save the result in R2. Pick 7 random numbers (all single digit) if you do not want to use your ID number. Then use the simulator to single-step the program and examine the registers.

Pre Lab Work (20) Output(20) Regularity(attendance and date of completion and sign) (10) total marks(50) Faculty in charge sign

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

Date: Time:

Exercise-2
(a) EXAMINING THE CY FLAG AND THE STACK [8051]
(b)

Data Transfer

OBJECTIVES: To analyze the way the flag bits of the PSW change. To understand the behavior of 8051 for stack instructions. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 2. MATERIALS: 8051 KEIL IDE. Program 1 Write and assemble a program to add the following data and then use the simulator to examine the CY flag. 92H, 23H, 66H, 87H, F5H Program 2 Write and assemble a program to load values into each of registers R0 - R4 and then push each of these registers onto the stack. Single-step the program, and examine the stack and the SP register after the execution of each instruction. Program 3 Write and assemble a program to: (a) Set SP = 0D, (b) Put a different value in each of RAM locations 0D, 0C, 0B, 0A, 09, and 08, (c) POP each stack location into registers R0 - R4. Use the simulator to single-step and examine the registers, the stack, and the stack pointer. Program 4 Write a program to calculate y where y = x2 + 2x + 9. x is between 0 and 9 and the look-up table for x2 is located at the address (code space) of 200H. Register R0 has the x, and at the end of the program R2 should have y. Use the simulator to change the x value and singlestep through the program, examining the registers as you go. Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

Date: Time:

Exercise-3
ARITHMETIC OPERATIONS-I

OBJECTIVES: To develop program to Add hex numbers.a Add BCD numbers. Add two multi-byte BCD numbers. Convert data from decimal to binary and hexadecimal systems. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 6. MATERIALS: 8051 KEIL IDE. Program 1 Write a program to add 10 bytes of data and store the result in registers R2 and R3. The bytes are stored in the ROM space starting at 200H. The data would look as follows: MYDATA: DB 92,34,84,129,... ;pick your own data. Notice that you must first bring the data from ROM space into the CPU's RAM, then add them together. Use a simulator to single-step the program and examine the data. Program 2 Write a program to add 10 bytes of BCD data and store the result in R2 and R3. The bytes are stored in ROM space starting at 300H. The data would look as follows: MYDATA: DB 92H,34H,84H,29H,... ;pick your own data. Notice that you must first bring the data from ROM space into the CPU's RAM, then add them together. Use a simulator to single-step the program and examine the data. Program 3 Write a program to add two multi-byte BCD numbers together and store the result in RAM locations 40H - 44H. The two multi-byte items are stored in the ROM space starting at 120H and 150H. See the following example data. ORG 120H DATA_1: DB 54H,76H,65H,98H ;number 98657654H DATA_2 DB 93H,56H,77H,38H ;number 38775693H Pick your own data for your program. Notice that you must first bring the data from ROM space into the CPU's RAM and then add them together. Use a simulator to single-step the program and examine the data.
Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date:

Exercise-

4[Assignment]
Time: ARITHMETIC OPERATIONS-II

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVES: To develop program to Convert data from hex to ASCII. Find the average of a set of hex data. To analyse the 8051 division and multiplication instructions. REFERENCES: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapters 6 or 7. MATERIALS: 8051 KEIL IDE. Program1 Write a program to get a byte of hex data from P1, convert it to decimal, and then to ASCII. For example, if P1 has FBH, which is equal to 251 in decimal, after conversion we will have 32H, 35H, and 31H. Place the ASCII result in RAM locations starting at 40H. Using a simulator, single-step the program and examine the data. Program 2 Write a program to convert 4 bytes of hex data to ASCII and place the result in RAM locations starting at 50H. The hex data is stored in ROM starting at 150H. The data is stored as follows: ORG 150H MYDATA: DB 7FH, 3CH, 54H, 2AH ;pick your own data Using a simulator, single-step the program and examine the data. Program 3 Write a program to find the average age of a group of children in a class. There are 12 children, ranging in age from 5 to 10 years old. Pick your own data. Notice that you must first bring the data from ROM space into the CPU's RAM and then add them together. Using a simulator, single-step the program and examine the data.
Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-5
SIMULATING I/O PORTS
M. Tech-SST VIT University

Microcontrollers Architecture and Organization

OBJECTIVES: To examine the I/O port operation using a simulator. To trace through a CALL subroutine using a simulator. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapters 3 and 4. MATERIALS: 8051 KEIL IDE Program 1 Write and assemble a program to toggle all the bits of P0, P1, and P2 continuously by sending 55H and AAH to these ports. Put a time delay between the "on" and "off" states. Then using the simulator, single-step through the program and examine the ports. Do not single-step through the time delay call. Program 2 Using a simulator for the program 1, examine the registers of the delay subroutine and make the delay shorter or longer by changing the register values. Program 3 Using a simulator, write a program to get a byte of data from P1 and send it to P0 and P2. Also, give a copy of it to registers R0, R1, and R2. Single-step the program and examine the ports and registers.
Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-6
HW Lab-I/O Ports

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVE: To test the 8051 system and its ports. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 4, 7, Appendix B, and Appendix C.2. MATERIALS: 8051 Trainer Kit LEDs DIP switches with pull-up resistors 8051 KEIL IDE Program 1 Test the operation of the ports of your 8051 trainer kit as follows. Wrote a Program to toggles the ports of the 8051. Use the LEDs to watch the bits of the ports toggle on and off. Make sure that the time delay in between the "on" and "off" states is long enough that you can observe each state clearly. Program 2 Test the 8051's ports for input operation as follows. Connect each bit of P1 (P1.0 P1.7) of the 8051 to DIP switches. Read Appendix C.2 very carefully to make sure that you do not damage the port. Then write and run a program to get data from P1 and send it to P2. Any change of status of the switches connected to P1 will be instantly reflected on LEDs connected to P2. The testing program could look like this. MOV MOV HERE: MOV A,P1 MOV SJMP A,#0FF ;A=FFH P1,A ;make P1 an input port ;get data from P1 P2,A ;send it to P2 HERE ;keep doing this

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-7
Timers
M. Tech-SST VIT University

Microcontrollers Architecture and Organization

OBJECTIVES: To program the 8051 timer to generate time delay. To generate a square wave using the 8051 timer. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 9. MATERIALS: 8051 KEIL IDE Program 1 Write a program using timer 0 to generate a 500 Hz square wave frequency on one of the pins of P1. Then examine the frequency using the KEIL IDE inbuilt Logic Analyzer. Program 2 Write a program using timer 1 to generate a 1 kHz square wave frequency on one of the pins of P1. Then examine the frequency using the oscilloscope.

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-8
Interfacing LCD with 8051

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVES: To understand the operation modes of an LCD. To interface the LCD controller with 8051 microcontroller REFERENCES: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 12. Dot Matrix LCD Module: Character-type DMC Series User's Manual by Optrex Corp. MATERIALS: 8051 KEIL IDE 8051 KIT 16x2 LCD. Program 1 Connect the LCD to your 8051 Kit. Then write and run a program to display your name on line 1 of the LCD (first name followed by last name with a space in between). Note: If you are not monitoring the busy flag of the LCD, put a few milliseconds delay in your program. See the discussion in Chapter 12. Program 2 Repeat Program 1 while also putting the year you graduated from high school on the second line. When you run your program, the LCD should show (for example): Line1: NAME Line2: VIT University Program 3 Write an LCD program to display your last name on the first line and the current year on the second line. Both should be in the middle of the line.

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-9
Key Pad Interfacing

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVE: To interface a 4x4 keyboard (keypad) to the 8051 Kit. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 12. MATERIALS: 8051 Kit IBM (or compatible) computer 8051 Keil IDE 4x4 keyboard In many small projects, the use of a keyboard as an input device is unavoidable. In this lab we discuss the 4x4 matrix keyboard and then show how to interface it with the 8051. Program 1 Connect the keypad to the 8051 as shown in Chapter 12 of the textbook. Write and run a program that scans your keyboard and displays any character pressed by the user on the LCD (or send it to the PC monitor). Your program must display keys 0 - 9 as numbers 0 - 9 on the PC screen while keys 10, 11, 12, 13, 14, and 15 (or you might say 0A - 0F in hex) are displayed as letters A, B, C, D, E, and F, respectively. You can modify and incorporate Program 12-1 of the textbook for your program.

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-10
Serial Communication

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVES: To write a program to transfer data to a PC serially. To write a program to receive data from a PC serially. REFERENCES: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 10. MATERIALS: 8051 KIT with MAX233 (or MAX232) 8051 KEIL IDE DB-9 RS232 connector with serial cable Program 1 After connecting (wire wrapping) the MAX233 to the 8051 as shown in Figure 10-8 in the textbook, connect your 8051 system to the PC's COM 2 port. Then write a program to transfer your last name to the PC continuously at the baud rate of 9600. On the PC side you need to use the Hyperterminal program (or Terminal in Windows 3.x) which comes with MS Windows 95 and 98. Here are the steps to set up Hyperterminal:
1. In Windows Accessory, click on Hyperterminal (if you get a modem installation option, choose "NO"). 2. Type a dummy name, and click OK. 3. For "Connect Using" select COM2 and click OK. We use COM2 since COM1 is normally used by the mouse. 4. Pick 9600 (or whatever baud rate you programmed the 8051), 8 bit data, no parity bit, and 1 stop bit. 5. Change the "Flow Control" to NONE or Xon/Xoff and click OK (definitely do not choose the hardware option).

After running your 8051 serial program, you should see your last name fill the PC screen.Program 2 After making sure that program 1 works properly, write a program to get data from the PC and display it on an LCD. If you do not have an LCD connected to the 8051, connect P1 to LEDs o and observe the incoming characters. As you press a key on the PC's keyboard, the character is sent to the 8051 serially and is displayed on LEDs. The characters displayed on LEDs are in ASCII (binary).

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Date: Time:

Exercise-11 Interrupt Programming

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

OBJECTIVES: To program the timer interrupt of the 8051. To program the serial interrupt of the 8051. To program the hardware interrupt of the 8051. REFERENCE: Mazidi and Mazidi, The 8051 Microcontroller and Embedded Systems, Chapter 11. MATERIALS: 8051 Kit with MAX232 8051 KEIL IDE Switches, LED, PC Program 1 Write an 8051 program to get data from one port and send it to another port continuously while an interrupt will do the following: One of the timers will toggle the PX.Y bit every 100 microseconds. Program 2 Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7 continuously while an interrupt will do the following: A serial interrupt service routine will receive data from a PC and display it on one of the ports. (Either connect LEDs to this port to examine the data coming in or display the received data on an LCD).

Pre Lab Work (20) Execution(20) Completion in time (10) total marks(50) Faculty in charge sign

Microcontrollers Architecture and Organization

M. Tech-SST

VIT University

Potrebbero piacerti anche