59
Microprocessor and System Lab Department of Computer Engineering Khwaja Fareed University of Engineering and Information Technology Rahim Yar Khan, Pakistan Preliminary version – 13 July 2017

Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Embed Size (px)

Citation preview

Page 1: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Microprocessor and System Lab

Department of Computer Engineering

Khwaja Fareed University of Engineering andInformation Technology

Rahim Yar Khan, Pakistan

Preliminary version – 13 July 2017

Page 2: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Contents

1 Lab 1 11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.2 Program Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.3 Input and MAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.4 RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1.5 Instruction Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1.6 Controller-Sequencer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1.7 Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.1.8 The Adder-Subtractor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.1.9 B Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.1.10 Output Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.1.11 Binary Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.12 Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Lab 2 - Registers used in Fetch Cycle 72.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Clock Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.4 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.5 Components Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.6 Program counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.7 MAR (Memory Address Register) . . . . . . . . . . . . . . . . . . . . . . . . . . 102.8 2-to-1 Nibble Multiplexer (Input unit)) . . . . . . . . . . . . . . . . . . . . . . . . 102.9 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Lab 3 : Introduction to 8051 Microcontroller 133.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.4 Microcontroller with Minimum Connections . . . . . . . . . . . . . . . . . . . . 133.5 In System Programming (ISP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.6 Precautions For Entire Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.7 Activities and Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4 Lab 4 : LED Pattern 184.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.4 Loops and Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.5 Activities and Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

ii

Preliminary version – 13 July 2017

Page 3: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Contents iii

5 Lab 5:Seven Segment Display 215.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.4 Seven Segment Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.5 Activities and Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6 Lab 6:Timers & Counter Programming 256.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256.4 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

6.4.1 Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256.4.2 Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266.4.3 Timer Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266.4.4 TCON (Timer Control Register): . . . . . . . . . . . . . . . . . . . . . . . 266.4.5 TMOD (Timer Mode Register) . . . . . . . . . . . . . . . . . . . . . . . . 26

6.5 Activities & Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

7 Lab 7 : Serial port programming 297.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297.4 Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

7.4.1 SCON Register: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307.5 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

8 Lab 9 : Interrupts programming 328.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.4 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

8.4.1 INTERRUPTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.4.2 INTERRUPT ENABLE REGISTER (IE): . . . . . . . . . . . . . . . . . . . 338.4.3 INTERRUPT PRIORITIES: . . . . . . . . . . . . . . . . . . . . . . . . . . 33

8.5 AActivities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

9 Lab 9 : LCD interfacing 369.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369.4 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

9.4.1 LCD(Liquid Crystal Display) . . . . . . . . . . . . . . . . . . . . . . . . . 369.5 LCD COMMAND CODES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379.6 Busy Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379.7 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Preliminary version – 13 July 2017

Page 4: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

iv Contents

10 Lab 10 : Keypad Interfacing 4010.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4010.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4010.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4010.4 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

11 Lab 12:ADC interfacing 4411.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4411.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4411.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4411.4 ADC 0804 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4411.5 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

12 Lab 12: DAC interfacing 4812.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4812.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4812.3 Equipment Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4812.4 DAC 0808 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4812.5 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

13 Lab 13: Introduction to PIC18F458 Microcontroller, Training board and simulationsoftware 5113.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5113.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5113.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5113.4 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

14 Lab 14: Loops and Subroutines in PIC Microcontroller 5414.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5414.2 Pre-Lab Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5414.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5414.4 Activities and Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Preliminary version – 13 July 2017

Page 5: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 1

Lab 1

1.1 Introduction

The SAP (Simple-As-Possible) is a computer designed for beginners. The main purpose ofSAP is to introduce all the crucial concepts behind computer operation. SAP- 1 is the firststage in the evolution toward modern computers. Although primitive, SAP is considered abig step for a beginner.

1.1.1 Architecture

Figure12.2 shows the architecture of SAP-1, a bus-organized computer. All register outputsto the 8 bit W-bus are three states; this allows orderly transfer of data. All other registeroutputs are two state; these outputs continuously drive the boxes they are connected to. Thelayout of Fig.12.2 emphasizes the registers used in SAP- 1. For this reason, no attempt hasbeen made to keep all control circuits in one block called the control unit, all input-outputcircuits in another block called the I/O unit, etc

Figure 1.1: Architecture for SAP-1

1

Preliminary version – 13 July 2017

Page 6: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

2 Lab 1

1.1.2 Program Counter

• 1. The program is stored at the beginning of the memory with the first instruction atbinary address 0000, the second instruction at address 0001, the third at address 0010,and so on.

• The program counter, which is part of the control unit, counts from 0000 to 1111.

• Its job is to send to the memory the address of the next instruction to be fetched andexecuted. It does this as follows.

– The program counter is reset to 0000 before each computer run.

– When the computer run begins, the program counter sends address 0000 to thememory.

– The program counter is then incremented to get 0001.

– After the first instruction is fetched and executed, the program counter sends ad-dress 0001 to the memory.

– Again the program counter is incremented.

– After the second instruction is fetched and executed, the program counter sendsaddress 0010 to the memory.

• In this way, the program counter is keeping track of the next instruction to be fetchedand executed.

• The program counter is like someone pointing a finger at a list of instructions, sayingdo this first, do this second do this third, etc.

• This is why the program counter is sometimes called a pointer; it points to an addressin memory where something important is being stored

1.1.3 Input and MAR

• Below the program counter is the input and MAR block.

• It includes the address and data switch registers.

• These switch registers, which are part of the input unit, allow you to send 4 addressbits and 8 data bits to the RAM.

• As you recall, instruction and data words are written into the RAM before a computerrun.

• The memory address register (MAR) is part of the SAP-1 memory.

• During a computer run, the address in the program counter is latched into the MAR.

• A bit later, the MAR applies this 4-bit address to the RAM, where a read operation isperformed.

Preliminary version – 13 July 2017

Page 7: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§1.1 Introduction 3

1.1.4 RAM

• The RAM is 16x8 static TTL RAM.

• It can be programmed by means of address and data switch registers.

• During a computer operation, the RAM receives a 4-bit address from MAR and a readoperation is performed.

• In this way, an instruction or data word stored in RAM is placed on the W bus for usein some other part of the computer.

1.1.5 Instruction Register

• The instruction register is part of the control unit.

• To fetch an instruction from the memory the computer does a memory read operation.

• This places the contents of the addressed memory location on the W bus.

• At the same time, the instruction register is set up for loading on the next positive clockedge.

• The contents of the instruction register are split into two nibbles.

• The upper nibble is a two-state output that goes directly to the block labeled "Controller-sequencerâAI.

• The lower nibble is a three-state output that is read onto the W bus when needed.

1.1.6 Controller-Sequencer

• The lower left block contains the controller-sequencer

• Before each computer run, CLR a signal is sent, to the program counter and a CLRsignal to the instruction register.

• This resets the program counter to 0000 and wipes out the last instruction in instructionregister

• A clock signal CLK is sent to all buffer registers; this synchronizes the operation of thecomputer, ensuring that things happen when they are supposed to happen. In otherwords, all register transfers occur on the positive edge of a common CLK signal.

• Notice that a CLK signal also goes to the program counter

• The 12 bits that come out of the controller-sequencer form a word controlling the restof the computer (like a supervisor telling others what to do.) The 12 wires carrying thecontrol word are called the control bus.

• The control word has the format of CON = This word determines how the registerswill react to the next positive CLK edge. For instance, a high EP and a low, LM meanthat the contents of the program counter are latched into the MAR on the next positiveclock edge.

• As another example, a low CE and a low LA mean that the addressed RAM word willbe transferred to the accumulator on the next positive clock edge.

Preliminary version – 13 July 2017

Page 8: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

4 Lab 1

1.1.7 Accumulator

• The accumulator (A) is a buffer register that stores intermediate answers during a com-puter run. In12.2 the accumulator has two outputs.

• The two-state output goes directly to the adder-Subtractor.

• The three-state output goes to the W bus.

• Therefore, the 8-bit accumulator word, continuously drives the adder-Subtractor thesame word appears on the W bus when EA is high.

1.1.8 The Adder-Subtractor

• SAP-1 uses a 2’s-complement adder-Subtractor. When Su is low in Fig. 10-1, the sumout of the adder-Subtractor is:

• When Su is high, the difference appears: (Recall that the 2’s complement is equivalentto a decimal sign change.)

• The adder-Subtractor is asynchronous (un-clocked); this means that its contents canchange as soon as the input words change.

• When is high, these contents appear on the W bus.

1.1.9 B Register

• The B register is another buffer register.

• It is used in arithmetic operations. A low LB and positive clock edge load the word onthe W bus into the B register.

• The two-state output of the B register drives the adder-Subtractor, supplying the num-ber to be added or subtracted from the contents of the accumulator.

1.1.10 Output Register

• At the end of a computer run, the accumulator contains the answer to the problembeing solved.

• At this point, we need to transfer the answer to the outside world.

• This is where the output register is used. When EA is high and L0 is low, the nextpositive clock edge loads the accumulator word into the output register.

• The output register is often called an output port because processed data can leave thecomputer through this register.

• In microcomputers the output ports are connected to interface circuits that drive pe-ripheral devices like printers, cathode-ray tubes, teletypewriters, and so forth. (Aninterface circuit prepares the data to drive each device.)

Preliminary version – 13 July 2017

Page 9: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§1.1 Introduction 5

1.1.11 Binary Display

• The binary display is a row of eight light-emitting diodes (LEDs).

• Because each LED connects to one flip-flop of the output port, the binary display showsus the contents of the output port.

• Therefore, after we’ve transferred an answer from the accumulator to the output port,we can see the answer in binary form.

1.1.12 Instruction Set

• A computer is a useless pile of hardware until someone programs it.

• This means loading step-by-step instructions into the memory before the start of acomputer run.

• The SAP-I instruction set consist on five instructions as given below;

– LDA

– ADD

– SUB

– OUT

– HLT

Preliminary version – 13 July 2017

Page 10: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

6 Lab 1

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 1.1: Lab Rubric

Preliminary version – 13 July 2017

Page 11: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 2

Lab 2 - Registers used in FetchCycle

2.1 Objectives

• To build up a circuit that generates Clear and the Clock signal, that is part of the ControlUnit of SAP-1 computer.

• To make the circuit of program counter for sap-1 that generates a 4-bit address code ofmemory, Input MAR and 2 to 1 Multiplexer

• To make the circuit of 16x8 RAM and Instruction-Register.

2.2 Objectives

• Quad two input NAND gate IC, 74LS 00 3

• Quad three input NAND gate IC, 74LS1 0 1

• Hex Inverter IC, 74LS04 1

• 555 Timer IC 1

• Dual J-K Flip Flop 1

• Push button switches 2

• Connecting wires

7

Preliminary version – 13 July 2017

Page 12: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

8 Lab 2 - Registers used in Fetch Cycle

2.3 Clock Circuit

The clock circuit as is shown in the figure 2.1 consists of mainly a 555 Timer and a J-K flipflop. 555 Timer produces a 2-kHz clock signal with a 75 % duty cycle at its output, and a J-Kflip flop, that divides the signal down to 1-kHz and also produces a 50% duty cycle.

Clock Buffers, which are two inverters, are used to produce the final clock signal, one CLKand other inverted CLK signal. These are used here so that the clock signal being generatedis able to drive low-power Schottky TTL loads.

Clear- Start Debouncer produces two outputs, CLR for the Instruction Register and theinverted CLR for the Program Counter and Ring Counter. S5 is a push button switch. Whendepressed, it goes to the clear position generating a high CLR and a low CLR. When S5 isreleased, it returns to the START position, producing a low CLR and a high CLR.

SAP-1 runs in either of the two modes, manual or automatic. In manual you press andrelease S6 to generate one clock pulse. When S6 is depressed, CLK is high; when releasedCLK is low. In other words, the single-step debouncer generates T states one at a time asyou press and release the button. This allows you to step through the different T states whiletroubleshooting or debugging.

Switch S7 is a single pole double throw SPDT switch that can remain in either the MAN-UAL or the AUTO position. When in Manual the single-step button is active. When in AUTOmode, the computer runs automatically. Two of the NAND gates are used to debounce theMANUAL-AUTO switch.

2.4 Procedure

• Connect the circuit as shown in the circuit diagram.

• Check the signals with the oscilloscope and get your work verified by your Lab instruc-tor.

• You will be graded for this Lab on the output and functionality of your circuit.

• For connections refer to the Pin configurations of the ICs.

2.5 Components Required

• Dual JK Flip Flop IC, 74LS107 2

• Quad three state switch IC, 74LS126 1

• 4 bit D-type Register, 74LS173 1

• Quad 2-to-1 Data Selector/ Multiplexer IC, 74LS157 1

• Connecting wires

Preliminary version – 13 July 2017

Page 13: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§2.6 Program counter 9

Figure 2.1: Clock Circuit for SAP âAS 1

2.6 Program counter

The program counter, which is a part of control unit, counts according to the available RAM-memory. Its job is to send memory the address of the next instruction to be fetched andexecuted. Program counter is also called pointer sometimes, as it works like pointing at alist of instructions stored at different addresses in the memory, saying do this first, do thissecond etc.

Preliminary version – 13 July 2017

Page 14: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

10 Lab 2 - Registers used in Fetch Cycle

2.7 MAR (Memory Address Register)

Chip C4, is a 74LS173, 4 bit buffer register.It serves as the MAR. Notice that pins 1 and 2 are grounded; this converts the three-state

output to a two-state output.In other words, the output of the MAR is not connected to the W bus, and so there’s no

need to use the three-state output.

2.8 2-to-1 Nibble Multiplexer (Input unit))

