Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

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

Microcontroller Intel [Instruction Set]

SN8F5000 Family Instruction Set

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Programming of 8085 microprocessor and 8051 micro controller Study material

8051 Overview and Instruction Set

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

Module Contents of the Module Hours COs

Digital Blocks Semiconductor IP

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Microcontroller

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

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

DR bit RISC Microcontroller. Instructions set details ver 3.10

Dodatak. Skup instrukcija


Microcontroller. Instruction set of 8051

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

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

Embedded Controller Programming

C51 Family. Architectural Overview of the C51 Family. Summary

Instruction Set Of 8051

Dragonchip. Instruction Set Manual

Assembly Language programming (2)

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

8051 Microcontroller Assembly Programming

8051 Microcontrollers

Highlights. FP51 (FPGA based 1T 8051 core)

Principle and Interface Techniques of Microcontroller

TUTORIAL Assembly Language programming (2)

8051 Core Specification

Assembly Language programming (3)

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

Application Brief D-005

Chapter Family Microcontrollers Instruction Set

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

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

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

MCS -51 Programmer s Guide and Instruction Set

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

AL8051S 8-BIT MICROCONTROLLER Application Notes

MICROCONTROLLER AND PLC LAB-436 SEMESTER-5

Contents. Join the Technical Community Today!

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

Introduction To MCS-51

Y51 Microcontroller. Technical Manual

8051 Instruction Set

8051 Programming: Arithmetic and Logic

MICROPROCESSOR LABORATORY MANUAL

ELEG3924 Microprocessor

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

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

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

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call

UNIT MICROCONTROLLER AND ITS PROGRAMMING

Principle and Interface Techniques of Microcontroller

Introduction to uc & Embedded Systems

8051 Programming using Assembly

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

MODULE-1. Short Answer Questions

Question Bank Microprocessor and Microcontroller

CPEG300 Embedded System Design. Lecture 3 Memory

ENE 334 Microprocessors

~: Simple Programs in 8051 assembly language :~

Arithmetic and Logic

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

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Microcontroller and Applications

EE6502- MICROPROCESSOR AND MICROCONTROLLER

D: arc SRC KUT51 KUT51LCD.LST KUT51LCD PAGE 1

CPEG300 Embedded System Design. Lecture 6 Interrupt System

CS 320. Computer Architecture Core Architecture

8051 Microcontroller

ET2640 Microprocessors

Chapter 9. Programming Framework

Lab-Report Microprocessors

Figure Programming model

MICROPROCESSOR & MICROCONTROLLER

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

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

UNIT MICROCONTROLLER

Module I. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC.

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

Application Brief D-002

CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

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

Assembly Language Programming of 8085

8051 Microcontroller Logical Operations. Prepared by : A. B. Modi Target Audience : 5 th Semester Students

VRS570 32K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU VRS580 64K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU

JUMP, LOOP AND CALL INSTRUCTIONS

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

Chapter 3. Bit Addressable Area. By DeccanRobots

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Transcription:

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 Experiment 3 Binary and BCD addition...13 Experiment 4 Fun with LED running...15 Experiment 5 Two's complement...16 Experiment 6 Internal and external memory...17 Experiment 7 STACK memory...18 Experiment 8 Subroutine...19 Experiment 9 Interrupt...1 Experiment 10 UART communication...4 Experiment 11 Using Watchdog timer...7 Appendix I Special Function Registers II 8051 Instruction hex code

Overview This Programming Book is designed for school students to learn basic of microcontroller technology with the 8051 Microcontroller kit. Students will learn how to program the 8051 microcontroller with machine code. The program will be very short and easy to understand. SAFTY INFORMATION The 7-segment LED and dot LED indicators are high brightness, to protect your eye, play it under enough lighting or in daytime is recommended. The kit is bare board, no housing, do not touch the conductive part of PCB with hand while the kit is powered on. The beep sound is quite loud so it may unpleasant for some place, you can turn off the beep with mute key. The voltage regulator 7805 is hot when using with AC adapter with output >1VDC. Tools 1.. 3. 8051 Microcontroller kit AC adapter with DC output +9V approx. 00mA or higher. RS3 cross cable for Experiment 10 UART communication 3

Experiment 1: Blinking LED Q1 I see the KIT has LED connected to PORT1 bit 7 or P1.7. How can we make it blinking? A1 Making LED blinking is simple with some board. The 8051 kit is the same, simple but not easy. We will learn the basic circuit and the use of logical instruction. Let us take a look at the hardware connection of P1.7 LED. P1.7 is bit 7 of PORT1 register. PORT1 is 8-bit register located in the internal data memory at location 90H. See the register map in Appendix I. P1.7 has bit address located at 97H. To make the LED turns on, logic at P1.7 must be '0'. The current will flow from +5V through R3, D10 and enter to the P1.7 bit then to GND pin. Logic '0' for P1.7 is approx. +0.7V. We have KCL, Kirchhoff's Current Law1 equation as, +5V = I*R3 + VF + 0.7V VF is forward voltage of the LED ~.0V I is DC current I = (+5V -.0V 0.7V)/330 We get I ~7mA. This is the forward current injected into PN junction. The electric filed at the junction provides jumping level for the recombination of electron and hole from conduction band to valence band which is will transform to light. The LED color is proportional to the energy gap. 1 https://en.wikipedia.org/wiki/kirchhoff's_circuit_laws 4

https://en.wikipedia.org/wiki/light-emitting_diode With logic '1' at P1.7, this forward current will be very small. Thus turn off the LED. What is the computer code to make it blinking? Here is our code. Line 1 Line Line 3 loop turn LED on tun LED off JUMP back to loop We see that there will need three steps to make the LED blinking. What is the 8051 code? We found the instruction that makes a specified bit to logic '0'. CLR bit To make a bit to be logic '1'. SETB bit And JMP instruction JMP loop What is the bit? In our case we will use bit P1.7. The 8051 instructions will be like this. loop CLR P1.7 SETB P1.7 JMP loop How can we test it with 8051 Kit? The 8051 will understand such instruction or not? Luckily, the 8051 kit accepts hex code that represents 8051 instruction. 5

