UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Size: px
Start display at page:

Download "UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING"

Transcription

1 UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

2 Instructions Alphabetical List of Instructions ACALL: Absolute Call ADD, ADDC: Add Accumulator (With Carry) AJMP: Absolute Jump ANL: Bitwise AND CJNE: Compare and Jump if Not Equal CLR: Clear Register CPL: Complement Register DA: Decimal Adjust DEC: Decrement Register DIV: Divide Accumulator by B DJNZ: Decrement Register and Jump if Not Zero INC: Increment Register JB: Jump if Bit Set JBC: Jump if Bit Set and Clear Bit JC: Jump if Carry Set JMP: Jump to Address JNB: Jump if Bit Not Set JNC: Jump if Carry Not Set JNZ: Jump if Accumulator Not Zero JZ: Jump if Accumulator Zero LCALL: Long Call LJMP: Long Jump MOV: Move Memory MOVC: Move Code Memory MOVX: Move Extended Memory MUL: Multiply Accumulator by B NOP: No Operation ORL: Bitwise OR POP: Pop Value From Stack PUSH: Push Value Onto Stack RET: Return From Subroutine RETI: Return From Interrupt 2

3 RL: Rotate Accumulator Left RLC: Rotate Accumulator Left Through Carry RR: Rotate Accumulator Right RRC: Rotate Accumulator Right Through Carry SETB: Set Bit SJMP: Short Jump SUBB: Subtract From Accumulator With Borrow SWAP: Swap Accumulator Nibbles XCH: Exchange Bytes XCHD: Exchange Digits XRL: Bitwise Exclusive OR Undefined: Undefined Instruction Operation: ACALL Function: Absolute Call Within 2K Block Syntax: ACALL code address Description: ACALL unconditionally calls a subroutine at the indicated code address. ACALL pushes the address of the instruction that follows ACALL onto the stack, leastsignificant-byte first, most-significant-byte second. The Program Counter is then updated so that program execution continues at the indicated address. The new value for the Program Counter is calculated by replacing the least-significant-byte of the Program Counter with the second byte of the ACALL instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate the page. Bits 3-7 of the most-significant-byte of the Program Counter remain unchaged. Since only 11 bits of the Program Counter are affected by ACALL, calls may only be made to routines located within the same 2k block as the first byte that follows ACALL. Operation: ADD, ADDC Function: Add Accumulator, Add Accumulator With Carry Syntax: ADD A,operand ADDC A,operand 3

4 Description: Description: ADD and ADDC both add the value operand to the value of the Accumulator, leaving the resulting value in the Accumulator. The value operand is not affected. ADD and ADDC function identically except that ADDC adds the value of operand as well as the value of the Carry flag whereas ADD does not add the Carry flag to the result. The Carry bit (C) is set if there is a carry-out of bit 7. In other words, if the unsigned summed value of the Accumulator, operand and (in the case of ADDC) the Carry flag exceeds 255 Carry is set. Otherwise, the Carry bit is cleared. The Auxillary Carry (AC ) bit is set if there is a carry-out of bit 3. In other words, if the unsigned summed value of the low nibble of the Accumulator, operand and (in the case of ADDC) the Carry flag exceeds 15 the Auxillary Carry flag is set. Otherwise, the Auxillary Carry flag is cleared. The Overflow (OV) bit is set if there is a carry-out of bit 6 or out of bit 7, but not both. In other words, if the addition of the Accumulator, operand and (in the case of ADDC) the Carry flag treated as signed values results in a value that is out of the range of a signed byte (-128 through +127) the Overflow flag is set. Otherwise, the Overflow flag is cleared. Operation: AJMP Function: Absolute Jump Within 2K Block Syntax: AJMP code address Description: AJMP unconditionally jumps to the indicated code address. The new value for the Program Counter is calculated by replacing the least-significant-byte of the Program Counter with the second byte of the AJMP instruction, and replacing bits 0-2 of the mostsignificant-byte of the Program Counter with 3 bits that indicate the page of the byte following the AJMP instruction. Bits 3-7 of the most-significant-byte of the Program Counter remain unchaged. Since only 11 bits of the Program Counter are affected by AJMP, jumps may only be made to code located within the same 2k block as the first byte that follows AJMP. 4

5 Operation: ANL Function: Bitwise AND Syntax: ANL operand1, operand2 Description: ANL does a bitwise "AND" operation between operand1 and operand2, leaving the resulting value in operand1. The value of operand2 is not affected. A logical "AND" compares the bits of each operand and sets the corresponding bit in the resulting byte only if the bit was set in both of the original operands, otherwise the resulting bit is cleared Operation: CJNE Function: Compare and Jump If Not Equal Syntax: CJNE operand1,operand2,reladdr Description: CJNE compares the value of operand1 and operand2 and branches to the indicated relative address if operand1 and operand2 are not equal. If the two operands are equal program flow continues with the instruction following the CJNE instruction. The Carry bit (C) is set if operand1 is less than operand2, otherwise it is cleared. Operation: CLR Function: Clear Register Syntax: CLR register 5

6 Description: CLR clears (sets to 0) all the bit(s) of the indicated register. If the register is a bit (including the carry bit), only the specified bit is affected. Clearing the Accumulator sets the Accumulator s value to 0. Operation: CPL Function: Complement Register Syntax: CPL operand Description: CPL complements operand, leaving the result in operand. If operand is a single bit then the state of the bit will be reversed. If operand is the Accumulator then all the bits in the Accumulator will be reversed. This can be thought of as "Accumulator Logical Exclusive OR 255" or as "255-Accumulator." If the operand refers to a bit of an output Port, the value that will be complemented is based on the last value written to that bit, not the last value read from it. Operation: DA Function: Decimal Adjust Accumulator Syntax: DA A Description: DA adjusts the contents of the Accumulator to correspond to a BCD (Binary Coded Decimal) number after two BCD numbers have been added by the ADD or ADDC instruction. If the carry bit is set or if the value of bits 0-3 exceed 9, 0x06 is added to the accumulator. If the carry bit was set when the instruction began, or if 0x06 was added to the accumulator in the first step, 0x60 is added to the accumulator. The Carry bit (C) is set if the resulting value is greater than 0x99, otherwise it is cleared. Operation: DEC Function: Decrement Register Syntax: DEC register 6

7 Description: DEC decrements the value of register by 1. If the initial value of register is 0, decrementing the value will cause it to reset to 255 (0xFF Hex). Note: The Carry Flag is NOT set when the value "rolls over" from 0 to 255. Operation: DIV Function: Divide Accumulator by B Syntax: DIV AB Instructions OpCode Bytes Cycles Flags DIV AB 0x C, OV Description: Divides the unsigned value of the Accumulator by the unsigned value of the "B" register. The resulting quotient is placed in the Accumulator and the remainder is placed in the "B" register. The Carry flag (C) is always cleared. The Overflow flag (OV) is set if division by 0 was attempted, otherwise it is cleared. Operation: DJNZ Function: Decrement and Jump if Not Zero Syntax: DJNZ register,reladdr Description: DJNZ decrements the value of register by 1. If the initial value of register is 0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new value of register is not 0 the program will branch to the address indicated by relative addr. If the new value 7

8 of register is 0 program flow continues with the instruction following the DJNZ instruction. Operation: INC Function: Increment Register Syntax: INC register Description: INC increments the value of register by 1. If the initial value of register is 255 (0xFF Hex), incrementing the value will cause it to reset to 0. Note: The Carry Flag is NOT set when the value "rolls over" from 255 to 0. In the case of "INC DPTR", the value two-byte unsigned integer value of DPTR is incremented. If the initial value of DPTR is (0xFFFF Hex), incrementing the value will cause it to reset to 0. Again, the Carry Flag is NOT set when the value of DPTR "rolls over" from to 0. Operation: JB Function: Jump if Bit Set Syntax: JB bit addr, reladdr Instructions OpCode Bytes Cycles Flags JB bit addr,reladdr 0x None Description: JB branches to the address indicated by reladdr if the bit indicated by bit addr is set. If the bit is not set program execution continues with the instruction following the JB instruction. Operation: JBC 8