Chip C5 is a 74LS157 2-to-1 nibble multiplexer.The left nibble (pins 14, 11, 5 & 2) come from the address switch register S1 (these are just

4 DIP switches of your trainer and will be used to manually program your RAM).The right nibble (pins 13, 10, 6, 3) comes from the MAR.The RUN-PROG switch S2 selects the nibble to reach to the output of C5.When S2 is in the PROG position (i.e. when it is low), the nibble out of the address switch

register is selected.On the other hand, when S2 is in the RUN position (i.e. when it is high), the output of

the MAR is selected.

2.9 Procedure

Connect the circuit as shown in the diagram.

Clear Clk

Data Enable Data OutputG1

G’2 D QG’1

1 X X X X 00 0 X X X Qo0 POS 1 X X Qo0 POS X 1 X Q00 POS 0 0 0 00 POS 0 0 1 1

Table 2.1: Truth table for 74LS173

Strobe G’ Select A’/B A B Output Y

1 X X X 00 0 0 X 00 0 1 X 10 1 X 0 00 1 X 1 1

Table 2.2: Truth Table for 74LS157

How to check the output: Connect CP, EP, CLR to logic level 1 and LM to logic level0. Connect CLK and CLK to the output of push button of trainer board (A AND A OR B

Preliminary version – 13 July 2017

Page 15: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§2.9 Procedure 11

AND B). Now the output of the 74LS157 will be A0,A1,A2 and A3 when Run/prog switch isconnected to logic 0, and the output of 74LS157 will be a 4 bit counter that will count from 0to 15 on each clock pulse when Run/prog switch is connected to logic level 1.