Let us look at the instruction hex code for 8051 microcontroller at the Appendix I. We found a group of BIT logical instructions. BIT logical HEX BYTE INSTRUCTION 7 8 A0 B0 ORL ANL ORL ANL C, bit C, bit C, /bit C, /bit B B3 C C3 D D3 1 1 1 CPL CPL CLR CLR SETB SETB bit C bit C bit C CLR bit instruction has two bytes HEX code i.e., C and bit location. So for CLR P1.7 the hex code will be C and 97. What is the hex code for SETB P1.7? It is D and 97. Now let us find the hex code for JMP LOOP instruction. JUMP 01 1 41 61 81 A1 C1 E1 AJMP AJMP AJMP AJMP AJMP AJMP AJMP AJMP addr11 addr11 addr11 addr11 addr11 addr11 addr11 addr11 0 80 3 LJMP addr16 SJMP offset We found LJMP addr16 (Long Jump) has three bytes, 0, XX, YY. What are XX and YY? In order to let the CPU executes the code, we must store these codes to the memory! Where is the location of memory we can store these codes? 8051 calls the memory space for storing the code as code memory. For our 6

kit, it provides address from 8000H to FFFFH. Key PC will set displayed address to 9000H when pressed. Details of memory map is explained in the User's manual, http://www.kswichit.com/8051kit/8051kitusermanual.pdf We will place it started from location 9000H. Here is the sample code or program that includes location and hex code. Address 9000 900 9004 hex code label C 97 LOOP D 97 0 90 00 instruction CLR P1.7 SETB P1.7 LJMP LOOP We see that the LOOP location is 9000 where the LJMP will jump to. Symbol LOOP is called label. It is used for placing where the CPU will jump to. We see that LJMP LOOP have 3 bytes hex code, i.e., 0, 90, 00. 0 is LJMP and 90 00 is the location where to jump to. How many byte of this small program? It is 7 bytes. Storing the hex code into memory will be byte by byte begin at location 9000. Address Code 9000 C 9001 97 900 D 9003 97 9004 0 9005 90 9006 00 Testing the code Enter the hex code to the kit using hex keys and key + for next address. When finished, press PC to 9000, then press key STEP. We see that every time the instruction CLR P1.7 was executed, the LED will be turned on. And the LED will be turned off at SETB P1.7. If we press key STEP still, what is happening? Can we write smaller code that produces the same blinking? We can use CPL BIT, Complement BIT instruction. 7

BIT logical HEX BYTE INSTRUCTION 7 8 A0 B0 ORL ANL ORL ANL C, bit C, bit C, /bit C, /bit B B3 C C3 D D3 1 1 1 CPL CPL CLR CLR SETB SETB bit C bit C bit C Now the code will be LOOP CPL P1.7 AJMP LOOP The hex code for CPL P1.7 is B, 97. And AJMP LOOP is 01, 00. AJMP uses only lower 11-bit of destination address. This address is merged into the hex code. It has only two bytes. LJMP instead will have three bytes. Finding hex code for the AJMP is easy with ALT, AJMP keys. Address 9000 900 hex code B 97 01 00 label instruction LOOP CPL P1.7 AJMP LOOP We see that now the program has only FOUR BYTES! Address Code 9000 B 9001 97 900 01 9003 00 Testing the code Enter the hex code to the kit using hex keys and key + for next address. Press key PC, then STEP to test it. Did you get the same blinking? 8

We have tested with single instruction execution by using key STEP. So we can see the LED blinking rate the same as repeat rate of the key that pressed. What is the CPU speed running? How to test it? Press RESET then PC, then key GO. Did you see the blinking? Key GO will let CPU to jump from monitor program to user program and run with CPU speed. Each instruction will need time to execute 1 4 oscillator periods. For example, Instruction Oscillator period CPL P1.7 1 AJMP LOOP 4 One machine cycle for 8051 is 1 clocks. Our kit has oscillator frequency 11.059MHz. Thus for CPL P1.7 it will take time equal to 1/11.059Hz=1.08µs. For AJMP LOOP,.17µs. So with CPU speed running, not under monitor control speed. We can not see the blinking with such very high rate. We can see the LED blinking again by the use of small delay code. Address Hex code 9000 B 97 900 9005 9006 9009 90 00 00 A3 85 83 D0 50 FA 900B 01 00 Label Instruction main CPL P1.7 loop MOV DPTR,#0 INC DPTR MOV PSW,DPH JNC loop AJMP main The code that inserted will provide a short delay before CPL P1.7 to be repeated again. We put at the center. The delay code uses 16-bit data in DPTR register, increment it until the left most bit becomes '1' or from 0000 to 8000H. We check the Left most bit by copying DPH to the PSW register where we have the Carry bit (see special function register in Appendix I) So we can test it with Jump if NO CARRY back to the LOOP. If carry is set then execute AJMP main to repeat running again. Enter the code and test run by key GO. You can see the blinking again. Can you change the speed of blinking faster? How? 9

Experiment : Binary number counting Q1 How do computer count the binary number? A1 We can write small code to show binary counting by using the Accumulator register. The 8051 kit provides 8- bit debugging LED. It will show the contents of Accumulator register under Single-Stepping with key STEP. LOOP INC A AJMP LOOP This code has only two instructions, INC A and AJMP LOOP. What is the INC A? It is the instruction that increments register A by one. What is register A? Register A is one byte memory. It is used for storing the 8-bit data. The chip designer calls it as the ACCUMULATOR register. Many arithmetic and logical instructions use the accumulator to store the results. Can you convert the program into hex code? See the Appendix II for hex code. Address hex code label 9000 9001 04 01 00 instruction LOOP INC A AJMP LOOP We see that our program has only 3 bytes, 04, 01 and 00. We can enter the code byte by byte from 9000 to 900. Test it using key PC, then STEP. What is happening at the debugging LED? Can you write down counting number in binary by observing the debugging LED? LED ON is 1 and LED OFF is 0. Started from 0000 0000. Decimal counting Binary counting 0 0000 0000 1 0000 0001 3 4 5 10