9 Function: Jump if Bit Set and Clear Bit Syntax: JB bit addr, reladdr Instructions OpCode Bytes Cycles Flags JBC bit addr,reladdr 0x None Description: JBC will branch to the address indicated by reladdr if the bit indicated by bit addr is set. Before branching to reladdr the instruction will clear the indicated bit. If the bit is not set program execution continues with the instruction following the JBC instruction Operation: JC Function: Jump if Carry Set Syntax: JC reladdr Instructions OpCode Bytes Cycles Flags JC reladdr 0x None Description: JC will branch to the address indicated by reladdr if the Carry Bit is set. If the Carry Bit is not set program execution continues with the instruction following the JC instruction. Operation: JMP Function: Jump to Data Pointer + Accumulator Syntax: Instructions OpCode Bytes Cycles Flags 9

10 0x None Description: JMP jumps unconditionally to the address represented by the sum of the value of DPTR and the value of the Accumulator Operation: JNB Function: Jump if Bit Not Set Syntax: JNB bit addr,reladdr Instructions OpCode Bytes Cycles Flags JNB bit addr,reladdr 0x None Description: JNB will branch to the address indicated by reladdress if the indicated bit is not set. If the bit is set program execution continues with the instruction following the JNB instruction. Operation: JNC Function: Jump if Carry Not Set Syntax: JNC reladdr Instructions OpCode Bytes Cycles Flags JNC reladdr 0x None Description: JNC branches to the address indicated by reladdr if the carry bit is not set. If the carry bit is set program execution continues with the instruction following the JNB instruction. 10

11 Operation: JNZ Function: Jump if Accumulator Not Zero Syntax: JNZ reladdr Instructions OpCode Bytes Cycles Flags JNZ reladdr 0x None Description: JNZ will branch to the address indicated by reladdr if the Accumulator contains any value except 0. If the value of the Accumulator is zero program execution continues with the instruction following the JNZ instruction. Operation: JZ Function: Jump if Accumulator Zero Syntax: JZ reladdr Instructions OpCode Bytes Cycles Flags JZ reladdr 0x None Description: JZ branches to the address indicated by reladdr if the Accumulator contains the value 0. If the value of the Accumulator is non-zero program execution continues with the instruction following the JZ instruction. Operation: LCALL Function: Long Call Syntax: LCALL code addr Instructions OpCode Bytes Cycles Flags 11

12 LCALL code addr 0x None Description: LCALL calls a program subroutine. LCALL increments the program counter by 3 (to point to the instruction following LCALL) and pushes that value onto the stack (low byte first, high byte second). The Program Counter is then set to the 16-bit value which follows the LCALL opcode, causing program execution to continue at that address. Operation: LJMP Function: Long Jump Syntax: LJMP code addr Instructions OpCode Bytes Cycles Flags LJMP code addr 0x None Description: LJMP jumps unconditionally to the specified code addr. Operation: MOV Function: Move Memory Syntax: MOV operand1,operand2 Description: MOV copies the value of operand2 into operand1. The value of operand2 is not affected. Both operand1 and operand2 must be in Internal RAM. No flags are affected unless the instruction is moving the value of a bit into the carry bit in which case the carry bit is affected or unless the instruction is moving a value into the PSW register (which contains all the program flags). ** Note: In the case of "MOV iram addr,iram addr", the operand bytes of the instruction are stored in reverse order. That is, the instruction consisting of the bytes 12

13 0x85, 0x20, 0x50 means "Move the contents of Internal RAM location 0x20 to Internal RAM location 0x50" whereas the opposite would be generally presumed. Operation: MOVC Function: Move Code Byte to Accumulator Syntax: MOVC Instructions OpCode Bytes Cycles Flags MOVC 0x None MOVC A,@A+PC 0x None Description: MOVC moves a byte from Code Memory into the Accumulator. The Code Memory address from which the byte will be moved is calculated by summing the value of the Accumulator with either DPTR or the Program Counter (PC). In the case of the Program Counter, PC is first incremented by 1 before being summed with the Accumulator. Operation: MOVX Function: Move Data To/From External Memory (XRAM) Syntax: MOVX operand1,operand2 Instructions OpCode Bytes Cycles Flags 0xF0 1 2 None 0xF2 1 2 None 0xF3 1 2 None MOVX A,@DPTR 0xE0 1 2 None MOVX A,@R0 0xE2 1 2 None MOVX A,@R1 0xE3 1 2 None 13

14 Description: MOVX moves a byte to or from External Memory into or from the Accumulator. If operand1 the Accumulator is moved to the 16-bit External Memory address indicated by DPTR. This instruction uses both P0 (port 0) and P2 (port 2) to output the 16- bit address and data. If operand2 is DPTR then the byte is moved from External Memory into the Accumulator. If operand1 the Accumulator is moved to the 8-bit External Memory address indicated by the specified Register. This instruction uses only P0 (port 0) to output the 8-bit address and data. P2 (port 2) is not affected. If operand2 then the byte is moved from External Memory into the Accumulator. Operation: MUL Function: Multiply Accumulator by B Syntax: MUL AB Instructions OpCode Bytes Cycles Flags MUL AB 0xA4 1 4 C, OV Description: Multiples the unsigned value of the Accumulator by the unsigned value of the "B" register. The least significant byte of the result is placed in the Accumulator and the most-significant-byte is placed in the "B" register. The Carry Flag (C) is always cleared. The Overflow Flag (OV) is set if the result is greater than 255 (if the most-significant byte is not zero), otherwise it is cleared. Operation: NOP Function: None, waste time Syntax: No Operation Instructions OpCode Bytes Cycles Flags 14

15 NOP 0x None Description: NOP, as it s name suggests, causes No Operation to take place for one machine cycle. NOP is generally used only for timing purposes. Absolutely no flags or registers are affected. Operation: ORL Function: Bitwise OR Syntax: ORL operand1,operand2 Description: ORL does a bitwise "OR" operation between operand1 and operand2, leaving the resulting value in operand1. The value of operand2 is not affected. A logical "OR" compares the bits of each operand and sets the corresponding bit in the resulting byte if the bit was set in either of the original operands, otherwise the resulting bit is cleared. Operation: POP Function: Pop Value From Stack Syntax: POP Instructions OpCode Bytes Cycles Flags POP iram addr 0xD0 2 2 None Description: POP "pops" the last value placed on the stack into the iram addr specified. In other words, POP will load iram addr with the value of the Internal RAM address pointed to by the current Stack Pointer. The stack pointer is then decremented by 1. Operation: PUSH Function: Push Value Onto Stack Syntax: PUSH 15

16 Instructions OpCode Bytes Cycles Flags PUSH iram addr 0xC0 2 2 None Description: PUSH "pushes" the value of the specified iram addr onto the stack. PUSH first increments the value of the Stack Pointer by 1, then takes the value stored in iram addr and stores it in Internal RAM at the location pointed to by the incremented Stack Pointer. Operation: RET Function: Return From Subroutine Syntax: RET Instructions OpCode Bytes Cycles Flags RET 0x None Description: RET is used to return from a subroutine previously called by LCALL or ACALL. Program execution continues at the address that is calculated by popping the topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first, followed by the least-significant-byte. Operation: RETI Function: Return From Interrupt Syntax: RETI Instructions OpCode Bytes Cycles Flags RETI 0x None Description: RETI is used to return from an interrupt service routine. RETI first enables interrupts of equal and lower priorities to the interrupt that is terminating. Program execution continues at the address that is calculated by popping the topmost 2 bytes off the 16

