Vous êtes sur la page 1sur 163

VIT UNIVERSITY

SCHOOL OF ELECTRONICS ENGINEERING (SENSE) FALL 2012-13 Sub Code: ECE 304 MICROCONTROLLER AND APPLICATIONS LAB MANUAL

Name: Slot: Faculty In-charge: Day: Lab system no:


Reg. No.:

Student Details

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name in caps: Lab system number: Branch: Microcontroller and Applications Theory Class Handler: Prof. Microcontroller and Applications Theory Slot No. : Microcontroller and Applications Lab Class Handler: Prof. Microcontroller and Applications Lab Slot No. :
I ensure to maintain 75 % attendance in Lab classes to appear in term end lab exam without fail. I ensure to enter my Lab internal marks on time in facultys mark /attendance register.

Students Sign with date:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sl. No.

Date

Title

Completion/signed Marks Date (50)

Average Marks (50): _______ Name: Slot: Faculty Name: Record completion date (to be filled by student): Microcontroller and Applications B. Tech-ECE SENSE_VIT University Page. Number: Reg. No.: Sign:

Study of 8051 Microcontroller:

1. Architecture of 8051 microcontroller 2. Block diagram 3. Registers and Register Banks 4. PSW 5. Addressing modes 6. Types of Instruction and Instruction set 7. Pin Diagram 8. Control word formats 9. Ports of 8051 Microcontroller 10. Keil Micro vision software details

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-1
EXAMINING THE CY FLAG AND THE STACK [8051]

OBJECTIVES: To examine the flag bits of the PSW. To examine the stack. 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

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Indicate the size (8- or 16-bit) of each of the following registers. PC = A= B=

R0=

R1=

R2=

R7=

2. For Question 1, indicate the largest value (in decimal) that each register can contain. PC = A= B=

R0=

R1=

R2=

R7=

3. For Question 1, indicate the largest value (in hex) that each register can contain.

PC =

A=

B=

R0=

R1=

R2=

R7=

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result: Thus the 8051 assembly level programs are developed for the above. After implementation in Keil micro vision tool the results are verified using manual calculation.

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-2

Data Transfer

OBJECTIVES: To code a program to transfer data from RAM locations to other RAM locations. To experiment with a look-up table. REFERENCE: Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems, Chapter 5. MATERIALS: 8051 KEIL IDE Program 1 Write a program to transfer a string of data from code space starting at address 200H to RAM locations inside the CPU starting at 40H. The data is as shown below: MYDATA: DB "VIT University" Using the simulator, single-step through the program and examine the data transfer and registers.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 2 Add the following subroutine to the program 1, single-step through the subroutine and examine the RAM locations. After data has been transferred from ROM space into RAM, the subroutine should copy the data from RAM locations starting at 40H to RAM locations starting at 60H.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 3 Write a program to calculate y where y = x2 + 2x + 9. x is between 0 and 9 and the lookup 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 single-step through the program, examining the registers as you go.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Find the value of the CY flag after the execution of the following code. (a) MOV A,#85H ADD A,#92H

(b)

MOV A,#15H ADD A,#72H

(c)

MOV A,#0F5H ADD A,#52H

(d)

MOV A,#0FF INC A

2. Upon reset, what is the value in the SP register?

3. Upon pushing data onto the stack, the SP register is _____________ (decremented, incremented).

4. Upon popping data from the stack, the SP register is ___________ (decremented, incremented).

5. Can you change the value of the SP register? If yes, explain why you would want to do that.

6. The stack uses the same area of RAM as bank ______.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-3
ARITHMETIC OPERATIONS-I

OBJECTIVES: To code a program to add hex numbers. To code a program to add BCD numbers. To code a program to add two multi-byte BCD numbers. To practice converting 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.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 singlestep the program and examine the data.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Explain the difference between the following two instructions: MOVC A,@A+DPTR MOV A,@R0

2. Circle the invalid instructions. MOV A,@R1 MOVC A,@R0+DPTR MOV A,@R2 MOV @R3,A

3. Explain the difference between the following two instructions: MOV A,40H MOV A,#40H

4. Explain the difference between the following two instructions: MOV 40H,A MOV 40H,#0A

5. Give the RAM address for the following registers. A= PSW= B= SP= R0= DPL= R2= DPH=

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-4
ARITHMETIC OPERATIONS-II