6 7 8 9 10 11 1 13 14 15 We see that the binary number for decimal 15 is 0000 1111. Instead of decimal number, we can have hexadecimal to represent the binary number as well. Write down again to this table with binary number. Decimal number Hex number Binary number 0 0 0000 0000 1 1 0000 0001 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 1 C 13 D 14 E 15 F We see that from 10 to 15 in decimal number, hex number will use A to F. We found 4-bit binary number can be represented with single letter hex number. Thus for 8-bit we can use only two hex digits, 11

For example, 1111 1111, we can write in hex FF. For 16-bit binary number we can use 4 digits hex. For example, 1111 1111 1111 1111, we can write in hex FFFF. Did you see when the count is FF or 1111 1111, if we press key STEP to execute INC A, what is the result? The count value will be zero. After FF or 55 in decimal number, it should be 56 or 100H, right. The result will be zero in accumulator. No carry flag. The accumulator has only 8-bit. It can store only 8-bit result. Let us see another example that produces the same but we get the correct result. 9000 9001 4 01 01 00 LOOP ADD A,#1 AJMP LOOP We use instruction ADD A,#1, add Accumulator with immediate data 1. Sharp symbol # indicates the value is immediate data. Test the code by entering hex codes to the memory and press STEP. When the count is FF and press key STEP to execute ADD A,#1, what is happening? Did you see the Carry Flag LED turn on? The result will be 1 00, Carry flag will be set. With Carry flag, we can use it for multiple byte addition correctly. We can use ADC A,#n for the next byte. It will ADD with carry flag from the lower byte correctly. I like to see the counting with key GO. How to do that? 9000 4 01 900 9005 90 01 00 F0 9006 9009 900A 900D 90 00 00 A3 85 83 D0 50 FA 900F 01 00 START ADD A,#1 MOV DPTR,#100H MOVX @DPTR,A loop MOV DPTR,#0 INC DPTR MOV PSW,DPH JNC loop AJMP START We have inserted two portions of code. The 1st portion is to write the accumulator to the debugging LED which is located at 100H. The nd portion is from Experiment 1, the delay using DPTR register. Enter the code and now test it with key GO. 1

Experiment 3: Binary and BCD Addition Q1 I have two variables, 19H and 91H. How to add them and show the result in 8-bit binary number? A1 We can use Accumulator register loaded with first data and add it with the second data. Line 1 Line start Load A with 19H Add A with 91H ; A = A+91H Adding two variables in the CPU will perform in the ALU (Arithmetic and Logical Unit). A=A+91H ALU A 91H In the ALU, it has binary adder circuit that produces the result of 8-bit binary number. Can you compute by hand? Hex number 19H 91H+ XX Better try with binary addition. 1+1= 10. 0001 1001 1001 0001+ Keep the result in mind. Now let us try with 8051 coding. ADDR HEX code 9000 9001 74 19 4 91 Instruction START MOV A,#19H ADD A,#91H Very simple and similar to last experiment. Enter the code and test run with key, PC and then STEP to ADD A,#91H 13

What is the result that shows on the debugging LED? The same as hand computing or not? Now let us modify both variables to FFH and 0. Again try with hand compute. Modify the code and test it with 8051 running. Did you see CY LED? What is the result? You can choose any variables and play with your friends by asking hand compute and check the result with 8051 kit. Discuss the result on the CY LED and debugging LED. BCD number addition 8051 has special instruction DA A, Decimal Adjust Accumulator for adjusting the result from binary addition to BCD number. Suppose we have two BCD numbers, 19 and 71. We want to add them. ADDR HEX code 9000 9001 9003 74 19 4 71 D4 Instruction START MOV A,#19H ADD A,#71H DA A ; load A with 19 ; add A with 71 ; adjust result to BCD Enter the code and test it with single stepping. What is the result after ADD A,#71H? What is the result after DA A instruction? We see that ADD A,#n is for binary number addition. However if we insert DA A following the ADD instruction, the result will be adjusted to BCD number correctly. 14

Experiment 4: Fun with LED running Q1 I have seen the LED tube that produces LED running, how can we make it by using the 8-bit debugging LED. A1 8051 has instruction that rotates bit. We can use it for making such running LED easily. The work should be like this. START LOOP Load A with 0000 0001 ROTATE LEFT A JUMP LOOP The RL A or rotate left accumulator will shift bit every bit LEFT one bit position. Bit 7 will be rotated into bit 0. 0000 0001 Accumulator Let us see the 8051 code. ADDR HEX code 9000 900 9003 74 01 3 01 0 Instruction MOV A,#1 LOOP RL A AJMP LOOP Enter the code to memory, press PC then STEP. Did you see the LED running at the 8-bit debugging LED? If we change RL A to RLC A, what is happening? Can you change the direction from right-to-left to left-to-right, how? Can you make the running from right to left then back to right repeatedly, how? 15

Experiment 5: Two's complement Q1 How can I make negative number using two's complement. A1 Two's complement is One's complement + 1. Suppose we want to subtract Accumulator with 1, how to do that using two's complement. Number 1 in 8-binary is 0000 0001 Making two's complement with One's complement + 1. One's complement of 0000 0001 is 1111 1110 Then Add it with 1. 1111 1110+ 0000 0001 1111 1111 We get 1111 1111 or FF is -1. What is happening if we add FF to the Accumulator. Here is the code. ADDR HEX code 9000 900 9003 74 FF 4 FF 01 0 Instruction MOV A,#FFH LOOP ADD A, #-1 AJMP LOOP Enter the code and test it with single stepping. We see that the accumulator contents will be decremented by one every time at the ADD A,#-1 instruction. Can you make the decrement from -1 to -, how? 16