17 stack. The most-significant-byte is popped off the stack first, followed by the leastsignificant-byte. RETI functions identically to RET if it is executed outside of an interrupt service routine. Operation: RL Function: Rotate Accumulator Left Syntax: RL A Instructions OpCode Bytes Cycles Flags RL A 0x C Description: Shifts the bits of the Accumulator to the left. The left-most bit (bit 7) of the Accumulator is loaded into bit 0. Operation: RLC Function: Rotate Accumulator Left Through Carry Syntax: RLC A Instructions OpCode Bytes Cycles Flags RLC A 0x C Description: Shifts the bits of the Accumulator to the left. The left-most bit (bit 7) of the Accumulator is loaded into the Carry Flag, and the original Carry Flag is loaded into bit 0 of the Accumulator. This function can be used to quickly multiply a byte by 2. Operation: RR Function: Rotate Accumulator Right Syntax: RR A 17

18 Instructions OpCode Bytes Cycles Flags RR A 0x None Description: Shifts the bits of the Accumulator to the right. The right-most bit (bit 0) of the Accumulator is loaded into bit 7. Operation: RRC Function: Rotate Accumulator Right Through Carry Syntax: RRC A Instructions OpCode Bytes Cycles Flags RRC A 0x C Description: Shifts the bits of the Accumulator to the right. The right-most bit (bit 0) of the Accumulator is loaded into the Carry Flag, and the original Carry Flag is loaded into bit 7. This function can be used to quickly divide a byte by 2. Operation: SETB Function: Set Bit Syntax: SETB bit addr Instructions Description: Sets the specified bit. Operation: SJMP OpCode Bytes Cycles Flags SETB C 0xD3 1 1 C SETB bit addr 0xD2 2 1 None 18

19 Function: Short Jump Syntax: SJMP reladdr Instructions OpCode Bytes Cycles Flags SJMP reladdr 0x None Description: SJMP jumps unconditionally to the address specified reladdr. Reladdr must be within -128 or +127 bytes of the instruction that follows the SJMP instruction. Operation: SUBB Function: Subtract from Accumulator With Borrow Syntax: SUBB A,operand Description: SUBB subtract the value of operand from the value of the Accumulator, leaving the resulting value in the Accumulator. The value operand is not affected. The Carry Bit (C) is set if a borrow was required for bit 7, otherwise it is cleared. In other words, if the unsigned value being subtracted is greater than the Accumulator the Carry Flag is set. The Auxillary Carry (AC) bit is set if a borrow was required for bit 3, otherwise it is cleared. In other words, the bit is set if the low nibble of the value being subtracted was greater than the low nibble of the Accumulator. The Overflow (OV) bit is set if a borrow was required for bit 6 or for bit 7, but not both. In other words, the subtraction of two signed bytes resulted in a value outside the range of a signed byte (-128 to 127). Otherwise it is cleared. Operation: SWAP Function: Swap Accumulator Nibbles Syntax: SWAP A 19

20 Instructions OpCode Bytes Cycles Flags SWAP A 0xC4 1 1 None Description: SWAP swaps bits 0-3 of the Accumulator with bits 4-7 of the Accumulator. This instruction is identical to executing "RR A" or "RL A" four times. Operation: XCH Function: Exchange Bytes Syntax: XCH A,register Description: Exchanges the value of the Accumulator with the value contained in register Operation: XCHD Function: Exchange Digit Syntax: XCHD A,[@R0/@R1] Instructions OpCode Bytes Cycles Flags XCHD A,@R0 0xD6 1 1 None XCHD A,@R1 0xD7 1 1 None Description: Exchanges bits 0-3 of the Accumulator with bits 0-3 of the Internal RAM address pointed to indirectly by R0 or R1. Bits 4-7 of each register are unaffected. Operation: XRL 20

21 Function: Bitwise Exclusive OR Syntax: XRL operand1,operand2 Description: XRL does a bitwise "EXCLUSIVE OR" operation between operand1 and operand2, leaving the resulting value in operand1. The value of operand2 is not affected. A logical "EXCLUSIVE OR" compares the bits of each operand and sets the corresponding bit in the resulting byte if the bit was set in either (but not both) of the original operands, otherwise the bit is cleared. Operation: Undefined Instruction Function: Undefined Syntax:??? Instructions OpCode Bytes Cycles Flags??? 0xA5 1 1 C Description: The "Undefined" instruction is, as the name suggests, not a documented instruction. The 8051 supports 255 instructions and OpCode 0xA5 is the single OpCode that is not used by any documented function. Since it is not documented nor defined it is not recommended that it be executed. However, based on my research, executing this undefined instruction takes 1 machine cycle and appears to have no effect on the system except that the Carry Bit always seems to be set. 21

22 PROGRAMMING Show the status of the CY, AC and P flag after the addition of 9CH and 64H in the following instructions. MOV A, #9CH ADD A, #64H ;after the addition A=00H, CY=1 Solution: 9C CY = 1 since there is a carry beyond the D7 bit AC = 1 since there is a carry from the D3 to the D4 bi P = 0 since the accumulator has an even number of 1s (it has zero 1s) 22

23 Show the stack and stack pointer from the following. Assume the default stack area. MOV R6, #25H MOV R1, #12H MOV R4, #0F3H PUSH 6 PUSH 1 PUSH 4 Example Examining the stack, show the contents of the register and SP after execution of the following instructions. All value are in hex. MOV SP, #5FH ;make RAM location 60H ;first stack location MOV R2, #25H MOV R1, #12H MOV R4, #0F3H PUSH 2 PUSH 1 PUSH 4 23

24 Write a program to (a) load the accumulator with the value 55H, and (b) complement the ACC 700 times MOV A,#55H ;A=55H MOV R3,#10 ;R3=10, outer loop count NEXT: MOV R2,#70 ;R2=70, inner loop count AGAIN: CPL A ;complement A register DJNZ R2,AGAIN ;repeat it 70 times DJNZ R3,NE Find the period of the machine cycle for MHz crystal frequency Solution: /12 = khz; machine cycle is 1/921.6 khz = 1.085μs For 8051 system of 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 Solution: 24

25 Machine cycles Time to execute (a) 1 1x1.085μs = 1.085μs (b) 1 1x1.085μs = 1.085μs (c) 2 2x1.085μs = 2.17μs (d) 2 2x1.085μs = 2.17μs (e) 2 2x1.085μs = 2.17μs (f) 1 1x1.085μs = 1.085μs (g) 4 4x1.085μs = 4.34μs Find the size of the delay in following program, if the crystal frequency is MHz. MOV A,#55H AGAIN: MOV P1,A ACALL DELAY CPL A SJMP AGAIN ;---time delay DELAY: MOV R3,#200 HERE: DJNZ R3,HERE RET Solution: Machine cycle DELAY: MOV R3,#200 1 HERE: DJNZ R3,HERE 2 RET 2 Therefore, [(200x2)+1+2]x1.085μs = μs. Find the size of the delay in following program, if the crystal frequency is MHz. Machine Cycle DELAY: MOV R3,#