Figure 2.2: Program Counter and MAR

Preliminary version – 13 July 2017

Page 16: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

12 Lab 2 - Registers used in Fetch Cycle

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 2.3: Lab Rubric

Preliminary version – 13 July 2017

Page 17: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 3

Lab 3 : Introduction to 8051Microcontroller

3.1 Objective

• To examine and use 8051 microcontroller, assembler and simulator.

• To learn in system programming (ISP) of microcontroller.

3.2 Pre-Lab Reading

Chapter 1, 2, 8, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

3.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 3.1: Components Required

3.4 Microcontroller with Minimum Connections

8051 microcontroller has 40 pins, out of which 32 pins are for four eight bit I/O ports. Apartfrom general usage, port 3 is also used for specific tasks and each pin of this port has specialpurpose. A crystal oscillator is attached at pin 18 and 19 along with capacitors. In case themicrocontroller is to be derived from external clock, pin 18 is left with no connection andexternal clock is given at pin 19. Vcc is applied at pin 40 and 31 while pin 20 is connected toground. In case pin 31 is left low, microcontroller will not use internal ROM to run, rather itwill execute the program from external ROM (if connected). Thus in normal case, when the

13

Preliminary version – 13 July 2017

Page 18: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

14 Lab 3 : Introduction to 8051 Microcontroller

program is written in internal ROM, EA pin is given high logic. Pin 9 is RESET. If this pin iskept high for at least two machine cycles, microcontroller resets and terminates all activities.

3.5 In System Programming (ISP)

In-System Programming (ISP) is performed without removing the microcontroller from thesystem. The In-System Programming (ISP) facility consists of a series of internal hardwareresources coupled with internal firmware to facilitate remote programming of the microcon-troller through the serial port. This firmware is embedded within each P89C51RB2/RC2/RD2Hxxdevice. The ISP function uses five pins:TxD, RxD, VSS, VCC, andVPP as shown in figure 1.1.When the microcontroller programs its own Flash memory, all of the low level details arehandled by code that is permanently contained in a 1-kbyte Boot ROM that is separate fromthe Flash memory. A user program simply calls the common entry point with appropriateparameters in the Boot ROM to accomplish the desired operation. Boot ROM operationsinclude things like: erase block, program byte, verify byte, program security lock bit, etc.The Boot ROM overlays the program memory space at the top of the address space fromFC00 to FFFF hex, when it is enabled. If the flash memory of microcontroller is completelyerased, Boot ROM will also be erased which will make our microcontroller useless. Suchmicrocontroller will not be programmed by ISP. Therefore, never erase full memory blocksof microcontroller. Figure 1.2 shows flash memory configuration and position of Boot ROMin flash memory of microcontroller.

Figure 3.1: Flash Memory Configuration

Preliminary version – 13 July 2017

Page 19: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§3.6 Precautions For Entire Course 15

3.6 Precautions For Entire Course

• Do not erase full memory blocks of the microcontroller.

• Remember to initialize the ports of the microcontroller.

• Do not at any point draw more than 26mA from the microcontroller.

3.7 Activities and Exercises

• You are required to make this circuit on breadboard and check the waveform at pin 19using oscilloscope. Verify that its frequency is equal to 12 MHz and show it to yourinstructor. Draw the diagram of 8051 with minimum connections in space providedbelow.