Experiment 6: Internal and external memory Q1 How can we access the internal or external memory? A1 8051 has two spaces for memory i.e., internal and external memory. For internal or on-chip memory, location from 00-7FH we can use DIRECT addressing to access it. From 80H-FFH we must use INDIRECT addressing. If we use DIRECT addressing for location 80HFFH, it will access special function registers instead. For external memory we can use MOVX or MOVC with INDIRECT addressing to access it. ADDR HEX code Instruction 9000 900 9005 E5 7F 90 90 10 F0 MOV A,7FH MOV DPTR,#9010H MOVX @DPTR,A The 1st instruction MOV A,7FH (no # symbol) will copy the internal memory at location 7FH to Accumulator. This is DIRECT addressing. Read data from the on-chip memory directly. The nd instruction MOV DPTR,#9010H will load DPTR register with immediate value 9010. This value will be location of external memory. The 3rd instruction MOVX @DPTR,A will copy the contents of Accumulator to external memory pointed to by DPTR. Enter the code and test it with single stepping. Before test the code, write down the contents of location 7F (internal memory) and 9010(external memory). Use ALT 5(ONCHIP RAM) and key + or to access the internal RAM. For external RAM, use key ADDR and key + or -. After test the code then write down the result. Before After Onchip 7F = Onchip 7F = External 9010= External 9010= Can you copy the external memory location 9011 to internal memory location 80? How? 17

Experiment 7: STACK memory Q1 What is STACK memory? How to access it? A1 STACK memory is the memory space allocated for saving RETURN address from CALL instruction. Storage in STACK memory will be in STACK level. The TOP of STACK location will be pointed to by STACK pointer register, SP. We can access stack memory properly with instruction PUSH and POP instruction. PUSH will place the data to top of stack and POP will retrieve it from top of stack. Let us play with STACK memory. Suppose we want to copy the location 7FH to 7EH using PUSH and POP instructions. ADDR HEX code Instruction 9000 900 C0 7F D0 7E PUSH 7FH POP 7EH The 8051 kit provides USER STACK at location 60H. Thus top of STACK will be location 60H onchip memory. PUSH 7FH will make SP=SP+1, the SP will be 61H then copy the contents of location 7FH to 61H. POP 7EH will copy the contents of top of stack to location 7EH then SP=SP-1. Top of stack will get back to 60H. Enter the code and write down the memory location, stack, SP and stack's contents [SP] after single step. 7E= 7F= SP [SP] before 60H PUSH 7FH 61H POP 7EH 60H Note: For upper block of internal memory, 80H-FFH, PUSH and POP instructions will access to Special Function Registers. 18

Experiment 8: Subroutine Q1 What is the subroutine? A1 Subroutine is a small code that was called by main program. We can make such a small code to be subroutine then use it with CALL instruction. At the end of subroutine we must place RET or return instruction. So the CPU can return to main code and performs other tasks. STACK memory will be used to save the return address. 8051 has two kinds of subroutine calling instructions i.e., ACALL and LCALL. ACALL is Absolute Call. And LCALL is Long Call. ACALL used only 11 bits of the subroutine address. So it can call within kb block. LCALL uses 16 bits address. So it can call the subroutine anywhere in 64kB space. RET can be used for both Calling instructions. We will use LCALL beforehand. Here is the sample code. ADDR HEX code Instruction 9000 900 9005 74 01 1 90 10 80 FE MOV A,#1 LCALL sum SJMP here 9010 901 4 0 here sum ADD A,# RET The subroutine named sum is located at 9010. We see that at the end of subroutine it has RET instruction. When the main code calls subroutine sum, the address next to LCALL sum, 9005 will be saved to STACK memory. When finished, RET will retrieve this saved location 9005 from STACK to the Program Counter register. So the CPU will continue fetching the instruction code follow the LCALL or location 9005. Enter the code from 9000 to 9005 and from 9010 to 901. 19

Write down the result after the instruction was executed. ADDR HEX code Instruction 9000 900 9005 74 01 1 90 10 80 FE MOV A,#1 ; SP= LCALL sum ; SP= [SP]= SJMP here ; jump here 9010 901 4 0 here sum ADD A,# ; A= RET ; SP= Check the results with below illustration. 1 MOV A,#1 LCALL sum SJMP here ADD A,# 3 4 STEP 1 SP = 60H STEP SP = 6H RET STACK MEMORY 0D 60 6 61 60 90 05 0D Program Counter 90 10 Program Counter 90 05 STEP 3 SP = 6H 6 61 60 90 05 0D STEP 4 SP = 60H 60 0D 0

Experiment 9: Interrupt Q1 What is the interrupt of 8051 microcontroller? How to test it with 8051 kit? A1 Interrupt in the microprocessor or microcontroller is the operation that calls to the service routine on special events. We do not need to call the service routine by CALL instruction, instead the CPU's hardware will generate calling mechanism to the interrupt service routine when appropriate interrupt control flags are enabled automatically. The actual process is every machine cycle, the interrupt logic will be polled. So it can call the interrupt service routine on the event based. Our chip, 89S5 has six interrupt sources, external interrupt 0, 1, timer0, 1,. and UART. 1

What is interrupt vectors? The interrupt vector is the location where the CPU will jump to for a given interrupt source. For example External interrupt 0 has vector address 0003. For our kit, when we press INT0 button making active low at INT0 pin, the CPU will save the next program counter to STACK memory then jump to location 0003. When service is completed, the RETI (Return from Interrupt) instruction will retrieve the stored program counter to the program counter register to return to the main program. Interrupt Vector Address External interrupt 0 0003H Timer/counter 0 000BH External interrupt 1 0013H Timer/counter 1 001BH Serial port 003H Timer/counter 00BH To provide interrupt testing by user program, the 8051 kit has relocated these vectors to RAM with base address is 8000H. For external interrupt, the RAM vector will be 8000H+0003 or 8003H. The 8051 kit provides buttons for testing external interrupts, INT0 and INT1. We will test the code that responded to the INT0. ADDR HEX code Instruction 8003 8004 8007 8008 04 SERV_EX0 INC A 90 01 00 MOV DPTR,#0100H F0 MOVX @DPTR,A ; write debugging LED 3 RETI 9000 900 9004 9006 D A8 D AF D 88 80 FE START here SETB EX0 ; enable external int0 SETB EA ; enable ALL SETB IT0 ; detect high to low SJMP here Now we have interrupt service routine for INT0 at location 8003H. The service will increment accumulator A and write to the debugging LED then return to main code. The main code sets EX0 and EA to enable INT0 interrupt logic and type of INT0 signal, then JUMP here. Enter the code then press PC, GO.