26 HERE: NOP 1 NOP 1 NOP 1 NOP 1 DJNZ R3,HERE 2 RET 2 Solution: The time delay inside HERE loop is [250( )]x1.085μs = μs. Adding the two instructions outside loop we have μs + 3 x 1.085μs = μs Find the size of the delay in following program, if the crystal frequency is MHz. Machine Cycle DELAY: MOV R2,#200 1 AGAIN: MOV R3,#250 1 HERE: NOP 1 NOP 1 DJNZ R3,HERE 2 DJNZ R2,AGAIN 2 RET 2 Solution: For HERE loop, we have (4x250)x1.085μs=1085μs. For AGAIN loop repeats HERE loop 200 times, so we have 200x1085μs=217000μs. But MOV R3,#250 and DJNZ R2,AGAIN at the start and end of the AGAIN loop add (3x200x1.805)=651μs. As a result we have =217651μs. PORT PROGRAMMING 26

27 The following code will continuously send out to port 0 the alternating value 55H and AAH BACK: MOV A,#55H MOV P0,A ACALL DELAY MOV A,#0AAH MOV P0,A ACALL DELAY SJMP BACK Port 0 is configured first as an input port by writing 1s to it, and then data is received from that port and sent to P1 MOV A,#0FFH ;A=FF hex MOV P0,A ;make P0 an i/p port ;by writing it all 1s BACK: MOV A,P0 ;get data from P0 MOV P1,A ;send it to port 1 SJMP BACK ;keep doing it Write the following programs. Create a square wave of 50% duty cycle on bit 0 of port 1. Solution: The 50% duty cycle means that the on and off state (or the high and low portion of the pulse) have the same length. Therefore, we toggle P1.0 with a time delay in between each state. 27

28 Another way to write the above program is: Sometimes we need to access only 1 for 2 bits of the port Write a program to perform the following: (a) Keep monitoring the P1.2 bit until it becomes high (b) When P1.2 becomes high, write value 45H to port 0 (c) Send a high-to-low (H-to-L) pulse to P2.3 28

29 The look-up table allows access to elements of a frequently used table with minimum operations 29

30 Write a program to get the x value from P1 and send x2 to P2, continuously 30

31 While there are instructions such as JNC and JC to check the carry flag bit (CY), there are no such instructions for the overflow flag bit (OV). How would you write code to check OV? Assume that RAM locations 40 44H have the following values. Write a program to find the sum of the values. At the end of the program, register A should contain the low byte and R7 the high byte. 40 = (7D) 41 = (EB) 42 = (C5) 43 = (5B) 44 = (30) Write a program to add two 16-bit numbers. Place the sum in R7 and R6; R6 should have the lower byte. 31

32 (a) Write a program to get hex data in the range of 00 FFH from port 1 and convert it to decimal. Save it in R7, R6 and R5. (b) Assuming that P1 has a value of FDH for data, analyze program. (b) To convert a binary (hex) value to decimal, we divide it by 10 repeatedly until the quotient is less than 10. After each division the remainder is saves. 32

33 Therefore, we have FDH=253. Write a program that finds the number of 1s in a given byte. Write a program to transfer value 41H serially (one bit at a time) via pin P2.1. Put two highs at the start and end of the data. Send the byte LSB first. Write a program to bring in a byte of data serially one bit at a time via pin P2.7 and save it in register R2. The byte comes in with the LSB first. 33

34 TIMER PROGRAMMING In the following program, we create a square wave of 50% duty cycle (with equal portions high and low) on the P1.5 bit. Timer 0 is used to generate the time delay. Analyze the program In the above program notice the following step. 1. TMOD is loaded. 2. FFF2H is loaded into TH0-TL0. 3. P1.5 is toggled for the high and low portions of the pulse. The following program generates a square wave on P1.5 continuously using timer 1 for a time delay. Find the frequency of the square 34

35 wave if XTAL = MHz. In your calculation do not include the overhead due to Instructions in the loop. Solution: Since FFFFH 7634H = 89CBH + 1 = 89CCH and 89CCH = clock count and us = ms for half of the square wave. The frequency = Hz. Also notice that the high portion and low portion of the square wave pulse are equal. In the above calculation, the overhead due to all the instruction in the loop is not included. Assume XTAL = MHz, write a program to generate a square wave of 50 khz frequency on pin P2.3. Solution: Look at the following steps. (a) T = 1 / 50 = 20 ms, the period of square wave. (b) 1 / 2 of it for the high and low portion of the pulse is 10 ms. 35

36 (c) 10 ms / us = 9216 and = in decimal, and in hex it is DC00H. (d) TL = 00 and TH = DC (hex). Examine the following program and find the time delay in seconds. Exclude the overhead due to the instructions in the loop. Solution: 36

37 TH-TL = 0108H = 264 in decimal and = Now µs = ms, and for 200 of them we have ms = seconds. Assume XTAL = MHz, find the frequency of the square wave generated on pin P1.0 in the following program Solution: First notice the target address of SJMP. In mode 2 we do not need to reload TH since it is auto-reload. Now (256-05) us = us = us is the high portion of the pulse. Since it is a 50% duty cycle square wave, the period T is twice that; as a result T = us = us and the frequency = khz Find the frequency of a square wave generated on pin P

38 T = 2 ( us ) = ms, and frequency = 72 Hz SERIAL COMMUNICATION PROGRAMMING With XTAL = MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b) 2400 (c) 1200 Solution: The machine cycle frequency of 8051 = / 12 = khz, and khz / 32 = 28,800 Hz is frequency by UART to timer 1 to set baud rate. 38

39 (a) 28,800 / 3 = 9600 where -3 = FD (hex) is loaded into TH1 (b) 28,800 / 12 = 2400 where -12 = F4 (hex) is loaded into TH1 (c) 28,800 / 24 = 1200 where -24 = E8 (hex) is loaded into TH1 Notice that dividing 1/12 of the crystal frequency by 32 is the default value upon activation of the 8051 RESET pin. NOTE FOR REFERENCE Write a program for the 8051 to transfer letter A serially at 4800 baud, continuously. 39

40 Write a program for the 8051 to transfer YES serially at 9600 baud, 8-bit data, 1 stop bit, do this continuously 40

41 Write a program for the 8051 to receive bytes of data serially, and put them in P1, set the baud rate at 4800, 8-bit data, and 1 stop bit Assume that XTAL = MHz for the following program, state (a) what this program does, (b) compute the frequency used by timer 1 to set the baud rate, and (c) find the baud rate of the data transfer. 41

42 Solution: (a) This program transfers ASCII letter B ( binary) continuously (b) With XTAL = MHz and SMOD = 1 in the above program, we have: / 12 = khz machine cycle frequency / 16 = 57,600 Hz frequency used by timer 1 to set the baud rate / 3 = 19,200, the baud rate. 42

43 INTERRUPTS PROGRAMMING An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service A single microcontroller can serve several devices by two ways Interrupts Whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler Polling The microcontroller continuously monitors the status of a given device When the conditions met, it performs the service After that, it moves on to monitor the next device until every one is serviced Polling can monitor the status of several devices and serve each of them as certain conditions are met The polling method is not efficient, since it wastes much of the microcontroller s time by polling devices that do not need service ex. JNB TF,target The advantage of interrupts is that the microcontroller can serve many devices (not all at the same time) Each devices can get the attention of the microcontroller based on the assigned priority For the polling method, it is not possible to assign priority since it checks all devices in a round-robin fashion 43

44 The microcontroller can also ignore (mask) a device request for service This is not possible for the polling method For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler When an interrupt is invoked, the microcontroller runs the interrupt service routine For every interrupt, there is a fixed location in memory that holds the address of its ISR The group of memory locations set aside to hold the addresses of ISRs is called interrupt vector table Upon activation of an interrupt, the microcontroller goes through the following steps 1. It finishes the instruction it is executing and saves the address of the next instruction (PC) on the stack 2. It also saves the current status of all the interrupts internally (i.e: not on the stack) 3. It jumps to a fixed location in memory, called the interrupt vector table, that holds the address of the ISR The microcontroller gets the address of the ISR from the interrupt vector table and jumps to it It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine which is RETI (return from interrupt) 5. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted First, it gets the program counter (PC) address from the stack by popping the top two bytes of the stack into the PC Then it starts to execute from that address Six interrupts are allocated as follows Reset power-up reset 44

45 Two interrupts are set aside for the timers:one for timer 0 and one for timer 1 Two interrupts are set aside for hardware xternal interrupts P3.2 and P3.3 are for the external hardware nterrupts INT0 (or EX1), and INT1 (or EX2) Serial communication has a single interrupt that belongs to both receive and transfer 45

46 Show the instructions to (a) enable the serial interrupt, timer 0 interrupt, and external hardware interrupt 1 (EX1),and (b) disable (mask) the timer 0 interrupt, then (c) show how to disable all the interrupts with a single instruction. Write a program to generate a square wave if 50Hz frequency on pin P1.2. This is similar to Example 9-12 except that it uses an interrupt for timer 0. Assume that XTAL= MHz 46

47 Assume that the INT1 pin is connected to a switch that is normally high. Whenever it goes low, it should turn on an LED. The LED is connected to P1.3 and is normally off. When it is turned on it should stay on for a fraction of a second. As long as the switch is pressed low, the LED should stay on. 47

48 48

49 Self check 1.What is the advantage of using an internal timer when 8253 is available? 49

50 2.By what means a timer is inialised when compared to a control word used in 8085? 3.How will you check the completion of Timer? 4.What is the initialization operation required to assign a port as input.write the corresponding instruction 5.SWAP? VS XCHG? 6.Is there a index addressing mode in 8051? 7.SETB P1.7 stands for? I Instructions 2 M Machine cycles 24 Key Terms A Auto-reload 37 B Branch 9 Baud 40 C Complement 23 D Delay 24 P Programming 22 Port programming S Stack 22 Square wave 27 Serial communication Programming 38 T Timer programming 34 U Uart 38 50

51 KEY WORD QUIZ 1,The mode uses Auto-reload is 2.TheBranch instruction changes the value of the PC?true or false 3.The baud rates of the UART are, and 4.The instruction used to complement the accumulator is 5.What is the value of T is XTAL is MHz? MULTIPLE CHOICE In 8051 the number of ADDRESSINGMODES available is For interfacing an I/O device with 8051 we use the instruction MOV IN OUT all the above SETB P1.0 makes port1 zeroth bit 1 0 Z None of the above A=40.After execution of SWAP instruction A= The number of register banks in 8051 is

52 80 08 What is the size of the DATA IN 8051? The value of A and R1 after executing the following instruction is MOV 24,#34 MOV A,#78 MOV R1,#24 CPL A XCHD A,@R1 The addressing mode of MOV A,20 is Direct Indirect Registered Immediate The number of timers in 8051 is PSEN stands for Program status enable Power source enable Program store enable Power stimulus emphasize node MOVX A,@DPTR will read the of data pointed by Register DPTR from the Byte,Register pair Word,register pair Byte,external memory Word,external memory ACALL calls subroutines with a target address within bytes k 2k 52

53 QUESTIONS 1.Write a program to transfer value 55H serially (one bit at a time) via pin P2.1. Put two highs at the start and end of the data. Send the byte LSB first. 2.Write a program to bring in a byte of data serially one bit at a time via pin P2.7 and save it in register B. The byte comes in with the LSB first. 3.Assume XTAL = MHz, write a program to generate a square wave of 30 khz frequency on pin P With XTAL = 12 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b) 2400 (c) Write a program for the 8051 to transfer letters A-Z serially at 4800 baud, continuously. 6.Write a program for the 8051 to transfer YES serially at 2400 baud, 7-bit data, 1 stop bit, do this continuously 7.Write a program for the 8051 to receive bytes of data serially, and put them in P2, set the baud rate at 9600, 8-bit data, and 1 stop bit 8.Assume that XTAL = MHz for the following program, state (a) what this program does, (b) compute the frequency used by timer 1 to set the baud rate, and (c) find the baud rate of the data transfer. 9.Write a program to perform the following: (a) Keep monitoring the P2.2 bit until it becomes low (b) When P2.2 becomes low, write value 55H to port 3 (c) Send a high-to-low (H-to-L) pulse to P Create a square wave of 60% duty cycle on bit 7 of port Write a program to continuously send out to port 0 the alternating value 55H and AAH with a Delay of 1 sec. 12.Explain about the data transfer instruction of with suitable examples 13.Explain about the arithmetic and logical instruction of with suitable examples 14.Explain about the bit manipulation instruction with suitable examples. 53

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING Instructions Alphabetical List of Instructions ACALL: Absolute Call ADD, ADDC: Add Accumulator (With Carry) AJMP: Absolute Jump ANL: Bitwise AND CJNE: Compare

More information

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman Microprocessors 1 The 8051 Instruction Set Microprocessors 1 1 Instruction Groups The 8051 has 255 instructions Every 8-bit opcode from 00 to FF is used except for A5. The instructions are grouped into

More information

Microcontroller Intel [Instruction Set]

Microcontroller Intel [Instruction Set] Microcontroller Intel 8051 [Instruction Set] Structure of Assembly Language [ label: ] mnemonic [operands] [ ;comment ] Example: MOV R1, #25H ; load data 25H into R1 2 8051 Assembly Language Registers

More information

Microcontroller. Instruction set of 8051

Microcontroller. Instruction set of 8051 UNIT 2: Addressing Modes and Operations: Introduction, Addressing modes, External data Moves, Code Memory, Read Only Data Moves / Indexed Addressing mode, PUSH and POP Opcodes, Data exchanges, Example

More information

Contents 8051 Instruction Set BY D. BALAKRISHNA, Research Assistant, IIIT-H Chapter I : Control Transfer Instructions Lesson (a): Loop Lesson (b): Jump (i) Conditional Lesson (c): Lesson (d): Lesson (e):

More information

8051 Overview and Instruction Set

8051 Overview and Instruction Set 8051 Overview and Instruction Set Curtis A. Nelson Engr 355 1 Microprocessors vs. Microcontrollers Microprocessors are single-chip CPUs used in microcomputers Microcontrollers and microprocessors are different

More information

SN8F5000 Family Instruction Set

SN8F5000 Family Instruction Set SONiX Technology Co., Ltd. 8051-based Microcontroller 1 Overview SN8F5000 is 8051 Flash Type microcontroller supports comprehensive assembly instructions and which are fully compatible with standard 8051.

More information

Programming of 8085 microprocessor and 8051 micro controller Study material

Programming of 8085 microprocessor and 8051 micro controller Study material 8085 Demo Programs Now, let us take a look at some program demonstrations using the above instructions Adding Two 8-bit Numbers Write a program to add data at 3005H & 3006H memory location and store the

More information

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Q. Classify the instruction set of 8051 and list out the instructions in each type. INTRODUCTION Here is a list of the operands and their meanings: A - accumulator; Rn - is one of working registers (R0-R7) in the currently active RAM memory bank; Direct - is any 8-bit address register

More information

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP Digital Blocks Semiconductor IP 805 Microcontroller General Description The Digital Blocks Microcontroller Verilog IP Core is complaint with the MCS 5 Instruction Set and contains standard 805 MCU peripherals,

More information

8051 Microcontroller

8051 Microcontroller 8051 Microcontroller EE4380 Fall 2001 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas 8051 Architecture Programmer s View Register Set Instruction Set Memory

More information

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP 805 SFR Bus Digital Blocks Semiconductor IP 805 Microcontroller Configurable Peripherals General Description The Digital Blocks (Configurable Peripherals) Microcontroller Verilog IP Core is complaint with

More information

DR bit RISC Microcontroller. Instructions set details ver 3.10

DR bit RISC Microcontroller. Instructions set details ver 3.10 DR80390 8-bit RISC Microcontroller Instructions set details ver 3.10 DR80390 Instructions set details - 2 - Contents 1. Overview 7 1.1. Document structure. 7 2. Instructions set brief 7 2.1. Instruction

More information

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller of 8085 microprocessor 8085 is pronounced as "eighty-eighty-five" microprocessor. It is an 8-bit microprocessor designed by Intel in 1977 using NMOS technology. It has the following configuration 8-bit

More information

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples. MICROCONTROLLERS AND APPLICATIONS 1 Module 2 Module-2 Contents: Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples. MEMORY

More information

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP Digital Blocks Semiconductor IP DB805C-FSM 805 Microcontroller FSM Finite State Machine General Description The Digital Blocks DB805C-FSM IP Core contains Digital Blocks compact DB805C CPU Core & GPIO

More information

Instruction Set Of 8051

Instruction Set Of 8051 Instruction Set Of 8051 By Darshan Patel M.Tech (Power Electronics & Drives) Assistant Professor, Electrical Department Sankalchand Patel college of Engineering-Visnagar Introduction The process of writing

More information

Dodatak. Skup instrukcija

Dodatak. Skup instrukcija Dodatak Skup instrukcija Arithmetic Operations [@Ri] implies contents of memory location pointed to by R0 or R1 Rn refers to registers R0-R7 of the currently selected register bank 2 ADD A,

More information

Module Contents of the Module Hours COs

Module Contents of the Module Hours COs Microcontrollers (EE45): Syllabus: Module Contents of the Module Hours COs 1 8051 MICROCONTROLLER ARCHITECTURE: Introduction to Microprocessors and Microcontrollers, the 8051 Architecture, 08 1 and pin

More information

Dragonchip. Instruction Set Manual

Dragonchip. Instruction Set Manual Dragonchip Instruction Set Manual Version 3.1 July 2004 The Objective of this document is to provide the user a detail description to the each instruction set used in Dragonchip s MCU family. There are

More information

Principle and Interface Techniques of Microcontroller

Principle and Interface Techniques of Microcontroller Principle and Interface Techniques of Microcontroller --8051 Microcontroller and Embedded Systems Using Assembly and C LI, Guang ( 李光 ) Prof. PhD, DIC, MIET WANG, You ( 王酉 ) PhD, MIET 杭州 浙江大学 2011 Chapter

More information

8051 Microcontrollers

8051 Microcontrollers 8051 Microcontrollers Richa Upadhyay Prabhu NMIMS s MPSTME richa.upadhyay@nmims.edu March 15, 2016 8051 INSTRUCTIONS JUMP, LOOP AND CALL INSTRUCTIONS 8051 INSTRUCTIONS Repeating a sequence of instructions

More information

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO. INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO. ADD A,Rn Add register to 28..2F 1 12 X X X accumulator ADD A,direct Add direct byte 25 2 12 X X X to accumulator ADD A,@Ri Add indirect RAM 26..27

More information

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote Programming Book1 8051 Microcontroller Kit Rev 3.0 January, 016 016 Wichit Sirichote 1 Contents Overview...3 SAFTY INFORMATION...3 Tools...3 Experiment 1 Blinking LED...4 Experiment Binary number counting...9

More information

TUTORIAL Assembly Language programming (2)

TUTORIAL Assembly Language programming (2) 8051 Assembly Language programming (2) TUTORIAL 4 EEE3410 Microcontroller Applications 1. Write the instructions to move value 34h into register A and value 3Fh into register B, then add them together.

More information

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS EXAMINATION FOR 159.233 COMPUTER SYSTEMS Semester One June 2008 Time allowed: THREE (3) hours This exam contains THREE (3) questions ANSWER ALL THREE (3) QUESTIONS

More information

Embedded Controller Programming

Embedded Controller Programming Embedded Controller Programming Counters, Timers and I/O in Assembly Language Ken Arnold Copyright 2000-2004 Ken Arnold 1 Outline Timer/Counters Serial Port More 8051 Instructions Examples Copyright 2000-2004

More information

Highlights. FP51 (FPGA based 1T 8051 core)

Highlights. FP51 (FPGA based 1T 8051 core) Copyright 2017 PulseRain Technology, LLC. FP51 (FPGA based 1T 8051 core) 10555 Scripps Trl, San Diego, CA 92131 858-877-3485 858-408-9550 http://www.pulserain.com Highlights 1T 8051 Core Intel MCS-51 Compatible

More information

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture Department of Electrical Engineering Lecture 4 The 8051 Architecture 1 In this Lecture Overview General physical & operational features Block diagram Pin assignments Logic symbol Hardware description Pin

More information

C51 Family. Architectural Overview of the C51 Family. Summary

C51 Family. Architectural Overview of the C51 Family. Summary Architectural Overview of the C51 Family C51 Family Summary 1. Introduction............................................................ I.1. 1.1. TSC80C51/80C51/80C31.................................................................

More information

Assembly Language programming (2)

Assembly Language programming (2) EEE3410 Microcontroller Applications LABORATORY Experiment 2 Assembly Language programming (2) Name Class Date Class No. Marks Arithmetic, Logic and Jump instructions Objectives To learn and practice the

More information

MCS -51 Programmer s Guide and Instruction Set

MCS -51 Programmer s Guide and Instruction Set MCS -51 Programmer s Guide and Instruction Set November 1992 Order Number 270249-003 COPYRIGHT INTEL CORPORATION 1996 MCS -51 PROGRAMMER S GUIDE AND INSTRUCTION SET CONTENTS PAGE MEMORY ORGANIZATION 1

More information

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

ET355 Microprocessors Thursday 6:00 pm 10:20 pm ITT Technical Institute ET355 Microprocessors Thursday 6:00 pm 10:20 pm Unit 4 Chapter 6, pp. 139-174 Chapter 7, pp. 181-188 Unit 4 Objectives Lecture: BCD Programming Examples of the 805x Microprocessor

More information

8051 Programming: Arithmetic and Logic

8051 Programming: Arithmetic and Logic 8051 Programming: Arithmetic and Logic EE4380 Fall 2002 Class 4 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Topics Signed and Unsigned arithmetic Binary

More information

~: Simple Programs in 8051 assembly language :~

~: Simple Programs in 8051 assembly language :~ ~: Simple Programs in 8051 assembly language :~ Here some simple programs of 8051 are given to understand the operation of different instructions and to understand the logic behind particular program.

More information

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue Control Transfer Instructions Jump, Loop, and Call 1 Jump Instructions JZ label ; Jump if A=0 JNZ label ; Jump if A!=0 DJNZ reg, label ; Decrement and Jump if A (or reg.)!=0 CJNE A, byte ; Compare and

More information

8051 Core Specification

8051 Core Specification 8051 Core Specification Authors: Jaka Simsic Simon Teran jakas@opencores.org simont@opencores.org Rev. 0.1 August 14, 2001 First Draft www.opencores.org Rev 0.1 First Draft 1 of 26 Revision History Rev.

More information

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization Program Memory The 80C51 has separate address spaces for program and data memory. The Program memory can be up to 64k bytes long. The lower 4k

More information

Chapter Family Microcontrollers Instruction Set

Chapter Family Microcontrollers Instruction Set Chapter 4 8051 Family Microcontrollers Instruction Set Lesson 5 Program Flow Control and Interrupt Flow Control Instructions 2 Branch instructions- Jump to new value of Program Counter (PC) LJMP address16

More information

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.6 Arithmetic and Logics Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Arithmetic instructions Signed number operations Logic

More information

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000, 8051 TUTORIAL Donal Heffernan University of Limerick May-2002 8051 Tutorial D.Heffernan 2000, 2001 1 Blank 8051 Tutorial D.Heffernan 2000, 2001 2 Some reference material: Test books + MacKenzie Scott.

More information

ENE 334 Microprocessors

ENE 334 Microprocessors Page 1 ENE 334 Microprocessors Lecture 10: MCS-51: Logical and Arithmetic : Dejwoot KHAWPARISUTH http://webstaff.kmutt.ac.th/~dejwoot.kha/ ENE 334 MCS-51 Logical & Arithmetic Page 2 Logical: Objectives

More information

Y51 Microcontroller. Technical Manual

Y51 Microcontroller. Technical Manual Y51 Microcontroller Technical Manual Disclaimer Systemyde International Corporation reserves the right to make changes at any time, without notice, to improve design or performance and provide the best

More information

Assembly Language programming (3)

Assembly Language programming (3) EEE3410 Microcontroller Applications LABORATORY Experiment 3 Assembly Language programming (3) Name Class Date Class No. Marks Conditional Program Branching and Subroutine Call in 8051 Objectives To learn

More information

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm NAME as31 - An Intel 8031/8051 assembler SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm DESCRIPTION As31 assembles infile.asm into one of several different output formats. The output

More information

8051 Microcontroller Assembly Programming

8051 Microcontroller Assembly Programming 8051 Microcontroller Assembly Programming EE4380 Fall 2002 Class 3 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Topics Machine code 8051 Addressing Modes

More information

MICROPROCESSOR LABORATORY MANUAL

MICROPROCESSOR LABORATORY MANUAL MICROPROCESSOR LABORATORY MANUAL T.C. AYDIN ADNAN MENDERES UNIVERSITY ENGINEERING FACULTY ELECTRICAL & ELECTRONICS ENGINEERING DEPARTMENT Prepared by: Res. Asst. Abdullah GÜLDEREN Aydın 2019 Contents 1.

More information

Principle and Interface Techniques of Microcontroller

Principle and Interface Techniques of Microcontroller Principle and Interface Techniques of Microcontroller --8051 Microcontroller and Embedded Systems Using Assembly and C LI, Guang ( 李光 ) Prof. PhD, DIC, MIET WANG, You ( 王酉 ) PhD, MIET 杭州 浙江大学 2014 Chapter

More information

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary C51 Family Programmer s Guide and Instruction Set Summary 1. Memory Organization.................................................... I.3.2 1.1. Program Memory.......................................................................

More information

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text 1. Interrupt An interrupt is the occurrence of a condition--an event --

More information

Application Brief D-005

Application Brief D-005 Interfacing the Avago HDSP-2xxx LED Alphanumeric Displays with the Intel 8751H Microcontroller Application Brief D-005 Introduction The HDSP-21xx/-25xx series of products is ideal for applications where

More information

Arithmetic and Logic

Arithmetic and Logic 8051 - Arithmetic and Logic EE4380 Fall 2001 Class 8 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Signed Arithmetic - Concepts Representation of the sign

More information

AL8051S 8-BIT MICROCONTROLLER Application Notes

AL8051S 8-BIT MICROCONTROLLER Application Notes AL8051S 8-BIT MICROCONTROLLER Application Notes 6-14-2012 Table of Contents GENERAL INFORMATION... 3 FEATURES... 3 Key features... 3 Design features... 3 INTERFACE... 4 Symbol... 4 Signal description...

More information

CPEG300 Embedded System Design. Lecture 8 Timer

CPEG300 Embedded System Design. Lecture 8 Timer CPEG300 Embedded System Design Lecture 8 Timer Hamad Bin Khalifa University, Spring 2018 Review 8051 port and port schematic Internal read/write data path Serial communication vs. parallel communication

More information

Introduction To MCS-51

Introduction To MCS-51 Introduction To MCS-51 By Charoen Vongchumyen Department of Computer Engineering Faculty of Engineering KMITLadkrabang 8051 Hardware Basic Content Overview Architechture Memory map Register Interrupt Timer/Counter

More information

UNIT MICROCONTROLLER AND ITS PROGRAMMING

UNIT MICROCONTROLLER AND ITS PROGRAMMING M i c r o p r o c e s s o r s a n d M i c r o c o n t r o l l e r s P a g e 1 UNIT-7 8051 MICROCONTROLLER AND ITS PROGRAMMING INTRODUCTION The microcontroller incorporates all the features that are found

More information

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS Addition of Unsigned Numbers The instruction ADD is used to add two operands Destination operand is always in register A Source operand can be a register,

More information

Microcontroller and Embedded Systems:

Microcontroller and Embedded Systems: Microcontroller and Embedded Systems: Branches: 1. Electronics & Telecommunication Engineering 2. Electrical & Electronics Engineering Semester: 6 th Semester / 7 th Semester 1. Explain the differences

More information

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1) Department of Electrical Engineering Lecture 5 8051 Assembly Language Programming (1) 1 In this Lecture 8051 programming model Assembly language syntax Operation codes and operands Machine instructions

More information

ELEG3924 Microprocessor

ELEG3924 Microprocessor Department of Electrical Engineering University of Arkansas ELEG3924 Microprocessor Ch.3 Jump, Loop, and Call Dr. Jing Yang jingyang@uark.edu 1 OUTLINE Loop and Jump instructions Call instructions Time

More information

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes 8051 Software Overview: 1. Addressing Modes 2. Instruction Set 3. Programming 8051 Addressing Modes: UNIT-III ASSEMBLY LANGUAGE PROGRAMMING The CPU can access data in various ways, which are called addressing

More information

Interrupt Programming: Interrupts vs. Polling Method:

Interrupt Programming: Interrupts vs. Polling Method: UNIT 4: INTERRUPT PROGRAMMING & SERIAL COMMUNICATION WITH 8051: Definition of an interrupt, types of interrupts, Timers and Counter programming with interrupts in assembly. 8051 Serial Communication: Data

More information

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution: Assignment 2 1. Assume that 5 binary data items are stored in RAM locations starting at 50h, as shown below. Write a program to find the sum of all the numbers. The calculation is in 16-bit format and

More information

CS 320. Computer Architecture Core Architecture

CS 320. Computer Architecture Core Architecture CS 320 Computer Architecture 8051 Core Architecture Evan Hallam 19 April 2006 Abstract The 8051 is an 8-bit microprocessor designed originally in the 1980 s by the Intel Corporation. This inexpensive and

More information

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions Programming in Assembler Need knowledge of CPU 8051 Programmers model what registers are available? what memory is available? code memory (for programs) data memory (for variables and the stack) what instructions

More information

Microcontroller and Applications

Microcontroller and Applications S.Y. Diploma : Sem. IV [DE/EJ/ET/EN/EX/EQ/IS/IC/IE] Microcontroller and Applications Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define

More information

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen 8051 Single Board Monitor Programming Monitor Program Available Monitor Program Minmon - Yeralan & Ahluwalia Programming and Interfacing the 8051 Microcontroller PaulMon1 & PaulMon2 - Paul Stoffregen http://www.pjrc.com/tech/8051

More information

Introduction to uc & Embedded Systems

Introduction to uc & Embedded Systems Introduction to uc & Embedded Systems Prepared by, Tamim Roshdy Embedded Systems What is an embedded system? An embedded system is an application that contains at least one programmable computer (typically

More information

ELEG3923 Microprocessor Ch.9 Timer Programming

ELEG3923 Microprocessor Ch.9 Timer Programming Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.9 Timer Programming Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Programming 8051 Timers Counter programming Timer programming

More information

MICROPROCESSOR & MICROCONTROLLER

MICROPROCESSOR & MICROCONTROLLER a) From road north to East From road east to north From road south to west From road west to south From road west to north b) From road north to East From road south to west From road south to north From

More information

ET2640 Microprocessors

ET2640 Microprocessors ET2640 Microprocessors Unit -2 Processor Programming Concepts Basic Control Instructor : Stan Kong Email : skong@itt-tech.edu Figure 2 4 Bits of the PSW Register 8051 REGISTER BANKS AND STACK 80 BYTES

More information

اصول ميکروکامپيوترها استاد درس: دکتر http://ee.iust.ac.ir/rahmati/index.htm rahmati@iust.ac.ir ا درس Email و Website برای تکاليف و... : http://eel.iust.ac.ir/rahmati/ ١ هجدهم فصل ا شنايی با تايمرهای 8051

More information

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Loop and Jump instructions Call instructions Time delay

More information

CPEG300 Embedded System Design. Lecture 6 Interrupt System

CPEG300 Embedded System Design. Lecture 6 Interrupt System CPEG300 Embedded System Design Lecture 6 Interrupt System Hamad Bin Khalifa University, Spring 2018 Correction Lecture 3, page 18: Only direct addressing mode is allowed for pushing or popping the stack:

More information

EE6502- MICROPROCESSOR AND MICROCONTROLLER

EE6502- MICROPROCESSOR AND MICROCONTROLLER . EE6502- MICROPROCESSOR AND MICROCONTROLLER UNIT III - 8051 MICROCONTROLLER PART - A 1. What is Microcontroller? A device which contains the microprocessor with integrated peripherals like memory, serial

More information

8051 Programming using Assembly

8051 Programming using Assembly 8051 Programming using Assembly The Instruction Addressing Modes dest,source ; dest = source A,#72H ;A=72H A, # r ;A= r OR 72H R4,#62H ;R4=62H B,0F9H ;B=the content of F9 th byte of RAM DPTR,#7634H DPL,#34H

More information

JUMP, LOOP AND CALL INSTRUCTIONS

JUMP, LOOP AND CALL INSTRUCTIONS JUMP, LOOP AND CALL INSTRUCTIONS After you have understood the tutorial on Introduction to assembly language which includes simple instruction sets like input/output operations, now it s time to learn

More information

MODULE-1. Short Answer Questions

MODULE-1. Short Answer Questions MODULE-1 Short Answer Questions 1. Give the comparison between microprocessor and microcontroller. It is very clear from figure that in microprocessor we have to interface additional circuitry for providing

More information

INTERRUPTS PROGRAMMING

INTERRUPTS PROGRAMMING INTERRUPTS PROGRAMMING The 8051 Microcontroller and Embedded Systems: Using Assembly and C Mazidi, Mazidi and McKinlay Chung-Ping Young 楊中平 Home Automation, Networking, and Entertainment Lab Dept. of Computer

More information

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU Summary Core Reference CR0115 (v2.0) March 13, 2008 The TSK51x is a fully functional, 8-bit microcontroller, incorporating the Harvard architecture. This core reference includes architectural and hardware

More information

Question Bank Microprocessor and Microcontroller

Question Bank Microprocessor and Microcontroller QUESTION BANK - 2 PART A 1. What is cycle stealing? (K1-CO3) During any given bus cycle, one of the system components connected to the system bus is given control of the bus. This component is said to

More information

8051 Microcontroller

8051 Microcontroller 8051 Microcontroller 1 Salient Features (1). 8 bit microcontroller originally developed by Intel in 1980. (2). High-performance CMOS Technology. (3). Contains Total 40 pins. (4). Address bus is of 16 bit

More information

CHAPTER 11 INTERRUPTS PROGRAMMING

CHAPTER 11 INTERRUPTS PROGRAMMING CHAPTER 11 INTERRUPTS PROGRAMMING Interrupts vs. Polling An interrupt is an external or internal event that interrupts the microcontroller To inform it that a device needs its service A single microcontroller

More information

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text In this lecture embedded C program for interrupt handling

More information

8051 Instruction Set

8051 Instruction Set 8051 Instruction Set 23-ug-16 ptkarule@rediffmail.com 1 Programmers Model of 8051 7FH 30H 2FH 20H 1FH 00H General Purpose Bit addressable Register Banks 1FH 18H 17H 10H 0FH 08H 07H 00H R7 R6 R5 R4 R3 R2

More information

8051 Microcontroller. Ali Ziya Alkar 1

8051 Microcontroller. Ali Ziya Alkar 1 8051 Microcontroller Ali Ziya Alkar 1 8051 Introduction 8051 is one of the most popular microcontrollers in use today. Many derivative microcontrollers have since been developed that are based on--and

More information

Q.1. A) Attempt any THREE of the following:

Q.1. A) Attempt any THREE of the following: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas 8051 - Interrupts EE4380 Fall 2001 Class 9 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Polling Vs Interrupts Polling: MCU monitors all served devices continuously,

More information

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS Looping Repeating a sequence of instructions a certain number of times is called a loop Loop action is performed by DJNZ reg, Label The register is decremented

More information

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas 8051 Timers Class 7 EE4380 Fall 2002 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Introduction Timers Timing devices - Generate specific time delay Event

More information

1. Write A Program to move a block of data within the internal RAM

1. Write A Program to move a block of data within the internal RAM UNIT 2: Example Programs. 1. Write A Program to move a block of data within the internal RAM Org 0h start1: mov r0,#40h ;r0 pointed to internal RAM 40h mov r1,#30h ;r1 pointing to internal RAM 030h mov

More information

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution 1. (a) 1. (b) T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution Priority modes. 1) Fully Nested Mode : It is a general purpose mode. IR 0 highest priority IR 1 lowest

More information

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING CHAPTER 2 8051 ASSEMBLY LANGUAGE PROGRAMMING Registers Register are used to store information temporarily: A byte of data to be processed An address pointing to the data to be fetched The vast majority

More information

Legacy documentation refer to the Altium Wiki for current information. TSK52x MCU

Legacy documentation refer to the Altium Wiki for current information. TSK52x MCU Legacy documentation TSK52x MCU Summary Core Reference CR0116 (v2.0) March 13, 2008 The TSK52x is a fully functional, 8-bit microcontroller, incorporating the Harvard architecture. This core reference

More information

UNIT MICROCONTROLLER

UNIT MICROCONTROLLER Page UNIT-5 805 MICROCONTROLLER INTRODUCTION The microcontroller incorporates all the features that are found in microprocessor. The microcontroller has built in ROM, RAM, Input Output ports, Serial Port,

More information

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code:

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code: MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code: 17534 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following.

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following. MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following. (9M) 1) Describe the instructions SWAP A and MOVX@DPTR,A with one example. (3Marks) SWAP A

More information

Contents. Join the Technical Community Today!

Contents. Join the Technical Community Today! Contents CHAPTER 1: INTRODUCTION... 5 1. WELCOME... 5 1.2 PS 8051 BOARD OVERVIEW... 6 1.3 PS 8051 SPECIFICATIONS... 7 CHAPTER 2: SYSTEM DESCRIPTION... 9 2.1 HARDWARE... 9 2.2 MAPPING OF DEVICES... 11 2.2.1

More information

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip.

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip. EXPERIMENT NO.1 AIM: Study of 8051 Microcontroller TOOLS: 8051 kit THEORY: Salient Features of 8051 A Microcontroller is a complete computer system built on a single chip. It contains all components like

More information

8051 Microcontrollers

8051 Microcontrollers 8051 Microcontrollers Richa Upadhyay Prabhu NMIMS s MPSTME richa.upadhyay@nmims.edu March 8, 2016 Controller vs Processor Controller vs Processor Introduction to 8051 Micro-controller In 1981,Intel corporation

More information