• This task is designed to get you familiar with ASEM-51 assembler. Write a simpleassembly language code in which you move a value in register A. Then from registerA, move this value to registers R0-R7. Save this file as .asm and generate .hex file andsimulate it. Write the code in following space. A microcontroller simulator helps inviewing the inside of a microcontroller. Hex file of code is loaded in the simulator whichshows the code in âAŸdisassembled code windowâAZ. Values of different registers anddata in RAM is also shown and updated at each step of the code.

Preliminary version – 13 July 2017

Page 20: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

16 Lab 3 : Introduction to 8051 Microcontroller

• Write an assembly language code in which a value is moved in register A. Then fromregister A, 5 is added to this value and moved to register R0. Keep adding 5 and movethe data from R1 to R7 registers. Now load the hex file of this code in the simulatorand use the simulator to single step the program. Examine and write down the valuesof registers on each step and show to your instructor.

Preliminary version – 13 July 2017

Page 21: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§3.7 Activities and Exercises 17

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 3.2: Lab Rubric

Preliminary version – 13 July 2017

Page 22: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 4

Lab 4 : LED Pattern

4.1 Objective

• To learn to use loops and subroutines for programming 8051 microcontroller.

• To learn on/off leds using loops and subroutines.

4.2 Pre-Lab Reading

Chapter 3 Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

4.3 Equipment Required

InstrumentsOscilloscope

8051 ETK TrainerDC Power Supply

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

LEDs 8 red colored

Table 4.1: Equipment Required

4.4 Loops and Subroutines

In the sequence of instructions to be executed, it is often necessary to transfer programcontrol to a different location. There are many instructions in the 8051 to achieve this. Thislab covers the control transfer instructions available in 8051 Assembly language. Repeating asequence of instructions a sequence of instructions a certain number of times is called a loop.The loop is most widely used action that any microprocessor performs. In the 8051, the loopaction is performed by the instruction DJNZreg, label. Another control transfer instructionis the CALL instruction, which is used to call a subroutine. Subroutines are often used to

18

Preliminary version – 13 July 2017

Page 23: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§4.5 Activities and Exercises 19

perform tasks that need to be performed frequently. This makes a program more structuredin addition to saving memory space. In the 8051 microcontroller, there are two instructionsfor call: LCALL and ACALL. Deciding which to use depends on the target address.

4.5 Activities and Exercises

• Connect 8 leds with port 1 of 8051 at breadboard and write the code which shows upcounter from 0 to 255. Show output to your instructor.

• Write a code which generates a square wave of central frequency 10 KHz and dutycycle of 50%. Explain mathematical calculations for time setting and show the outputwave on oscilloscope.

Preliminary version – 13 July 2017

Page 24: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

20 Lab 4 : LED Pattern

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 4.2: Lab Rubric

Preliminary version – 13 July 2017

Page 25: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 5

Lab 5:Seven Segment Display

5.1 Objective

• To interface 7-segment display through DM 74LS47 IC with microcontroller.

• To interface 7-segment display without decoder.

5.2 Pre-Lab Reading

Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

5.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 5.1: Components Required

21

Preliminary version – 13 July 2017

Page 26: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

22 Lab 5:Seven Segment Display

5.4 Seven Segment Display

The pin configuration for seven segment display is given below:

Figure 5.1: Pin Configuration

5.5 Activities and Exercises

• Write and run an assembly language code to display 0 to 9 on a 7-segment displaywithout using a decoder IC. The increment should be after every second.

Preliminary version – 13 July 2017

Page 27: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§5.5 Activities and Exercises 23

• Write and run an assembly language code to display 0 to 99 on two 7-segment displaysusing 74LS47 BCD to 7-segment driver IC. There should be no invalid states. Showoutput to your instructor.

Preliminary version – 13 July 2017

Page 28: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

24 Lab 5:Seven Segment Display

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 5.2: Lab Rubric

Preliminary version – 13 July 2017

Page 29: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 6

Lab 6:Timers & CounterProgramming

6.1 Objective

• To program timer of 8051 microcontroller.

• To use 8051 microcontroller as event counter.

6.2 Pre-Lab Reading

Chapter 9, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

6.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 6.1: Components Required

6.4 Theory

6.4.1 Timers

The 8051 microcontroller has two timers: Timer 0 and Timer 1. They are used to generatetime delay. Both Timer 0 and Time 1 are 16 bits wide. Since the 8051 has an 8-bit architecture,each 16-bit timer is accessed as two separate registers of low byte and high byte. In Timeruse, the 8051’s crystal is used as the source of the frequency.

25

Preliminary version – 13 July 2017

Page 30: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

26 Lab 6:Timers & Counter Programming

6.4.2 Counter

The 8051 microcontroller has two counters. They are used to count events happening outsidethe microcontroller. When timer/counter is used as a counter, it is a pulse outside the 8051that an increment the TH, TL registers. In counter mode, TMOD and TH, TL registers arethe same as for the timer.

6.4.3 Timer Modes

There are four timer modes in 8051. A timer or counter function and modes are selected bywriting appropriate bits in the SFR (special function register) , called the timer mode register(TMOD) whereas the control of timer operation is done through the SFR , called the timercontrol register (TCON) . These SFRs are shown in following tables.

6.4.4 TCON (Timer Control Register):

TCON register is bit addressable, as indicated below:

Table 6.2: Add captionTCON.7 TCON.6 TCON.5 TCON.4 TCON.3 TCON.2 TCON.1 TCON.0

TF1 TR1 TF0 TRO IE1 IT1 IE0 IT0

Table 6.3: Add captionTCON.7 TF1 Timer 1 overflow flag, set when timer overflowsTCON.6 TR1 Timer 1 run control bitTCON.5 TF0 Timer 0 overflow flag, set when timer 0 overflowsTCON.4 TRO Timer 0 run control bitTCON.3 IE1 Interrupt 1TCON.2 IT1 Timer interrupt 1TCON.1 IE0 Interrupt 0 flagTCON.0 IT0 Timer 0 interrupt ,IT=0 , low level trigger ,IT0=1 edge trigger

6.4.5 TMOD (Timer Mode Register)

TMOD register is bit addressable, as indicated below:

Table 6.4: Add captionTMOD.7 TMOD.6 TMOD.5 TMOD.4 TMOD.3 TMOD.2 TMOD.1 TMOD.0

GATE C/T M1 M0 GATE C/T M1 M0

6.5 Activities & Exercise

• Following code use Timer 0 in mode 2 and toggles port 2 after every 1 second. Explaineach step of the code to your instructor and fill the blank spaces. Run the code inmicrocontroller and verify result.

Preliminary version – 13 July 2017

Page 31: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§6.6 Summary 27

Table 6.5: Add captionORG 00HMOV P2, #0FFH port 2 is made _______port.MOV A, #0FFH contents of P2=_____, A=________TMOD, # 00000010B MOV Timer ____ and mode ___is used.AGN:MOV R0, #04 Time to execute this instruction______AG2: MOV TH0, #250 Time to execute this instruction______SETB TR0 TL0 timer is ________JNB TF0, $ loop will exit when________CLR TR0 TL0 timer is ________CLR TF0 TCON.5=______DJNZ R0, AG2 Jump if ________CPL A contents of A_____MOV P2, A contents of A_____JMP AGNEND

• Write a code which generates a square wave of central frequency 10 KHz and dutycycle of 70%. Use timer mode 1. Explain mathematical calculations for timer settingand show the output wave on oscilloscope.

• Timers in 8051 can also be used as event counter for events happening outside micro-controller. When C/T bit of TMOD register is set, timer acts as counter. In this case thecounter counts up as the pulses are fed from pins P3.4 and P3.5 for timer 0 and timer1 respectively. Write an assembly language code that counts the pulse applied at P3.4for 1 second and move the result on port 2. Use timer 1 to create a delay of 1 secondafter which the count is checked and reset. Verify your program by applying signals ofdifferent frequency and check their count.

6.6 Summary

Preliminary version – 13 July 2017

Page 32: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

28 Lab 6:Timers & Counter Programming

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 6.6: Lab Rubric

Preliminary version – 13 July 2017

Page 33: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 7

Lab 7 : Serial port programming

7.1 Objective

To use 8051 microcontroller for serial communication.

7.2 Pre-Lab Reading

Chapter 10, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

7.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 7.1: Components Required

7.4 Serial Communication

In serial communication, the data is sent one bit at a time in contrast to parallel communica-tion, in which the data is sent a byte or more at a time. Serial communication of 8051 is thetopic of our lab. The 8051 has serial communication capability built into it, thereby makingpossible fast data transfer using only a few wires. 8051 supports a full duplex serial port.8051has TXD and RXD pins for transmission and reception of serial data respectively. The 8051serial communication is supported by RS232 standard. Communication between two micro-controllers and multiprocessor communication is also possible. In serial transmission, baudrate is one important factor. The baud rate is reciprocal of the time to send one bit. Baud rateis need not be equal to number of bits per second .This is because each byte is preceded by astart bit and followed by a one stop bit .The start and stop bits are used to synchronize theserial receivers . The data byte is always transmitted with least significant bit first. For error

29

Preliminary version – 13 July 2017

Page 34: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

30 Lab 7 : Serial port programming

checking purpose it is possible to include a parity bit as well, just prior to the sop bit .Thusthe bits are transmitted at specific time intervals determined by the baud rate. For error freeserial communication it is necessary that the baud rate, the number of data bits, the numberof stop bits, and the presence and absence of a parity bit along with its status be the same attransmitter and receiver ends. The basic mechanism of serial transmission is that a data bytein a parallel form is converted into serial data stream. Along with some more bits like start,stop and parity bits, a serial data frame is sent over a line. There are four modes of serialdata transmission in 8051.In each of these modes, it is important to decide the baud rate, theway in which serial data frame is sent and any other information, etc. What is common in allthese modes is the use of SFR called SBUF, for transmission as well as reception. The data tobe transmitted must be transferred to SBUF.

7.4.1 SCON Register:

One more SFR that controls the serial communication is the serial control register SCON.Bits SM0 and SM1 in SCON define serial port mode. Bit SM2 enables the multiprocessorcommunication in mode 2 and 3. Transmission is initiated by the execution of any instructionthat uses SBUF as the destination.

Table 7.2: Add captionSCON.7 SCON.6 SCON.5 SCON.4 SCON.3 SCON.2 SCON.1 SCON.0

SM0 SM1 SM2 REN TB8 RB8 TI RI

Table 7.3: Add captionSCON bit Description

SM0 Serial communication modeSM1 Serial communication modeSM2 In mode 2 and 3 , if set , this will enable multiprocessor communicationREN (Receive enable ) Enable serial receptionTB8 This is the 9th data bit that is transmitted in modes 2 and 3

RB8 9th data bit that is received in modes 2 and 3.it is not used in mode 0 .in mode 1, if SM2 =0,then RB8 is the stop bit that is received

TI Transmit interrupt flag ,set by hardware , must be cleared by software

Table 7.4: Add captionSM0 SM1 MODE Description Baud Rate

0 0 0 8-bit shift register mode fosc /120 1 1 8-bit UART Variable (set by timer 1)1 0 2 9-bit UART fosc/164 or fosc/321 1 3 9-bit UART Variable (set by timer 1)

7.5 Activities and Exercise

• Serial pins of 8051 microcontroller are connected to serial port of PC using MAX232 IC.Write a code which sends your name and registration number from microcontroller to

Preliminary version – 13 July 2017

Page 35: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§7.5 Activities and Exercise 31

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 7.5: Lab Rubric

the HyperTerminal program on the PC. Set the baud rate at 9600 bps. Write the runningcode in following space provided.

• Connect two microcontrollers serially. Transmit incremental values from 0 to 255 afterevery second serially from one microcontroller to the other. On receiving, the micro-controller shows the value on port 2. Use timer 0 to create delay of 1 second. Set thebaud rate at 9600 bps.

Preliminary version – 13 July 2017

Page 36: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 8

Lab 9 : Interrupts programming

8.1 Objective

To learn interrupt programming of 8051 microcontroller.

8.2 Pre-Lab Reading

Chapter 11, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

8.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 8.1: Components Required

8.4 Theory

8.4.1 INTERRUPTS