OBJECTIVES: To write a program to convert data from hex to ASCII. To write a program to find the average of a set of hex data. To examine 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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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.

Program number: Aim:

page number:

Algorithm:

Sample Manual calculation for verification:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Explain the difference between the ADD and ADDC instructions.

2. Show how to perform the subtraction: 29H - 21H.

4. True or False. "DA A" must be used for adding BCD data only.

5. Can we use the "DA A" instruction to convert data such as 9CH into BCD without first performing an ADD instruction? Explain your answer.

6. Show a simple program to add 2345H and 56F8H.

7. Show a simple program to subtract 2345H from 56F8H.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-5
SIMULATING I/O PORTS

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 number: Aim:

page number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Algorithm:

Sample Manual calculation for verification:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. In the 8051, when dividing a byte by a byte what is the largest value for the numerator? What about the denominator? Give the value in both hex and decimal.

2. In the 8051, when dividing a byte by a byte what is the largest value for the quotient? What about the remainder? Give the value in both hex and decimal.

3. In the 8051, when multiplying two numbers what is the largest value for each number?

4. Explain the role of the OV flag in division and multiplication instructions.

5. In generating a square of numbers between 0 and 9 there are two methods: (a) using the MUL instruction, or (b) using a look-up table. Which one is faster in the 8051?

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-6
HW Lab-I/O Ports

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

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 Microcontroller and Applications B. Tech-ECE SENSE_VIT University Page. Number:

LEDs connected to P2. The testing program could look like this.
MOV 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

HERE: MOV

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Upon reset, all the ports of the 8051 are configured as ______ (input, output).

2. To make all the bits of a port an input port we must write ____ hex to it.

3. Which ports of the 8051 are bits addressable?

4. What does it mean for port to be "read-modify-write"?

5. Write a program to monitor P2.4 continuously. When it becomes low, it sends 55H to P1.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-7
Timers

OBJECTIVES: To program the 8051 timer. 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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Upon reset, all ports of the 8051 are configured as _____________ (output, input).

2. Which ports of the 8051 have internal pull-up resistors?

3. Which ports of the 8051 require the connection of external pull-up resistors in order to be used for I/O? Show the drawing for the connection.

4. In the 8051, explain why we must write "1" to a port in order for it to be used for input.

5. Explain why we need to buffer the switches used as input in order to avoid damaging the 8051 port.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-8
Interfacing LCD with 8051

OBJECTIVES: To understand the operation modes of an LCD. To interface and program an LCD. 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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. What is the maximum frequency that can be generated using Mode 1 if the crystal frequency is 11.0592 MHz? Show your calculation.

2. What is the maximum frequency that can be generated using Mode 2 if the crystal frequency is 11.0592 MHz? Show your calculation.

3. What is the lowest frequency that can be generated using Mode 1 if the crystal frequency is 11.0592 MHz? Show your calculation.

4. What is the lowest frequency that can be generated using Mode 1 if the crystal frequency is 11.0592 MHz? Show your calculation.

5. In mode 1, when is TFx set to high?

6. In mode 2, when is TFx set to high?

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-9
Key Pad Interfacing

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.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. How does the LCD distinguish data from instruction codes when receiving information at its data pin?

2. To send the instruction code 01 to clear the display, we must make RS = ___.

3. To send letter 'A' to be displayed on the LCD, we must make RS = ____.

4. What is the purpose of the E line? Is it an input or an output as far as the LCD is concerned?

5. When is the information (code or data) on the LCD pin latched into the LCD?

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-10
Serial Communication

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 number: Aim:

page number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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).

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 3 Modify and run the program 1 to transfer the data at the rate of 19200 baud.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. The 8051 TxD and RxD signals ________ (are, are not) TTL-compatible.

2. In this lab, what is the role of the MAX233 (MAX232) chip?

3. With XTAL=11.0592 MHz, what is the maximum baud rate for the 8051?

4. Show how to achieve the maximum baud rate in Question 3.

5. What is the role of TI and RI?

6. True or false. The 8051 can transfer data in full-duplex.

7. For full duplex, what are the absolute minimum signals needed between the 8051 and the PC? Give their names.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-11 Interrupt Programming

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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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).

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Name:

Batch:

1. Name all of the interrupts in the 8051 and their vector table addresses.