What is happening? If we press key INT0, what is happening? Have you notice the counting jump sometime? The logic appeared at pin INT0 will change from high to low when the key was pressed. However with simple circuit that makes High and Low signals using mechanical contact, so the signal at INT0 will be bouncing signal. It will make counting jump. To read the logic signal from key bouncing, we may use the RS flip-flop or monostable stable circuit to make clean signal. The sample RS flipflop that produces clean signal at Q output is shown below. Can you modify the code for another external interrupt, INT1 by decrementing the Accumulator when pressed? Note EX1 bit is located at AAH, IT1 is located at 8AH. Refer to register map in Appendix I. 3

Experiment 10: UART communication Q1 What is UART? How to use it for data communication? A1 UART is short for Universal Asynchronous Receiver and Transmitter. It is the circuit that converts parallel to serial data and vice versa. Main purpose of the UART is for data communication between two computers. Data manipulated in the CPU is 8-bit parallel. If we want to send it to another computer, of course we can send it with 8-bit data. But if we convert the 8-bit parallel to serial data, we will use less wire to send it. Our kit has UART port with RS3 logic. The format is 9600 bit/s 8 data bit, no parity and one stop bit. Student can send the data from one kit to another kit. The RS3 cross cable can be made easily with two DB9 Female connector. Both ends are DB9 female connector. You can get from the computer shop also. UART frame is started with START bit. The data to be sent will be bit 0, 1,... to bit 7 and then STOP bit. Bit period is equal to 1/9600. Above pattern is for 71H. 4

This experiment will need two 8051 kits. Connect them with the RS3 cable. RS3 cross cable Kit # Receiver Kit #1 Transmitter We will use debugging LED to display the 8-bit data received from the transmitter. Let us send a byte from Kit#1 to Kit#. Kit #1 will be transmitter. Kit# will be receiver. 8051 has internal UART hardware, the format has been set by monitor program, 9600 bit/s 8-data bite no parity bit and one stop bit. To send a byte, we will check TI bit, if it is high, then clear it and we can write a byte to SBUF register. The internal UART will shift the data in SBUF to TXD pin serially. Here is the code for Kit#1 transmitter. ADDR HEX code 9000 900 9005 74 41 1 90 07 80 FE 9007 900A 900C 900E 30 99 FD C 99 F5 99 Instruction MOV A,#'A' LCALL COUT SJMP $ COUT JNB TI,$ CLR TI MOV SBUF,A RET The main code will load register A with ASCII code of letter 'A' which is 41H then call subroutine, COUT to send a byte from Accumulator. 5

The subroutine COUT will check TI bit, if it is high then the UART hardware will be ready to accept the byte. We then clear it and write A to SBUF register. Then return to main. The parallel data in A will be shifted out at TXD pin serially. Here is the code for Kit# receiver. ADDR HEX code 9000 9003 9006 9007 1 90 09 90 01 00 F0 80 F7 9009 900C 900E 9010 30 98 FD C 98 E5 99 Instruction RECEIVE LCALL CIN MOV DPTR,#100H MOVX @DPTR,A SJMP RECEIVE CIN JNB RI,$ CLR RI MOV A,SBUF RET The receiver will poll the RI bit in the CIN subroutine. If RI is high then clear it and now we see that we read the data from SBUF. In opposite direction with COUT subroutine. When RI is high, all bits received will be ready to read. The byte being received will write to the debugging LED. Then repeat get the byte continuously. Enter the code for transmitter and receiver. At the receiver, press PC then GO. The receiver will wait for the data from transmitter. At the transmitter, press PC then GO. It will send letter 'A' with ASCII code 41H to the receiver. Did you get 41H or 0100 0001 at the debugging LED of the receiver? While the receiver is still running, we can change the byte at the transmitter. If we send it again, the receiver will show the byte being received. Try change another data byte and send it. The cable is rather short, 1m. Can we use longer cable? The RS3 cable uses negative logic with +3V to +15V for logic '0' and -3V to -15V for logic '1'. The signal is single-end with common ground. Longer cable with different ground voltage could cause undefined logic. Recommendation for this type of signal is limited to short cable. To send/receive longer distant, we must use differential mode, sending with electric current instead. Such standards are RS4 or RS485. 6

Experiment 11: Using Watchdog timer Q1 What is Watchdog timer? How to use it? A1 Our Kit has AT89S5 as the microcontroller. This chip provides special timer, WDT that will RESET the chip in case of out of controlled program flowing. For normal operation, if this watchdog timer has been enabled, the CPU must reset it periodically. To enable the use of WDT, Watch Dog Timer, we must write 1EH and E1H to the WDTRST register at location A6H. WDTRST is write only register. Once enable it, in the main loop running, we must write 1EH and E1H to WDTRTS in order to signal the timer that we are running in normal operation. If the program flowing is not in the main loop, no writing such sequence, the WDT will overflow then produces the reset signal to restart again. "SimpleWatchdogTimer" by Lambtron - Own work. Read more https://en.wikipedia.org/wiki/watchdog_timer Above diagram illustrates the concept of WDT. We see that the time is counter that accepts clock signal. The main computer must reset it before timeout, if not, the timeout signal will reset the main computer. For 89S5 the WDT is 14 bit counter so it will overflow when the count is 4000H. We can calculate time to overflow for 11.059MHz oscillator by 16384*1/Oscillator ~ 17ms We must clear the counter within this period to signify that we are in normal operation. 7

Here is the test code for WDT. Addr Hex code Label Instruction 9000 75 A6 1E 9003 75 A6 E1 START: MOV 0A6H,#1EH ; enable WDT MOV 0A6H,#0E1H 9006 B 97 main: cpl p1.7 9008 90 00 00 900B A3 900C 85 83 D0 MOV dptr,#0 loop: INC dptr MOV psw,dph 900F 30 B3 06 JNB P3.3, SKIP 901 75 A6 1E 9015 75 A6 E1 MOV 0A6H,#1EH ; clear WDT MOV 0A6H,#0E1H 9018 50 F1 jnc loop SKIP: 901A 80 EA ; press INT1 key will skip WDT sjmp main The WDT is enable at START by writing sequence of 1EH and E1H to the WDTRST at location A6H. We test it with LED blinking at P1.7 as the normal operation. At location 901, we insert the same code, writing sequence of 1EH and E1H to the WDTRST, but now it will clear the counter. We use key INT1 or bit P3.3 for skipping the clearing of WDT. This is a test key to see if the WDT is not cleared, what will happen? Enter the code and press key PC, then GO. Did you see normal operation? The LED blinking at P1.7. Let us press key INT1. What is happening? If we press key INT1 or P3.3, JNB P3.3 will jump to 9108, skipping the clearing WDT, so the WDT will overflow then rest the CPU. We will get to 8051 monitor. WDT is useful for remote applications and for making the recovery process automatically. 8

Appendix I Special Function Registers 9

8051 SFR byte and bit locations Accumulator has byte address, E0H. Bit Address is E0H + bit 0-8. For example bit 1 of the Accumulator is located at E1H. Port P1 has byte address 90H. P1.7 is located at 90H+7=97. DPL is non bit addressable. Its byte location is 8H. 30

PSW register(d0h) Carry flag is located at D7H. For example to set Carry flag. We use D D7 SETB PSW.7 or D3 SETB C 31

Timer Control Register, TCON(88h) IT1 is located at Carry 88H+= 8AH. 3

Timer Mode Register, TMOD(89h) 33

Timer Mode Register, TMOD(C9h) 34

Timer Control Register, TCON(C8h) 35

Interrupt Enable Register, IE(A8h) EA bit is located at A8H+7= AFH. EX1 bit is located at A8H+= AAH. 36

Serial Control Register, SCON(98h) 37

Auxiliary Register, AUXR(8Eh) 38

Appendix II 8051 Instruction hex code 39

8051 Instruction hex code MOVE with immediate data Hex Bytes Instruction 74 MOV A, #immediate 75 3 MOV direct, #immediate 76 MOV @R0, #immediate 77 MOV @R1, #immediate 78 MOV R0, #immediate 79 MOV R1, #immediate 7A MOV R, #immediate 7B MOV R3, #immediate 7C MOV R4, #immediate 7D MOV R5, #immediate 7E MOV R6, #immediate 7F MOV R7, #immediate 90 3 MOV DPTR, #immediate MOVE with direct memory location 85 3 MOV direct, direct 88 MOV direct, R0 89 MOV direct, R1 8A MOV direct, R 8B MOV direct, R3 8C MOV direct, R4 8D MOV direct, R5 8E MOV direct, R6 8F MOV direct, R7 A8 MOV R0, direct A9 MOV R1, direct AA MOV R, direct AB MOV R3, direct AC MOV R4, direct AD MOV R5, direct AE MOV R6, direct AF MOV R7, direct MOVE with Accumulator E5 MOV A, direct E6 1 MOV A, @R0 E7 1 MOV A, @R1 E8 1 MOV A, R0 E9 1 MOV A, R1 EA 1 MOV A, R EB 1 MOV A, R3 EC 1 MOV A, R4 ED 1 MOV A, R5 EE 1 MOV A, R6 EF 1 MOV A, R7 F5 MOV direct, A F6 1 MOV @R0, A F7 1 MOV @R1, A F8 1 MOV R0, A F9 1 MOV R1, A FA 1 MOV R, A FB 1 MOV R3, A FC 1 MOV R4, A FD 1 MOV R5, A FE 1 MOV R6, A FF 1 MOV R7, A MOVE with external memory E0 1 MOVX A, @DPTR E 1 MOVX A, @R0 E3 1 MOVX A, @R1 F0 1 MOVX @DPTR, A F 1 MOVX @R0, A F3 1 MOVX @R1, A MOVE with code memory 83 1 MOVC A, @A+PC 93 1 MOVC A, @A+DPTR Bit MOVE 9 MOV bit, C A MOV C, bit Indirect MOVE with R0 and R1 86 MOV direct, @R0 87 MOV direct, @R1 A6 MOV @R0, direct A7 MOV @R1, direct ADD with Accumulator 4 ADD A, #immediate 5 ADD A, direct 6 1 ADD A, @R0 7 1 ADD A, @R1 8 1 ADD A, R0 9 1 ADD A, R1 A 1 ADD A, R B 1 ADD A, R3 C 1 ADD A, R4 D 1 ADD A, R5 E 1 ADD A, R6 F 1 ADD A, R7 ADD with Accumulator & carry flag 34 ADDC A, #immediate 35 ADDC A, direct 36 1 ADDC A, @R0 37 1 ADDC A, @R1 38 1 ADDC A, R0 39 1 ADDC A, R1

3A 1 ADDC A, R 3B 1 ADDC A, R3 3C 1 ADDC A, R4 3D 1 ADDC A, R5 3E 1 ADDC A, R6 3F 1 ADDC A, R7 Subtract with borrow 94 SUBB A, #immediate 95 SUBB A, direct 96 1 SUBB A, @R0 97 1 SUBB A, @R1 98 1 SUBB A, R0 99 1 SUBB A, R1 9A 1 SUBB A, R 9B 1 SUBB A, R3 9C 1 SUBB A, R4 9D 1 SUBB A, R5 9E 1 SUBB A, R6 9F 1 SUBB A, R7 INC and DEC 04 1 INC A 05 INC direct 06 1 INC @R0 07 1 INC @R1 08 1 INC R0 09 1 INC R1 0A 1 INC R 0B 1 INC R3 0C 1 INC R4 0D 1 INC R5 0E 1 INC R6 0F 1 INC R7 A3 1 INC DPTR 14 1 DEC A 15 DEC direct 16 1 DEC @R0 17 1 DEC @R1 18 1 DEC R0 19 1 DEC R1 1A 1 DEC R 1B 1 DEC R3 1C 1 DEC R4 1D 1 DEC R5 1E 1 DEC R6 1F 1 DEC R7 COMPARE with JUMP B4 3 CJNE A, #immediate, offset B5 3 CJNE A, direct, offset B6 3 CJNE @R0, #immediate, offset B7 3 CJNE @R1, #immediate, offset B8 3 CJNE R0, #immediate, offset B9 3 CJNE R1, #immediate, offset BA 3 CJNE R, #immediate, offset BB 3 CJNE R3, #immediate, offset BC 3 CJNE R4, #immediate, offset BD 3 CJNE R5, #immediate, offset BE 3 CJNE R6, #immediate, offset BF 3 CJNE R7, #immediate, offset D8 DJNZ R0, offset D9 DJNZ R1, offset DA DJNZ R, offset DB DJNZ R3, offset DC DJNZ R4, offset DD DJNZ R5, offset DE DJNZ R6, offset DF DJNZ R7, offset D5 3 DJNZ direct, offset JUMP 01 AJMP addr11 1 AJMP addr11 41 AJMP addr11 61 AJMP addr11 81 AJMP addr11 A1 AJMP addr11 C1 AJMP addr11 E1 AJMP addr11 0 3 LJMP addr16 80 SJMP offset JUMP with flag 10 3 JBC bit, offset 0 3 JB bit, offset 30 3 JNB bit, offset 40 JC offset 50 JNC offset 60 JZ offset 70 JNZ offset JUMP indirect 73 1 JMP @A+DPTR CALL subroutine and Return 11 ACALL addr11 31 ACALL addr11 51 ACALL addr11 71 ACALL addr11 91 ACALL addr11 B1 ACALL addr11

D1 ACALLaddr11 F1 ACALL addr11 1 3 LCALL addr16 1 RET 3 1 RETI ROTATE 03 1 RR A 13 1 RRC A 3 1 RL A 33 1 RLC A C4 1 SWAP A LOGICAL 5 ANL direct, A 53 3 ANL direct, #immediate 54 ANL A, #immediate 55 ANL A, direct 56 1 ANL A, @R0 57 1 ANL A, @R1 58 1 ANL A, R0 59 1 ANL A, R1 5A 1 ANL A, R 5B 1 ANL A, R3 5C 1 ANL A, R4 5D 1 ANL A, R5 5E 1 ANL A, R6 5F 1 ANL A, R7 4 ORL direct, A 43 3 ORL direct, #immediate 44 ORL A, #immediate 45 ORL A, direct 46 1 ORL A, @R0 47 1 ORL A, @R1 48 1 ORL A, R0 49 1 ORL A, R1 4A 1 ORL A, R 4B 1 ORL A, R3 4C 1 ORL A, R4 4D 1 ORL A, R5 4E 1 ORL A, R6 4F 1 ORL A, R7 6 XRL direct, A 63 3 XRL direct, #immediate 64 XRL A, #immediate 65 XRL A, direct 66 1 XRL A, @R0 67 1 XRL A, @R1 68 1 XRL A, R0 69 1 XRL A, R1 6A 1 XRL A, R 6B 1 XRL A, R3 6C 1 XRL A, R4 6D 1 XRL A, R5 6E 1 XRL A, R6 6F 1 XRL A, R7 BIT logical 7 ORL C, bit 8 ANL C, bit A0 ORL C, /bit B0 ANL C, /bit B CPL bit B3 1 CPL C C CLR bit C3 1 CLR C D SETB bit D3 1 SETB C Exchange C5 XCH A, direct C6 1 XCH A, @R0 C7 1 XCH A, @R1 C8 1 XCH A, R0 C9 1 XCH A, R1 CA 1 XCH A, R CB 1 XCH A, R3 CC 1 XCH A, R4 CD 1 XCH A, R5 CE 1 XCH A, R6 CF 1 XCH A, R71 D6 1 XCHD A, @R0 D7 1 XCHD A, @R1 PUSH & POP C0 PUSH direct D0 POP direct Accumulator A4 1 MUL AB 84 1 DIV AB D4 1 DA A E4 1 CLR A F4 1 CPL A No operation 00 1 NOP Prepared for 8051 Microcontroller Kit by Wichit Sirichote 015

8051 Instruction hex code Hex Bytes Instruction 00 1 NOP 01 AJMP addr11 0 3 LJMP addr16 03 1 RR A 04 1 INC A 05 INC direct 06 1 INC @R0 07 1 INC @R1 08 1 INC R0 09 1 INC R1 0A 1 INC R 0B 1 INC R3 0C 1 INC R4 0D 1 INC R5 0E 1 INC R6 0F 1 INC R7 10 3 JBC bit, offset 11 ACALL addr11 1 3 LCALL addr16 13 1 RRC A 14 1 DEC A 15 DEC direct 16 1 DEC @R0 17 1 DEC @R1 18 1 DEC R0 19 1 DEC R1 1A 1 DEC R 1B 1 DEC R3 1C 1 DEC R4 1D 1 DEC R5 1E 1 DEC R6 1F 1 DEC R7 0 3 JB bit, offset 1 AJMP addr11 1 RET 3 1 RL A 4 ADD A, #immediate 5 ADD A, direct 6 1 ADD A, @R0 7 1 ADD A, @R1 8 1 ADD A, R0 9 1 ADD A, R1 A 1 ADD A, R B 1 ADD A, R3 C 1 ADD A, R4 D 1 ADD A, R5 E 1 ADD A, R6 F 1 ADD A, R7 30 3 JNB bit, offset 31 ACALL addr11 3 1 RETI 33 1 RLC A 34 ADDC A, #immediate 35 ADDC A, direct 36 1 ADDC A, @R0 37 1 ADDC A, @R1 38 1 ADDC A, R0 39 1 ADDC A, R1 3A 1 ADDC A, R 3B 1 ADDC A, R3 3C 1 ADDC A, R4 3D 1 ADDC A, R5 3E 1 ADDC A, R6 3F 1 ADDC A, R7 40 JC offset 41 AJMP addr11 4 ORL direct, A 43 3 ORL direct, #immediate 44 ORL A, #immediate 45 ORL A, direct 4 6 1 ORL A, @R0 47 1 ORL A, @R1 48 1 ORL A, R0 49 1 ORL A, R1 4A 1 ORL A, R 4B 1 ORL A, R3 4C 1 ORL A, R4 4D 1 ORL A, R5 4E 1 ORL A, R6 4F 1 ORL A, R7 50 JNC offset 51 ACALL addr11 5 ANL direct, A 53 3 ANL direct, #immediate 54 ANL A, #immediate 55 ANL A, direct 56 1 ANL A, @R0 57 1 ANL A, @R1 58 1 ANL A, R0 59 1 ANL A, R1 5A 1 ANL A, R 5B 1 ANL A, R3 5C 1 ANL A, R4 5D 1 ANL A, R5 5E 1 ANL A, R6 5F 1 ANL A, R7 60 JZ offset 61 AJMP addr11 6 XRL direct, A 63 3 XRL direct, #immediate 64 XRL A, #immediate 65 XRL A, direct 66 1 XRL A, @R0 67 1 XRL A, @R1 68 1 XRL A, R0 69 1 XRL A, R1 6A 1 XRL A, R 6B 1 XRL A, R3 6C 1 XRL A, R4 6D 1 XRL A, R5

6E 1 XRL A, R6 6F 1 XRL A, R7 70 JNZ offset 71 ACALL addr11 7 ORL C, bit 73 1 JMP @A+DPTR 74 MOV A, #immediate 75 3 MOV direct, #immediate 76 MOV @R0, #immediate 77 MOV @R1, #immediate 78 MOV R0, #immediate 79 MOV R1, #immediate 7A MOV R, #immediate 7B MOV R3, #immediate 7C MOV R4, #immediate 7D MOV R5, #immediate 7E MOV R6, #immediate 7F MOV R7, #immediate 80 SJMP offset 81 AJMP addr11 8 ANL C, bit 83 1 MOVC A, @A+PC 84 1 DIV AB 85 3 MOV direct, direct 86 MOV direct, @R0 87 MOV direct, @R1 88 MOV direct, R0 89 MOV direct, R1 8A MOV direct, R 8B MOV direct, R3 8C MOV direct, R4 8D MOV direct, R5 8E MOV direct, R6 8F MOV direct, R7 90 3 MOV DPTR, #immediate 91 ACALL addr11 9 MOV bit, C 93 1 MOVC A, @A+DPTR 94 SUBB A, #immediate 95 SUBB A, direct 96 1 SUBB A, @R0 97 1 SUBB A, @R1 98 1 SUBB A, R0 99 1 SUBB A, R1 9A 1 SUBB A, R 9B 1 SUBB A, R3 9C 1 SUBB A, R4 9D 1 SUBB A, R5 9E 1 SUBB A, R6 9F 1 SUBB A, R7 A0 ORL C, /bit A1 AJMP addr11 A MOV C, bit A3 1 INC DPTR A4 1 MUL AB A5 undefined A6 MOV @R0, direct A7 MOV @R1, direct A8 MOV R0, direct A9 MOV R1, direct AA MOV R, direct AB MOV R3, direct AC MOV R4, direct AD MOV R5, direct AE MOV R6, direct AF MOV R7, direct B0 ANL C, /bit B1 ACALL addr11 B CPL bit B3 1 CPL C B4 3 CJNE A, #immediate, offset B5 3 CJNE A, direct, offset B6 3 CJNE @R0, #immediate, offset B7 3 CJNE @R1, #immediate, offset B8 3 CJNE R0, #immediate, offset B9 3 CJNE R1, #immediate, offset BA 3 CJNE R, #immediate, offset BB 3 CJNE R3, #immediate, offset BC 3 CJNE R4, #immediate, offset BD 3 CJNE R5, #immediate, offset BE 3 CJNE R6, #immediate, offset BF 3 CJNE R7, #immediate, offset C0 PUSH direct C1 AJMP addr11 C CLR bit C3 1 CLR C C4 1 SWAP A C5 XCH A, direct C6 1 XCH A, @R0 C7 1 XCH A, @R1 C8 1 XCH A, R0 C9 1 XCH A, R1 CA 1 XCH A, R CB 1 XCH A, R3 CC 1 XCH A, R4 CD 1 XCH A, R5 CE 1 XCH A, R6 CF 1 XCH A, R7 D0 POP direct D1 ACALL addr11 D SETB bit D3 1 SETB C D4 1 DA A D5 3 DJNZ direct, offset D6 1 XCHD A, @R0 D7 1 XCHD A, @R1 D8 DJNZ R0, offset D9 DJNZ R1, offset DA DJNZ R, offset DB DJNZ R3, offset DC DJNZ R4, offset DD DJNZ R5, offset DE DJNZ R6, offset

DF DJNZ R7, offset E0 1 MOVX A, @DPTR E1 AJMP addr11 E 1 MOVX A, @R0 E3 1 MOVX A, @R1 E4 1 CLR A E5 MOV A, direct E6 1 MOV A, @R0 E7 1 MOV A, @R1 E8 1 MOV A, R0 E9 1 MOV A, R1 EA 1 MOV A, R EB 1 MOV A, R3 EC 1 MOV A, R4 ED 1 MOV A, R5 EE 1 MOV A, R6 EF 1 MOV A, R7 F0 1 MOVX @DPTR, A F1 ACALL addr11 F 1 MOVX @R0, A F3 1 MOVX @R1, A F4 1 CPL A F5 MOV direct, A F6 1 MOV @R0, A F7 1 MOV @R1, A F8 1 MOV R0, A F9 1 MOV R1, A FA 1 MOV R, A FB 1 MOV R3, A FC 1 MOV R4, A FD 1 MOV R5, A FE 1 MOV R6, A FF 1 MOV R7, A 90 01 00 MOV DPTR,#0100H 4. Bit is location of bit address. A B MOV C, P3. 5. OFFSET is the byte distant between current Program counter and the destination. Finding the OFFSET byte can be done with ALT, OFFSET press. 6. Addr11 is 11 bits of destination address. Finding the hex code for AJMP or ACALL can be done with ALT, AJMP or ACALL press. 7. Long CALL or Long JMP uses 16-bit address. 0 91 00 LJMP 9100H 1 00 0B LCALL 000B NOTES 1. Direct address is RAM location 00-7F and SFR 80-FF Hex code Instruction 75 30 55 MOV 30H, #55H 75 90 1F MOV 90H,#1FH 90H is PORT1, Special Function Register (SFR).. Indirect address is RAM location 00-FF 78 90 MOV R0,#90H 76 0 MOV @R0,#0H 90H is not PORT1. It is general RAM space in the upper page 80-FF. The upper page must be accessed with indirect addressing 3. Immediate data for DPTR will be 16-bit Prepared for 8051 Microcontroller Kit by Wichit Sirichote 015

Note 40