A single microcontroller can serve several devices. There are two ways to do that: interruptsor polling. In the interrupt method, whenever any device needs its service, the device notifiesthe microcontroller by sending it can interrupt signal. Upon receiving an interrupt signal,the microcontroller interrupts whatever it is doing and serves the device. The programassociated with the interrupt is called the interrupt service routine (ISR) or interrupt handler.In polling, the microcontroller continuously monitors the status of a given device; when thestatus condition is met, it performs the service. After that, it moves on to monitor the nextdevice until each one is serviced. There are five interrupts in 8051which are shown in thefollowing table.

32

Preliminary version – 13 July 2017

Page 37: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§8.4 Theory 33

Table 8.2: Add captionInterrupt Flag Affected Vector Cause Of Interrupt (If Enabled)External interrupt 0 IE0 003H A high to low transition on pin INT0Timer /counter 0 interrupt TF0 00BH Overflow of timer/counter 0External interrupt 1 INT pin IE1 0013H A high to low transition on pin INT1Timer /counter 1 interrupt TF1 001BH Overflow of timer /counter 1Serial port RI+TI 0023H Either TI or RI flag is set

8.4.2 INTERRUPT ENABLE REGISTER (IE):

The interrupt enable register allows the programmer to enable interrupts as needed. Thisregister IE is bit addressable. Enable all (EA) bit allows disabling the whole interrupt opera-tion. If cleared. Thus, it acts as a master control bit for any of the interrupts. The advantageof this facility is that, just by a single bit, one can control over all the interrupt sources. Forany particular interrupt to occur, bit EA and corresponding bit must be set. For example incase of serial interrupt bit EA and bit ES must be set.

Table 8.3: Add captionIE.7 IE.6 IE.5 IE.4 IE.3 IE.2 IE.1 IE.0EA âAe âAe ES ET1 EX1 ET0 EX0

Table 8.4: Add caption

EA (Enable All) 0 = Disable all interrupts,1= Allows each of individual interrupts to be enabled.

ES Enable/Disable serial port interrupts,0=Disable , 1= Enable (provided EA=1)

ET1 Enable/Disable timer interrupt 1;0=Disable , 1= Enable (provided EA=1)

EX1 Enable/Disable External interrupt 1;0=Disable , 1= Enable (provided EA=1)

ET0 Enable/Disable timer interrupt 0;0=Disable , 1= Enable (provided EA=1)

EX0 Enable/Disable external interrupt 1;0=Disable , 1= Enable (provided EA=1)

8.4.3 INTERRUPT PRIORITIES:

User can program the interrupt priority levels by setting or clearing the bits in SFR calledinterrupt priority register (IP). IP register is also bit addressable. If the bit is set then thatparticular interrupt will have high priority. A high interrupt can interrupt the low priorityinterrupt. High priority interrupt will be served first. If the same priority level interruptsrequest simultaneously, then within each priority level there is a polling structure due to theinherent priority in the order. Shown in the following table

Note that the priority within level structure is used only to distinguish the requests ofthe same priority levels. The first instruction enables both interrupts, namely, the externalinterrupt 1 and the timer 1 interrupt. The instruction SETB PT1 assigns high priority to the

Preliminary version – 13 July 2017

Page 38: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

34 Lab 9 : Interrupts programming

Table 8.5: Add captionIP.7 IP.6 IP. 5 IP.4 IP.3 IP.2 IP.1 IP.0X X PT2 PS PT1 PX1 PT0 PX0

Table 8.6: Add captionIP.5 PT2 —IP.4 PS Serial interrupt priorityIP.3 PT1 Timer 1 interruptIP.2 PX1 External interruptIP.1 PT0 Timer 0 interruptIP.0 PX0 External interrupt 0

timer interrupt. So, if both of them request simultaneously, then the timer interrupt will beserved first.

8.5 AActivities and Exercise

• Write a code to turn on all LEDâAZs using port 2 for 3 seconds on receiving an externalinterrupt 0.

• Write a code which generates a square wave of central frequency 10 KHz on P1.1 usingtimer 0 in interrupt mode.

• Also receive serial data sent from HyperTerminal of PC using serial interrupt and dis-play this data on LEDs connected to port 2.

8.6 Summary

Preliminary version – 13 July 2017

Page 39: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§8.6 Summary 35

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 8.7: Lab Rubric

Preliminary version – 13 July 2017

Page 40: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 9

Lab 9 : LCD interfacing

9.1 Objective

To interface LCD with 8051 microcontroller.

9.2 Pre-Lab Reading

Chapter 12, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

9.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 9.1: Components Required

9.4 Theory

9.4.1 LCD(Liquid Crystal Display)

LCDs have found widespread use in the recent years. A normal LCD has 16 pins. Out ofthese pins, eight are data pins, three pins are for backlight and contrast setting and two pinsare for power supply. The rest three pins are control pins. Among these three pins RS is toselect between commands or data register. R/W pin is to read from LCD or write on LCD. Epin is used to latch in the information present on LCD data lines. Following diagram showsLCD connected to microcontroller.

As shown in figure only four data ports are connected with microcontroller. Therefore,do not forget to initialize LCD for 4 bit data length instead of eight.

To display letters and numbers 0–9 to these pins while making RS=1. There are alsoinstruction command codes that can be sent to the LCD to clear the display or force the

36

Preliminary version – 13 July 2017

Page 41: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§9.5 LCD COMMAND CODES 37

Figure 9.1: Architecture for SAP-1

Table 9.2: Add captionPin Symbol I/O DescriptionPin1 VSS — GroundPin2 VCC — +5 power supplyPin3 VEE — Power supply to control contrastPin4 RS I RS=0 to select command register

RS=1 to select data registerPin5 R/W I R/W=0 for write

R/W=1 for readPin6 E I/O EnablePin7 DB0 I/O The 8 bit data busPin8 DB1 I/O The 8 bit data busPin9 DB2 I/O The 8 bit data busPin10 DB3 I/O The 8 bit data busPin11 DB4 I/O The 8 bit data busPin12 DB5 I/O The 8 bit data busPin13 DB6 I/O The 8 bit data busPin14 DB7 I/O The 8 bit data bus

cursor to the home position or blink the cursor .The following table lists the instructioncommand codes.

9.5 LCD COMMAND CODES

9.6 Busy Flag

We use RS=0 to check the busy flag bit to see if the LCD is ready to receive the information.The busy flag is D7 and can be read when R/W=1 and RS=0. If D7 =0 the LCD is ready toreceive the information otherwise LCD is busy in taking care of internal operations if R/W=1, RS=0.

Preliminary version – 13 July 2017

Page 42: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

38 Lab 9 : LCD interfacing

Table 9.3: Add captionCode (Hex) Command to LCD instruction Register

1 Clear display screen2 Return home4 Decrement cursor (shift cursor to left)5 Shift display right6 Increment cursor (Shift cursor to right)7 Shift display left8 Display off , cursor offA Display off , cursor onC Display on , cursor offE Display on , cursor blinking10 Shift cursor position to left14 Shift cursor position to right18 Shift the entire display to the left1C Shift the entire display to the right80 Force cursor to beginning of first lineC0 Force cursor to beginning of second line38 2 lines and 5x7 matrix

9.7 Activities and Exercise

• Write an assembly language code to display your name in first row and registration insecond row of LCD.

• Display a message on first row of LCD which should be scrolling to either left or right.

Preliminary version – 13 July 2017

Page 43: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§9.7 Activities and Exercise 39

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 9.4: Lab Rubric

Preliminary version – 13 July 2017

Page 44: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 10

Lab 10 : Keypad Interfacing

10.1 Objective

To interface Keypad with 8051 microcontroller.

10.2 Pre-Lab Reading

Chapter 12, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

10.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 10.1: Components Required

10.4 Activities and Exercise

Connect keypad to port 2 and send the number pressed on keypad to LCD.

40

Preliminary version – 13 July 2017

Page 45: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§10.4 Activities and Exercise 41

Figure 10.1: Architecture for SAP-1

Figure 10.2: Architecture for SAP-1

Preliminary version – 13 July 2017

Page 46: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

42 Lab 10 : Keypad Interfacing

Figure 10.3: Architecture for SAP-1

Preliminary version – 13 July 2017

Page 47: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§10.4 Activities and Exercise 43

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 10.2: Lab Rubric

Preliminary version – 13 July 2017

Page 48: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 11

Lab 12:ADC interfacing

11.1 Objective

To interface Keypad with 8051 microcontroller.

11.2 Pre-Lab Reading

Chapter 12, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

11.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 11.1: Components Required

11.4 ADC 0804

ADC converts physical quantity into electrical quantity. They are used for sensing tempera-ture, velocity, pressure, and many other natural quantities. They produce electrical output inform of voltage or current. An ADC has n-bit resolution where n can be 8,10,12,16, or even24 bits. Step size is the smallest change that can be discerned by ADC .The higher resolutionADC provides smaller step size. In addition to resolution, conversion time is another majorfactor in judging an ADC. Conversion time is defined as the time it takes the ADC to convertthe analog input to a digital number .ADC 0804 is an 8-bit parallel analog to digital convertercompatible with 8-bit microcontroller. The following diagram shows the pin configuration ofIC.

WR pin is set to low in order to start conversion of analog signal applied at Vin(+). Whenthe conversion is completed INTR pin which is normally high goes low. RD pin set to low

44

Preliminary version – 13 July 2017

Page 49: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§11.5 Activities and Exercise 45

Figure 11.1: Pin Configuration of 0804

in order to get the converted data on data port D0-D7. VREF/2 pin is for reference voltagewhile Vin(-) is normally grounded. If VREF/2 is not connected, the input for ADC is in therange of 0-5 Volts.

11.5 Activities and Exercise

• Figure 9.2 shows an ADC connected to port 1 of microcontroller. RD, WR and INTRpins are connected to port 3. Connect the circuit as shown in diagram above and leavepin 7 unconnected. The following code reads digital value of analog signal sampled byADC. Resolution of ADC for this configuration is 19.53 mV. The code takes the sampleafter every second and sends the value on port 2. RD BIT P3.0WR BIT P3.1INTP BIT P3.2ORG 00HMAIN: CLR WRNOPSETB WRJB INTP, $CLR RDNOPNOPNOPMOV A, P1MOV P2, ASETB RDCALL DELAYJMP MAIN

Preliminary version – 13 July 2017

Page 50: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

46 Lab 12:ADC interfacing

Figure 11.2: ADC 0804connected to 89C51

END

(Make the subroutine of DELAY for 1 second)Download this program into microcontroller and verify its working by varying theanalog input signal.

• Write an assembly language code to read data from ADC whenever P3.5 is set to low.Also change the resolution of ADC.

Preliminary version – 13 July 2017

Page 51: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§11.5 Activities and Exercise 47

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 11.2: Lab Rubric

Preliminary version – 13 July 2017

Page 52: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 12

Lab 12: DAC interfacing

12.1 Objective

To interface Keypad with 8051 microcontroller.

12.2 Pre-Lab Reading

Chapter 13, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

12.3 Equipment Required

Instruments Oscilloscope, 8051 ETK Trainer

Components

Resistors 8.2kΩ, 10kΩ

Capacitors 10µF,30µF, 30µF

ICs 89C51RD2

Table 12.1: Components Required

12.4 DAC 0808

DAC0808 is an 8-bit digital to analog converter compatible with 8-bit microcontroller. Thefollowing diagram shows the pin configuration of IC. This DAC uses R/2R ladder methodwhich has a much higher degree of precision. Resolution of DAC depends on the numberof binary inputs. Since it is an 8-bit DAC, it can produce 256 discrete levels of output. Thefirst criterion for judging a DAC is its resolution, which is a function of the number of binaryinputs. The common ones are 8, 10 and 12 bits. The number of data bit inputs decides theresolution of the DAC since the number of analog output levels is equal to 2n. Where n is thenumber of data bit inputs.In the DAC 0808, the digital inputs are converted to current (Io).Io = Ir(D7/2 + D6/4 + D5/8 + D4/16 + D3/32 + D2/64 + D1/128 + D0/256)

48

Preliminary version – 13 July 2017

Page 53: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§12.5 Activities and Exercise 49

Figure 12.1: Pin Configuration of 0808

12.5 Activities and Exercise

• Figure 2 shows a DAC connected to microcontroller. Connect the circuit as shown inthe diagram.

Figure 12.2: DAC 0808 connected to 89C51

• Write a code to generate a sine wave at the output of DAC. Show the output at oscillo-scope. Explain clearly the calculations for different frequencies of sine wave.

Preliminary version – 13 July 2017

Page 54: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

50 Lab 12: DAC interfacing

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 12.2: Lab Rubric

Preliminary version – 13 July 2017

Page 55: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 13

Lab 13: Introduction to PIC18F458Microcontroller, Training board andsimulation software

13.1 Objective

To get familiar with PIC family of microcontrollers, itâAZs features, and programmingenvironment.

13.2 Pre-Lab Reading

Chapter 1, Mazidi and McKinlay, The 8051 Microcontroller and Embedded Systems

13.3 Theory

A summary of PIC18F458 microcontroller features is given below:

• Linear data memory addressing to 4 Kbytes

• Three external interrupt pins

• Timer0module: 8-bit/16-bit timer/counter

• Timer1module: 16-bit timer/counter

• Timer2module: 8-bit timer/counter

• Timer3module: 16-bit timer/counter

• Secondary oscillator clock option âAS Timer1/Timer3

• Capture/Compare/PWM (CCP) modules

• Enhanced CCP module with features for advanced motor control:

• 1, 2 or 4 PWM outputs

• Selectable PWM polarity

51

Preliminary version – 13 July 2017

Page 56: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

52 Lab 13: Introduction to PIC18F458 Microcontroller, Training board and simulation software

• Programmable PWM dead time

• Master Synchronous Serial Port (MSSP)

• 3-wire SPIâDc (Supports all 4 SPI modes)

• I2CâDc Master and Slave mode

• Addressable USART module

• 10-bit, up to 8-channel Analog-to-Digital Converter

• Comparator Voltage Reference module

• Programmable Brown-out Reset (BOR)

• CAN bus Module

• Power-on Reset (POR), Power-up Timer (PWRT)

• Watchdog Timer (WDT) with its own on-chip RC oscillator

• Programmable code protection

• Power-saving Sleep mode

• Selectable oscillator options

13.4 Activities and Exercise

• Write a simple program to continuously flash all PORTS LEDs one by one in a line witha 0.4sec on time for each LED (LEDâAZs are active LOW on this trainer board)

Preliminary version – 13 July 2017

Page 57: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§13.4 Activities and Exercise 53

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 13.1: Lab Rubric

Preliminary version – 13 July 2017

Page 58: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

Chapter 14

Lab 14: Loops and Subroutines inPIC Microcontroller

14.1 Objective

To get familiar with loops and subroutines in PIC microcontroller.

14.2 Pre-Lab Reading

Chapter 03 Mazidi, âAIJThe PIC Microcontroller and Embedded SystemsâAI

14.3 Theory

A summary of PIC18F458 microcontroller features is given below: Repeating a sequence oran operation a certain number of times is called a loop. Loop is most widely used programingtechnique. In PIC assembly language, the time delay loop looks like this:

Table 14.1: Add captionMovlw DâAZ50âAZmovwf Jjloop: movwf Kkloop: decfsz K,fgoto kloopdecfsz J,fgoto jloop

HereâAZs how it works. First, note that counting down is easier than counting up becauseitâAZs easier to test whether a byte equals 0 than whether it equals some other number.So we stuff decimal 50 into variables J and K at the beginning of the loop. The value 50is stored in W, which doesnâAZt change during the whole process; thus it can be copiedinto K fifty times. The crucial instruction here is decfsz K,f which means, âAIJDecrement(that is, subtract 1) and skip the next instruction if the result of decrementing was zero.âAIThus, a decfsz followed by a goto means âAIJSubtract 1 and go back unless the result of thesubtraction was 0.âAI Two decfsz loops, nested, produce the time delay we need. On thelast pass through the loop, the value of J or K respectively is 1; then, when it reaches 0, theprogram exits the loop. BNZ (branch if not zero) can also be used for looping. BRA and

54

Preliminary version – 13 July 2017

Page 59: Microprocessor and System Lab - CPE KFUEITcpe.kfueit.edu.pk/images/manuals/Microprocessor-and-System-Lab.… · Microprocessor and System Lab ... (Simple-As-Possible) is a computer

§14.4 Activities and Exercise 55

Microprocessor Systems Lab RubricPLOs Excellent Good Satisfactory Poor Score

3.0 2.0 1.0 0

ApparatusUsage PLO-5

Can indepen-dently setup,operate andhandle theapparatus

Can setupand handle

the apparatuswith minimal

help

Can setupand handle

the apparatuswith some

help

Cannot setupor handle the

apparatus

DataAcquisition PLO-5

All requireddata is

recorded andpresentedaccurately

andcompletely inthe required

format

Datarecorded andpresented iscomplete butaccuracy isnot as per

requirement.The required

format isfollowed.

Datarecorded andpresented is

partiallycomplete.

The requiredformat is

followed butwith few

deficiencies.

Datarecorded only

withconsiderable

assistancefrom

instructor

Design PLO-3

Specifications,parameters

andconstraints of

design arecompletely

present

Specifications,parameters

andconstraints of

design arepartiallypresent

Somespecifications,

parametersand

constraints ofdesign are

present

Nospecifications,

parametersand

constraints ofdesign are

present

DataInterpretation PLO-4

Analyzes andinterprets

data correctlyfor all tasks/experiments

in the lab

Analyzes andinterprets

data correctlyfor fewtasks/

experimentsin the lab

Analyzesdata correctly

howeverunable to

interpret itfor tasks/

experimentsin the lab

Unable toanalyze and

interpret datafor anytasks/

experimentsin the lab

Total Score in Lab (Out of 12)

Table 14.2: Lab Rubric

GOTO are unconditional jumps and may also be used for looping purpose. When we needto call some specific subroutine and need to come back to next instruction from the calledone, we use Call and Rcall instruction. We need to add return statement at the end of eachsubroutine for this purpose. One instruction in PIC take 4 oscillating periods to execute. Sof=Frequency of crystal/4; T=1/f sec will be time period for execution of single instruction.So by properly calculation the instruction execution tie we can generate delay of desire size.

14.4 Activities and Exercise

• Write a simple program to continuously flash all PORTS LEDs one by one in a line witha 0.4sec on time for each LED (LEDâAZs are active LOW on this trainer board)

Preliminary version – 13 July 2017