Https _doc-0o-c4-apps-viewer.googleusercontent

39
12MT06PED009 BY CH. BALAKISHAN

Transcript of Https _doc-0o-c4-apps-viewer.googleusercontent

Page 1: Https  _doc-0o-c4-apps-viewer.googleusercontent

12MT06PED009

BY CH. BALAKISHAN

Page 2: Https  _doc-0o-c4-apps-viewer.googleusercontent

DATA TRANSFER INSTRUCTIONS

MOVMOVCMOVX

Page 3: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV INSTRUCTIONThe MOV instruction moves data bytes/bits between the two specified operands. The byte/bit specified by the second operand is copied to the location specified by the first operandThe source data byte/bit is not affected.No other register or flag is affected.

MOV destination, source ;copy source to dest.

MOV A,#55H ;load value 55H into reg. A

Page 4: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV A,#35h; moving the 35h to the register A

MOV 35h,45h; moving the content of memory location 45h to the memory location 35h,

Here #35h is a data, 35h is a memory location.

Page 5: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV 30h,A; moving the content of reg. A to the memory location 30h,

MOV A,30h;MOV A,R1;

moving the content of reg. R1 to the reg. A

Page 6: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV 3,A; = MOV R3,A;MOV A,@R3;

moving the content of memory pointed to by R3 to A;

MOV @R3,A; moving the content of reg. A to the memory pointed to by reg.R3

Page 7: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV <dest-bit>,<src-bit> Function: To move bit dataOne of the operands must be the carry flagExample: MOV P1.3,C;

moves the carry bit to 3rd bit of port1 if C=1; the output of P1.3 is high, if C=0; the output of P1.3 is low,

Page 8: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV DPTR,16bit dataLoads the data pointer with 16 bit constant,This is 3 byte instruction,Data stored in 2nd and 3rd bytes of the instructionMOV DPTR, # 4567H

DPL=67H;(lower byte) DPH=45H;(higher byte)

Page 9: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOV DPTR, # 4567H;MOV DPL,#67H;MOV DPH,#45H;=

MOV R1,R2; it is not possible

Page 10: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOVC A,@A+ <base-reg> these instructions load the accumulator with a code byte or constant from program memoryThe address of the byte fetched is the sum of the original unsigned 8-bit Accumulator contents and the contents of a 16-bit base registerBase register may be either the Data Pointer or the PC

Page 11: Https  _doc-0o-c4-apps-viewer.googleusercontent

Example:Look-up table SQUR has the of values between 0

to 4, ORG 100HSQUR: DB 0,1,4,9,16 program to fetch the square value of 4

ORG 0H MOV A,#4H; MOV DPTR,100H; MOVC A,@A+DPTR; END;

Page 12: Https  _doc-0o-c4-apps-viewer.googleusercontent

MOVX <dest-byte>,<src-byte>

The MOVX instructions transfer data between the Accumulator and a byte of external data memory,This data space must be connected externallyAddress of external memory being accessed can be 16-bit or 8-bit

for 16 bit--- DPTR 8 bit----R0 or R1

Page 13: Https  _doc-0o-c4-apps-viewer.googleusercontent

16 Bit address data transfer:

MOVX @DPTR,A; this moves the contents of the

accumulator to the external memory location whose address is pointed to by DPTR,MOVX A,@DPTR;

this moves into the accumulator a byte from external memory whose address is pointed to by DPTR,

Page 14: Https  _doc-0o-c4-apps-viewer.googleusercontent

8 Bit address data transfer

MOVX A,@R1; This moves to the accumulator to the

external memory whose 8-bit address is pointed to by R0MOVX @R1,A;

This moves a byte from register into external memory location whose 8-bit address is held by R0

Page 15: Https  _doc-0o-c4-apps-viewer.googleusercontent

EXAMPLE PROGRAM USING MOVX INSTRUCTION..An external ROM uses the 8051 data space to store the look-up table (starting at 1000H) for DAC data. Write a program to read 30 Bytes of these data and send it to P1.

Page 16: Https  _doc-0o-c4-apps-viewer.googleusercontent

Solution:

MYXDATA EQU 1000HCOUNT EQU 30MOV DPTR, #MYXDATA;MOV R2, #COUNT;AGAIN: MOVX A,@DPTR;MOV P1,A;INC DPTR;DJNZ R2,AGAIN;

Page 17: Https  _doc-0o-c4-apps-viewer.googleusercontent

BRANCHING INSTRUCTIONS

Program branching instructions are used to control the flow of actions in program.Some instructions provide decision making capabilities and transfer control to other parts of program.

eg., Unconditional and conditional branches.

Page 18: Https  _doc-0o-c4-apps-viewer.googleusercontent

SJUMP(short jump):2 byte instruction1st byte opcode2nd byte relative address of target location relative address range is 00 – FFH, All conditional jumps are short jumps

Ex: SJUMP HERE; after executing this instruction it jumps to HERE label

Page 19: Https  _doc-0o-c4-apps-viewer.googleusercontent
Page 20: Https  _doc-0o-c4-apps-viewer.googleusercontent

LJUMP(long jump):

Unconditional long jump3byte instruction1st byte for op-code2nd and 3rd byte for 16 bit address of target location

Page 21: Https  _doc-0o-c4-apps-viewer.googleusercontent

CONDITIONAL JUMPS

Page 22: Https  _doc-0o-c4-apps-viewer.googleusercontent

JZ AND JNZ INSTRUCTIONSJZ label ; jump if A=0

Can be used only for register A, not any other register.flag registers will not be affected

JNZ label; jump if A is not zero

Page 23: Https  _doc-0o-c4-apps-viewer.googleusercontent

DJNZ INSTRUCTIONDJNZ reg, Label;The register is decremented.If it is not zero, it jumps to the target address referred to by the label.Prior to the start of loop the register is loadel with the counter for the number of repetitions.Counter can be R0 – R7 or RAM location.

Page 24: Https  _doc-0o-c4-apps-viewer.googleusercontent

ExampleProgram to complement the accumulator 3 times

ORG 0H; MOV A,0Fh; MOV R3,3; HERE: CPL A; DJNZ R3,HERE; END

Page 25: Https  _doc-0o-c4-apps-viewer.googleusercontent

EXAMPLE:Write a program to (a) load the accumulator with the value 55H, and (b) complement the ACC 700 times.

MOV A,#55H ;A=55HMOV R3,#10 ;R3=10, outer loop countNEXT: MOV R2,#70 ;R2=70, inner loop countAGAIN: CPL A ;complement A registerDJNZ R2,AGAIN ;repeat it 70 timesDJNZ R3,NEXT

Page 26: Https  _doc-0o-c4-apps-viewer.googleusercontent

JNC INSTRUCTIONJNC label ;jump if no carry, CY=0If CY = 0, the CPU starts to fetch and execute instruction from the address of the label.If CY = 1, it will not jump but will execute the next instruction below JNC.All conditional jumps are short jumpsThe address of the target must within

-128 to +127 bytes of the contents of PC

Page 27: Https  _doc-0o-c4-apps-viewer.googleusercontent

BYTE JUMPS:

Page 28: Https  _doc-0o-c4-apps-viewer.googleusercontent

CALL instructionsTo call a user defined functions in program Transfer control to a subroutineFlags are not affectedRET must be the last instruction of subroutineThese are two types

1) ACALL(absolute call) 2) LCALL (long call)

Page 29: Https  _doc-0o-c4-apps-viewer.googleusercontent

ACALL: 2 byte instruction 5 bits are used for op-code remaining 11 bits are used for subroutine target addressTarget address must be within 2K byte

Ex: ACALL label; here label address should be 2K byte

only

Page 30: Https  _doc-0o-c4-apps-viewer.googleusercontent

LCALL: 3 byte instruction1st byte for op-code2nd and 3rd for target address of the subroutineSubroutine address located anywhere within 64K byte

Ex: LCALL label;

Page 31: Https  _doc-0o-c4-apps-viewer.googleusercontent
Page 32: Https  _doc-0o-c4-apps-viewer.googleusercontent

Program to display 5 and 4 digits in seven segment display with delay:

ORG 0H; MOV P1,#05DH; ACALL DELAY; MOV P1,#026H; ACALL DELAY; END;DELAY: MOV R3,#55; (count=55) HERE: DJNZ R3,HERE;(loop) RET;

Page 33: Https  _doc-0o-c4-apps-viewer.googleusercontent

TIME DELAY CALCULATIONS

� CPU executing an instruction takes a certain number of clock cycles. These are referred as to as machine cycles.

� In original 8051, one machine cycle lasts 12 oscillator periods.

� Find the period of the machine cycle for 11.0592 MHz crystal frequency?

Page 34: Https  _doc-0o-c4-apps-viewer.googleusercontent

�Solution:11.0592/12 = 921.6 kHz;machine cycle is 1/921.6 kHz =

1.085μs

Page 35: Https  _doc-0o-c4-apps-viewer.googleusercontent

PROBLEM:�For 8051 system of 11.0592

MHz, find how long it takes to execute each instruction.

(a) MOV R3,#55 (b) DEC R3 (c) DJNZ R2 target

(d) LJMP (e) SJMP (f) NOP (g) MUL AB

Page 36: Https  _doc-0o-c4-apps-viewer.googleusercontent

Solution:

Page 37: Https  _doc-0o-c4-apps-viewer.googleusercontent

Find the size of the delay in following program,

if the crystal frequency is 11.0592MHz.

MACHINE CYCLEDELAY: MOV R3,#250 1HERE: NOP 1NOP 1NOP 1NOP 1DJNZ R3,HERE 2RET 2

Page 38: Https  _doc-0o-c4-apps-viewer.googleusercontent

SOLUTION

�The time delay inside HERE loop is [250(1+1+1+1+2)]x1.085μs = 1627.5μs. Adding the two instructions outside loop we have 1627.5μs + 3 x 1.085μs = 1630.755μs.

Page 39: Https  _doc-0o-c4-apps-viewer.googleusercontent