2. In timer mode 1, indicate when TF0 causes the interrupt.

3. In timer mode 2, indicate when TF0 causes the interrupt.

4. On reset, INT0 (and INT1) are _________ (edge, level) triggered.

5. On reset, which interrupt has the highest priority?

6. True or False. There is only a single interrupt for the serial data transfer.

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-12
ARITHMETIC OPERATIONS [ARM]

OBJECTIVES: To examine the flag bits of the CPSR. To code a program using ARM Arithmetic Instructions REFERENCE:
Sloss Andrew N., Symes Dominic, Wright Chris, ARM system developers guide: Designing and optimizing system software, Morgan Kaufmann, 2008.

. MATERIALS: ARM KEIL IDE. Program 1 Write and assemble a program to add the following data and then use the simulator to examine the CPSR flag. 922345H, 235678H, 662145H, 878798H, F5ABCDH

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 2 Write a program to add 10 words of data and store the result in registers R2 and R3. The bytes are stored in the ROM space [take your own starting address]

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

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 memory space into the CPU's Registers and then add them together. Using a simulator, single-step the program and examine the data.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program:

Output Verified sign by TA/TO with date: Comments

LABEL Mnemonics Operand

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Inference:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks: BEC

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Date: Time:

Exercise-13
LOAD AND STORE OPERATIONS [ARM]

OBJECTIVES:. To code a program using ARM Load and store Instructions To convert the C templates into ARM assembly code. REFERENCE:
Sloss Andrew N., Symes Dominic, Wright Chris, ARM system developers guide: Designing and optimizing system software, Morgan Kaufmann, 2008.

MATERIALS: ARM KEIL IDE. Program 1


Assume an array of 25 words. A compiler associates variables x and y with registers r0 and r1, respectively. Assume that the base address for the array is located in r2. Translate this C statement/assignment using the post-indexed form: x = array [5] + y Now try writing it using the pre-indexed form.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program: C Program

Output Verified sign by TA/TO with date: Comments

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 2
Assume an array of 25 words. A compiler associates y with r1. Assume that the base address for the array is located in r2. Translate this C statement/assignment using the post-indexed form: array [10] = array[5] + y Now try it using the pre-indexed form.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program: C program

Output Verified sign by TA/TO with date: Comments

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 3
Write ARM assembly to perform the following array assignment in C: for ( i = 0; i <= 10; i++) { a[i] = b[i] + c; } Assume that r3 contains i, r4 contains c, the starting address of array a is in r1, and the starting address of array b is in r2.

Program number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program: CProgram

Output Verified sign by TA/TO with date: Comments

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Inference:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Pre Lab Work(20) : Regularity(Attendance date of completion sign)(10): Output (20): BEC and &

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Total Marks(50): Faculty in charge Sign:

Date: Time:

Exercise-14
GPIO SIMULATIONS [ARM]

OBJECTIVES:. To code a program using C for ARM Microcontroller LPC2XXX REFERENCE:


Sloss Andrew N., Symes Dominic, Wright Chris, ARM system developers guide: Designing and optimizing system software, Morgan Kaufmann, 2008.

. MATERIALS: ARM KEIL IDE. Program 1 Write a C program to toggle all the bits of P0 continuously by sending appropriate values 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 number: Aim:

page number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample input and output:

Inference:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program: C Program

Output Verified sign by TA/TO with date: Comments

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Program 2 Using Keil IDE, write a program to get a byte of data from P1 and send it to P0 .Also, give a copy of it to registers R0, R1, and R2. Single-step the program and examine the ports and registers.

Program page number: Aim:

number:

Algorithm:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Sample Manual calculation for verification:

Sample input and output:

Inference:
Microcontroller and Applications B. Tech-ECE SENSE_VIT University Page. Number:

Program: C Program

Output Verified sign by TA/TO with date: Comments

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number:

Inference:

Result:

Exp Date: Completion/Sign Date: Name of the student: Reg. No: Microcontroller and Applications B. Tech-ECE BEC SENSE_VIT University Page. Number:

Pre Lab Work(20) : Regularity(Attendance and date of completion & sign)(10): Output (20): Total Marks(50): Faculty in charge Sign: Remarks:

Microcontroller and Applications

B. Tech-ECE

SENSE_VIT University Page. Number: