Https _doc-0o-c4-apps-viewer.googleusercontent
-
Upload
vijaydeepakg -
Category
Documents
-
view
151 -
download
0
Transcript of Https _doc-0o-c4-apps-viewer.googleusercontent
![Page 1: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/1.jpg)
12MT06PED009
BY CH. BALAKISHAN
![Page 2: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/2.jpg)
DATA TRANSFER INSTRUCTIONS
MOVMOVCMOVX
![Page 3: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/15.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/16.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/17.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/18.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/19.jpg)
![Page 20: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/20.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/21.jpg)
CONDITIONAL JUMPS
![Page 22: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/22.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/24.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/25.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/26.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/27.jpg)
BYTE JUMPS:
![Page 28: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/28.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/29.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/30.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/31.jpg)
![Page 32: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/32.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/33.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/34.jpg)
�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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/35.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/36.jpg)
Solution:
![Page 37: Https _doc-0o-c4-apps-viewer.googleusercontent](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/37.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/38.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052214/5584ae19d8b42a125c8b4fa6/html5/thumbnails/39.jpg)