Understanding Microcontroller Architecture (UMA)

1. Memory Organization

All 8051 devices have separate address spaces for program memory and data memory, as shown in Figure 1.1. and Figure 1.2. The logical separation of program and data memory allows data memory to be accessed with 8-bit addressing, which can be quickly stored and manipulated by an 8-bit CPU. In addition, 16-bit data memory addressing can also be generated through the DPTR register. Program memory (ROM, EPROM and FLASH) can only be read, not written. Program memory can be up to 64K bytes. In the 89S51, 4K bytes of program memory are on the chip. To read external program memory the microcontroller sends the PSEN (program store enable) signal.


Figure 1.1. Block diagram of the 8051 microcontroller

Data memory (RAM) occupies a separate address space from program memory. In the 8051 family, the lowest 128 bytes of data memory are on the chip. External RAM (maximum 64K bytes). In accessing External RAM, the microcontroller sends RD (read) and WR (write) signals.


Figure 1.2. 8051 Microcontroller Memory Architecture

2. Memory Program

Figure 1.2 shows a map of the bottom of program memory. After reset the CPU starts executing from location 0000H. As shown in Figure 1.3, each interrupt is assigned to a specific location in program memory. An interrupt causes the CPU to jump to the location where a specific service is to be performed.

External Interrupt 0, for example, is located at location 0003H. If External Interrupt 0 is to be used, then the service routine must be started at location 0003H. If this interrupt is not used, this service location can be used for various purposes as Program Memory.


Figure 1.3. Interrupt Map of the 8051 microcontroller

2. Memory Data

Figure 1.2 shows the internal and external data memory space of the 8051 family. The CPU generates the RD and WR signals required during external RAM access. The internal data memory is mapped as shown in Figure 1.2. The memory space is divided into three blocks, referred to as the lower 128 bytes, the upper 128 bytes and the SFR space.

Internal data memory addresses are always one byte wide. Direct addressing above 7Fh will access one memory address, and indirect addressing above 7Fh will access a different address. Thus, Figure 1.4 shows that the upper 128 bytes and the SFR space occupy the same address block, 80h to FFh, even though they are physically separate.

The lower 128 bytes of RAM are further grouped into blocks, as shown in Figure 1.5. The lower 32 bytes of RAM are grouped into 4 banks of 8 registers each. The program instructions for calling these registers are named R0 through R7. Two bits in the Program Status Word (PSW) can select which bank of registers to use. The use of registers R0 through R7 will make programming more efficient and shorter, compared to direct addressing.


Figure 1.4. Internal data memory


Figure 1.5. The bottom 128 bytes of internal RAM

All of the lower 128 bytes of RAM can be accessed using either direct or indirect addressing. The upper 128 bytes can only be accessed indirectly, Figure 1.6.


Figure 1.6. The top 128 bytes of internal RAM.

3. Special Function Register

A memory map called the special function register ( SFR ) space is shown in the following figure. Note that not all of these addresses are occupied, and unoccupied addresses are not allowed to be implemented. Read accesses to these addresses will produce random data, and write accesses will produce unclear effects.

Accumulator

ACC is the accumulator register. The mnemonic for this accumulator specific instruction can be simply abbreviated as A.

Register B

Register B is used during multiplication and division operations. In addition to the above purposes, this register can be used as a free register.

Word Status Program

The PSW register consists of status information of the program which is detailed in Table 1.1.

Stack Pointer

The stack pointer register has a data width of 8 bits. This register will be incremented before data is stored during push and call execution. While the stack can be anywhere in RAM. The stack pointer starts at address 07h after reset. This causes the stack to start at location 08h.

Data Pointers

Data Pointer (DPTR) consists of upper byte (DPH) and lower byte (DPL). This function is intended to store 16-bit data. Can be manipulated as a 16-bit register or two stand-alone 8-bit registers.


Figure 1.7. SFR Map

Ports 0, 1, 2 and 3
P0, P1, P2 and P3 are the SFRs occupied by Ports 0, 1, 2 and 3. Writing a logic 1 to a bit of a port SFR (P0, P1, P2 or P3) causes the corresponding port output pin to be in a logic high '1' condition. And vice versa.

Serial Data Buffer 
The serial buffer is actually two separate registers, the transmit buffer and the receive buffer. When data is loaded into the SBUF, it goes to the transmit buffer and is held for transmission. When data is taken from the SBUF, it comes from the receive buffer.

Timer Registers
The register pair (TH0, TL0) and (TH1, TL1) are 16-bit counting registers for Timer/Counter 0 and 1, respectively.

Control 
Registers IP, IE, TMOD, TCON, SCON, and PCON consist of control and status bits.

Program Status Word
PSW or Program Status Word contains status bits related to the condition or state of the microcontroller CPU at that time. PSW is located in the SFR space location (see Figure 1.9, with the address location D0h). In this PSW we can monitor several statuses including: carry bit, auxiliary carry (for BCD operations), two register bank selector bits, overflow flag, a parity bit and two status flags that can be defined by yourself. The carry bit can also be used for arithmetic operations, and can also be used as a universal accumulator for several boolean operations.

Table 1.2.1 Word Status Program


Table 1.2.1 Word Status Program

Bits RS0 and RS1 can be used to select one of four register banks as shown in table 19.2. The parity bit can be used to find out the number of logical '1's in the accumulator: P=1 if the accumulator has an odd number of logical '1's, and P=0 if the accumulator has an even number of logical '1's. The other two bits PSW1 and PSW5 can be used for various purposes.

8051 Microcontroller Architecture

1. Microcontroller

A microcontroller can be viewed as a system containing:

  • processor
  • memory 
  • I/O ports

2. Microcontroller Requirements

  • Monitoring the environment. >> Inputs.
  • Generate response. >> Output.
  • Response can be delayed. >> Timer/Counter.
  • Responses to prioritize. >> Interruptions.
  • Software to control the process. >> Non-volatile memory.
  • Temporary data. >> RAM.

3. Example of the Z80 Microcontroller Family from Zilog

  • 8-bit microprocessor based on the 8080 architecture.
  • Capable of 1 MIP at 4 MHz.
  • Accumulator, 6 8-bit registers, 2 index registers.
  • Uses external RAM for temporary data.
  • Built-in refresh circuitry for the external RAM.
  • Only port-based I/O.
  • Slowly disappearing.

4. MC6811 from Motorola

  • 8-bit stack-based architecture.
  • 2 accumulators and 2 index registers.
  • Built in EEPROM and RAM.
  • Digital I/O.
  • Timer.
  • ADC.
  • RS232 communication.
  • Was the most powerful and flexible controller available at introduction.
  • Around 1970.
  • Still very popular.

5. MCS-51 Family Microcontroller

First introduced by Intel in 1981.

  • Currently, the most widely used microcontroller.
  • 8-bit processor.
  • 2 distinct separately addressable memory areas.
  • Maximum of 64K on-chip ROM. (Usually 0 to 4K.)
  • Maximum of 64K external data memory.
  • Maximum of 64K external code memory.
  • Basic version (8051) contains (4K Bytes of on-chip ROM instruction memory or 128 Bytes of on-chip RAM for temporary data storage and the stack.)
  • 2 timers, one serial port, and four 8-bit parallel I/O ports.
  • Speeds starting from 12 MHz.

6. Features of the 8051 Microcontroller

| Feature           | Quantity  |
|-------------------|-----------|
| ROM               | 4k Bytes  |
| RAM               | 128 Bytes |
| Timer             | 2         |
| I/O Ports         | 4         |
| Serial Port       | 1         |
| Interrupt Soutces | 6         |

The 8051 is a member of the MCS-51 microcontroller family. There are several types that are slightly different from the above features.

7. MCS-51 Type

| Feature           | EPROM |      |      |      |      |      |
|-------------------|-------|------|------|------|------|------|
|                   | 8051  | 8052 | 8751 | 8752 | 8031 | 8032 |
| On-Chip ROM       | 4k    | 8k   | 4k   | 8k   | 0k   | 0k   |
| RAM (Bytes)       | 128   | 256  | 128  | 256  | 128  | 256  |
| Timers            | 2     | 3    | 2    | 3    | 2    | 3    |
| I/O Ports         | 4     | 4    | 4    | 4    | 2    | 2    |
| Serial Port       | 1     | 1    | 1    | 1    | 1    | 1    |
| Interrupt Sources | 6     | 8    | 6    | 8    | 6    | 8    |

8. MCS-51 Maker

There are many companies that produce MCS-51 family microcontrollers, such as:

Atmel Corporation

  • Flash instead of EPROM.
  • Low Voltage.
  • Minimal version with less memory and fewer I/O ports in a smaller package.
  • CMOS implementation.
  • Speeds that range from 12 to 20 MHz.

Dallas Semiconductor

  • Uses NV-RAM. Programmable in-system.
  • As large as 32K of instruction memory.
  • Some versions have an on-chip real-time clock.

Philips Corporation

  • Large selection of 8051 based microcontrollers.
  • Includes features like A/D and D/A on chip.

Xilinx and Altera

  • 8051 FPGA cores.

9. 8051 Microcontroller Architecture


8051 Microcontroller Architecture

10. Software

  • Memory Organization
  • Register Collection
  • Instructions

11. Hardware

  • Pin-out
  • Timing characteristics
  • Current/Voltage requirements

12. Memory Organization

The 8051 has separate addresses for program and data storage.


Microcontroller Memory Organization

13. Program Storage

After reset, the MCS-51 starts quoting instructions from 0000H. These can be taken from either external or internal memory.

  • If EA is low, then the program memory is external.
  • If EA is high, then addresses 0000 to 0FFF are internal ROM.

Data Storage

The 8051 has 256 bytes of internal RAM.

  • The bottom 128 bytes are used for data storage.
  • The upper 128 bytes are used for Special Function Registers (SFR).

The lower 128 bytes are used instead of just regular RAM

  • Saving registers,
  • Stack
  • And other features

  • The bottom 32 bytes form 4 banks of 8 registers per bank.
  • Only one bank can be active
  • The active bank can be selected by setting 2 bits in the PSW. [[The default bank (when turned on) is bank 0 (location 00 -- 07)]].
  • The 8 registers in each bank are called R0 to R7
  • Each of these registers has an address and can be accessed directly using that address, even if the bank in question is not activated.

  • The next 16 bytes -- locations 20H through 2FH -- form a block that can be addressed as either bytes or bits.
  • Bytes have addresses 20H to 2FH.
  • The bits have addresses 00H to 7FH.
  • Certain instructions are used to access these bits.
  • Locations 30H through 7FH are general purpose RAM.

14. RAM --First 128 Bytes


Bit addressable memory location

15. SFR -- Special Function Registers

  • The upper 128 bytes of RAM are used for special function registers. Only about 25 bytes are used. The rest is reserved for the development version of the 8051.
  • These registers correspond to functions that are important in the working of the MCS-51.
  • Some SFRs are both bit-addressable and byte-addressable. The address of bit 0 of a register is the same as the address of the corresponding register.


SFR Location

16. Special Function Registers

  • ACC and B registers -- 8 bits
  • DPTR : data pointer [DPH 😃PL] -- 16 bits (combined)
  • PC : Program Counter -- 16 bit
  • Stack pointer SP -- 8 bit
  • PSW : Program Status Word
  • P0, P1, P2, P3 - Port Latch
  • SBUF - Serial Data Buffer
  • TH0, TL0, TH1, TL1 - Timer Registers
  • Control Registers

17. ACC -- Accumulator

It is commonly used for copying and arithmetic instructions and can be written in several ways:

  • It is stated with ACC (or A).
  • With the address 0E0H.

Besides that, it is also bit addressable where ACC.2 means bit 2 of the ACC register.

18. Register B

  • Generally used as a temporary register, similar to registers R0 -- R7.
  • Used by two opcodes, such as: mul AB, div AB
  • Register B stores the second operand and stores the result such as: the top 8 bits of the multiplication result and the remainder of the division.
  • It can also be accessed via its address 0F0H.
  • It is bit-addressable.

19. Register DPL and DPH

  • 2 8-bit registers that can be combined into a 16-bit DPTR -- Data Pointer.
  • Used by commands that access external memory
  • Also used for storing 16bit values
  • mov DPTR, #data16 ; setup DPTR with 16bit ext address
  • movx A, @DPTR ; copy mem[DPTR] to A
  • Can be accessed as 2 separate 8-bit registers if needed.
  • DPTR is useful for string operations and look up table (LUT) operations.

20. The SP Register

  • SP is the stack pointer.
  • SP points to the last used location of the stack. (Push operation will first increment SP and then copy data and Pop operation will first copy data and then decrement SP).
  • In 8051, the stack grows upwards (from low memory to high memory) and can be in the internal RAM only.
  • On power-up, SP points to 07H. (Register banks 2,3,4 (08H to 1FH) form the default stack area).
  • Stack can be relocated by setting SP to the upper memory area in 30H to 7FH, (mov SP, #32H).

21. Register PSW

Program Status Word: is a "bit addressable" 8-bit register. Stores all flags.


Word Status Program

22. Registers P0, P1, P2, and P3

  • Port Latch.
  • Returns the value outputted on a specified port or the value read from a specified input port.
  • Bit addressable. The first bit address is also the address of the register concerned. Example: P1's address is 90H, so P1.7 or 97H are the same bit.

23. SBUF Register

  • Serial Port Data Buffer.
  • 2 registers with the same location. One to store serial data from input (Buffer Serial Data Receive). Another one to write serial data (Buffer Serial Data Transmit).

24. Timer Registers -- TH0 and TL0

  • High and low bytes of the 16-bit counting register for timer/counter T0.
  • There is a TH1 / TL1 pair for the T1 timer.

25. Control Register

  • IP -- Interrupt Priority.
  • IE -- Interrupt Enable.
  • TMOD -- Timer Mode.
  • TCON -- Timer Control.
  • T2CON -- Timer 2 Control (8052)
  • SCON -- Serial Port Control.
  • PCON -- Power Control (80C51).

26. Overview


8051 Microcontroller Architecture


Memory Management


Memory Addressing


SFR Table

8051 Instruction Set Addressing

Addressing modes, refers to how you address a particular memory location. The addressing modes in the 8051 instruction set are shown as follows:

  • Immediate Addressing MOV A,#20h
  • Direct Addressing MOV A,30h 
  • Indirect Addressing MOV A,@R0 
  • External Direct MOVX A,@DPTR 
  • Code Indirect MOVC A,@A+DPTR

1. Immediate Addressing 

Immediate addressing is called this, because the value to be stored in memory is directly in the code.

org 0h
start:MOV A,#20h; put constant 20 into Acc
      end
Org 0h
Start:MOV 70h,#0h; put constant 0 into RAM 70h
      MOV 71h,#1h;
      MOV 72h,#2h;
      end
;
      Org 0h
Start:MOV DPTR,#1234h;put constant 1234 into DPTR
      end
 Org 0h
Start:MOV PSW,#0; Select register bank 0
      MOV R0,#0; put 0 into register 0
      MOV R1,#1; put 1 into register 1
      MOV R2,#2; put 2 into register 2
      MOV R3,#3; put 3 into register 3
      MOV R4,#4; put 4 into register 4
      MOV R5,#5; put 5 into register 5
      MOV R6,#6; put 6 into register 6
      MOV R7,#7; put 7 into register 7
      end
      ;
org 0h
Start:MOV PSW,#8; Select register bank 1
      MOV R0,#0; put 0 into register 0
      MOV R1,#1; put 1 into register 1
      MOV R2,#2; put 2 into register 2
      MOV R3,#3; put 3 into register 3
      MOV R4,#4; put 4 into register 4
      MOV R5,#5; put 5 into register 5
      MOV R6,#6; put 6 into register 6
      MOV R7,#7; put 7 into register 7
      end

Immediate addressing is very fast addressing because the value to be loaded is within the instruction.

2. Direct Addressing 

It is called direct addressing because the value to be stored in memory is obtained directly from other memory.

org 0h
Start:MOV A,30h;
      end
      Org 0h
Start:Mov 70h,#1;put constant 1 into RAM 70h
      Mov A, 70h;copy RAM 70 content into Acc
      Mov A,#0 ;put constant 0 into Acc
      Mov 90h,A ;copy Acc content into RAM 90h
      end
Inbyte equ 70h
Port1 equ 90h
      Org 0h
Start:Mov Inbyte,#3;put constant 3 into RAM 70h
      Mov A,Inbyte ;copy RAM 70h content into Acc
      Mov A,#0 ;Clear accumulator
      Mov Port1,A ;copy Acc content into RAM 90h
      end
Org 0h
Mov DPTR,#Character
Start:Mov A, #0
      Inc DPTR
      Movc A, @A+DPTR
      Mov R0,A
      Sjmp Start
Character:
      DB 0,1,2,3,4,5,6,7,8,9

3. Indirect Addressing 

Indirect addressing is a very powerful addressing mode, which provides flexibility in terms of data transfer. Indirect addressing is also the only way to access the extra 128 bytes of internal RAM found on the 8052 family.

MOV A,@R0;

This instruction causes the 8051 to analyze the value of register R0. The 8051 will then fetch data from the accumulator with the value derived from the internal RAM address indicated by R0. For example, suppose R0 will be used to mark the RAM address 40h which contains the data 67h. When the above instruction is executed, the 8051 will look at the value of R0, which contains 40h, and send the contents of RAM 40h (in this case having the value 67h) to the accumulator.

MOV R0,#99h;
MOV @R0,#01h;

These instructions are invalid. Since indirect addressing always refers to internal RAM, these two instructions would write the value 01 to internal RAM address 99h on the 8052. On the 8051 these instructions would produce undefined results, since the 8051 only has 128 bytes of internal RAM.

Org 0h
Start:Mov PSW, #0 ; choose register bank 0
      Mov R0, #78h; put constant 78h into R0
      Mov @R0, #1 ; put contanta 1 into 78h
      end
Org 0h
Start:Mov PSW,#0; pilih register bank 1
      Mov R0,90h; copy RAM 90h content into R0
      Mov @R0,#1; put constant 1 into 90h
      End
      ;

Understanding 8051 Microcontroller Interrupts

The 8051 has 5 interrupt sources. Two external interrupts, two timer interrupts and a serial port interrupt.

Although it requires a deeper understanding, knowledge of interrupts is very helpful in overcoming microprocessor/microcontroller programming problems in terms of handling many input/output devices. Knowledge of interrupts is not enough to be discussed only in theory, concrete program examples are needed to understand.

When the RESET pin on the microprocessor/microcontroller IC receives a reset signal (on the MCS51 the signal is a momentary '1' signal, on other processors it is generally a momentary '0' signal), the Program Counter is filled with a value. This value is called the reset vector, which is the initial number of the program memory that contains the program to be executed.

The discussion above illustrates that the reset process is a hardware event (the reset signal is fed to the Reset leg) which is used to regulate the work of the software, namely determining the flow of the processor program (filling the Program Counter with the reset vector). The program that is run by resetting is the main program for the processor.

Hardware events that are used to regulate the operation of software, not only occur in the reset process, but also occur in the interrupt process.

In the interrupt process, the occurrence of something on a particular hardware is recorded in a special flip-flop, the flip-flop is often referred to as a 'flag', the record in the flag is arranged in such a way that it can be an interrupt request signal to the processor. If this interrupt request is served by the processor, the Program Counter will be filled with a value. This value is called an interrupt vector, which is the initial number of the program memory that contains the program used to serve the interrupt request.

A program that is executed by interruption is called an interrupt service routine (ISR). When the processor executes an ISR, the work being done on the main program is temporarily abandoned, after the ISR is completed the processor returns to executing the main program, as illustrated in Figure 1.


Figure 1.8 Processor work diagram serving interrupts

A processor can have several hardware devices that are sources of interrupt request signals, each interrupt source is served with a different ISR, thus the processor has several interrupt vectors to choose which ISR is used to serve interrupt requests from various sources. Sometimes an interrupt vector is used by more than one similar interrupt source, in this case the ISR concerned must determine itself which interrupt source must be served at that time.

If at the same time more than one interrupt request occurs, the processor will serve the interrupt request according to the predetermined priority, after serving the higher priority interrupt request, the processor will serve the next interrupt request, and only then will it return to working on the main program.

While the processor is working on an ISR, another interrupt request may occur, if the interrupt request that came recently has a higher priority, the ISR that is being worked on is left first, the processor serves the higher priority request, after serving the high priority interrupt the processor continues the original ISR, and then returns to working on the main program. This is called a nested interrupt, but not all processors have the ability to serve interrupts in this way.

1. MCS51 interrupt source

As seen in Figure 2, the AT89C51 has 6 interrupt sources, namely External Interrupts originating from the INT0 and INT1 pins, Timer Interrupts originating from Timer 0 and Timer 1, Serial Port Interrupts originating from the receiver and sender sections of the Serial Port.

In addition, the AT89C52 has 2 other interrupt sources, namely the Timer 2 Interrupt which comes from Timer 2 which is not present on the AT89C51.

The IE0 bit (or IE1 bit) in TCON is a flag that indicates an External Interrupt request. There are 2 conditions that can activate this flag, the first is because the voltage level is '0' on the INT0 (or INT1) leg, the second is because the signal transition from '1' to '0' on the INT0 (or INT1) leg. The choice of this signal form is determined via the IT0 bit (or IT1 bit) contained in the TCON register.

1. If the IT0 (or IT1) bit = '0' then the IE0 (or IE1) bit in TCON becomes '1' when the INT0 leg = '0'.
2. If the IT0 (or IT1) bit = '1' then the IE0 (or IE1) bit in TCON becomes '1' when the signal transition from '1' to '0' occurs on the INT0 leg.

Before the processor executes the ISR of the External Interrupt, the IE0 bit (or IE1 bit) is reset to '0', indicating that the External Interrupt request has been served. However, if the External Interrupt request occurs because the voltage level is '0' on the IT0 (or IT1) leg, and the voltage level on that leg is still ='0' then the IE0 bit (or IE1 bit) will immediately become '1' again!

The TF0 bit (or TF1 bit) in TCON is a flag that indicates a Timer Interrupt request. The TF0 bit (or TF1 bit) becomes '1' when an overflow occurs in the Timer 0 (or Timer 1) binary counter.

Before the processor executes the ISR of the Timer Interrupt, the TF0 bit (or TF1 bit) is set to '0', indicating that the Timer Interrupt request has been serviced.

Serial port interrupts occur due to two things, the first occurs after the serial port has finished sending 1 byte of data, this type of interrupt request is marked with the flag TI='1'. The second occurs when the serial port has received 1 byte of data in full, this type of interrupt request is marked with the flag RI='1'.

The above flags are not reset to '0' before the processor executes the ISR of the Serial Port Interrupt, because the flags are still needed by the ISR to determine whether the interrupt source is from TI or RI. In order for the serial port to be used again after sending or receiving data, the flags must be reset to zero through the program.

The interrupt request flags (IE0, TF0, IE1, TF1, RI and TI) can all be set to zero or one by instructions, the effect is exactly the same as if the change was made by hardware. This means that interrupt requests can be made programmatically, for example an external interrupt request IT0 can be made with the SETB IE0 instruction.

2. Enable Interrupts

All interrupt request sources discussed above can each be activated or deactivated individually via the bits in the IE (Interrupt Enable Register).

The EX0 and EX1 bits are used to set external interrupts INT0 and INT1, the ET0 and ET1 bits are used to set timer 0 and timer 1 interrupts, and the ES bit is used to set serial port interrupts, as shown in Figure 2. In addition, there is also an EA bit that can be used to set all interrupt sources at once.

After reset, all bits in the IE register are set to '0', meaning the interrupt system is disabled. To enable one of the interrupt systems, the corresponding interrupt control bit is enabled and also the EA that controls all interrupt sources. For example, the instruction used to enable the external interrupt INT0 is SETB EX0 followed by SETB EA.

| MSB |   |   |    |     |     |     | LSB |
|-----|---|---|----|-----|-----|-----|-----|
| EA  | X | X | ES | ET1 | EX1 | ET0 | EX0 |
| BIT  | SYMBOL | FUNCTION                                                                                                                                                                       |
|------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| IE.7 | EA     | Disables all interrupts. If EA=0, no interrupt will be acknowledged. If EA=1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit. |
| IE.6 | -      | -                                                                                                                                                                              |
| IE.5 | -      | -                                                                                                                                                                              |
| IE.4 | ES     | Enables or disables the Serial Port interrupt. If ES=0, the Serial Port interrupt is disabled.                                                                                 |
| IE.3 | ET1    | Enables or disables the Timer 1 Overflow interrupt. If ET1=0, the Timer 1 interrupt is disabled.                                                                               |
| IE.2 | EX1    | Enables or disables External Interrupt 1. If EX1=0, External interrupt 1 is disabled.                                                                                          |
| IE.1 | ET0    | Enables or disables the Timer 0 Overflow interrupt. If ET0=0, the Timer 0 interrupt is disabled.                                                                               |
| IE.0 | EX0    | Enables or disables External interrupt 0. If EX0=0, External interrupt 0 is disabled.                                                                                          |

3. Interrupt Vector

When the MCS51 responds to an interrupt request, the Program Counter is filled with a value called the interrupt vector, which is the starting number of the program memory that holds the ISR to service the interrupt request. The interrupt vector is used to execute the hardware-enabled LCALL instruction.

The interrupt vector for external interrupt INT0 is $0003, for timer 0 interrupt is $000B, for external interrupt INT1 is $0013, for timer 1 interrupt is $001B and for serial port interrupt is $0023.

The distance between interrupt vectors is 8, or only 8 bytes are available for each ISR. If an ISR is indeed short, no more than 8 bytes, then the ISR can be written directly to the program memory provided for it. ISRs longer than 8 bytes are written elsewhere, but the program memory pointed to by the interrupt vector is filled with a JUMP instruction towards the relevant ISR.

| Source  | Vector Address |
|---------|----------------|
| IE0     | 0003H          |
| TF0     | 000BH          |
| IE1     | 0013H          |
| TF1     | 001BH          |
| RI + TI | 0023H          |

4. Priority Levels

Each interrupt source can be placed at two different priority levels. The priority level setting is done with the bits in the IP (Interrupt Priority) register.

The PX0 and PX1 bits are for setting the priority level of external interrupts INT0 and INT1, the PT0 and PT1 bits are for setting the timer 0 and timer 1 interrupts, and the PS bit is for setting the serial port interrupts, as shown in Figure 2.

After reset, all bits in the IP register are set to '0', meaning all interrupt sources are placed at the zero priority level. Each interrupt source can be placed at the high priority level by setting its control bit to 'one'. For example, the timer 0 interrupt can be placed at the high priority level with the SETB PT1 instruction.

An ISR for a non-priority interrupt can be interrupted by an interrupt source that is in the primary priority level. But interrupts that are in the same priority level cannot interrupt each other.

If 2 interrupt requests occur at the same time, while both interrupts are at different priority levels, then the interrupt at the highest priority level will be served first, after which the interrupt at the non-priority level will be served.

If both requests are at the same priority level, the priority will be determined in the following order: external interrupt INT0, timer 0 interrupt, external interrupt INT1, timer 1 interrupt and finally the serial port interrupt.

MCS51 Interrupt System Complete Chart

Although the MCS51 interrupt system is relatively simple compared to the Motorola MC68HC11 interrupt system, because it involves 5 interrupt sources, each of which must be set separately, it is not easy to remember all of these problems, especially when creating a program, it is often felt to be very troublesome to flip through books to set each of these interrupt sources.

Figure 2 illustrates the MCS51 interrupt system in full, along with each bit in the SFR (Special Function Register) registers used to control each interrupt source.

The switches depicted in Figure 2 represent the bits in the register that must be set to control the interrupt source, the small flag boxes are flags in the register that record the interrupt request from each interrupt source. The position of the switches in the figure represents the initial position after the MCS51 is reset.

This image is very helpful when writing programs involving MCS51 interrupts.

Interrupt Priority Register (IP)

| MSB |   |   |    |     |     |     | LSB |
|-----|---|---|----|-----|-----|-----|-----|
| X   | X | X | PS | PT1 | PX1 | PT0 | PX0 |

Note:

| BIT  | SYMBOL | FUNCTION                                                                                                  |
|------|--------|-----------------------------------------------------------------------------------------------------------|
| IP.7 | -      | -                                                                                                         |
| IP.6 | -      | -                                                                                                         |
| IP.5 | -      | -                                                                                                         |
| IP.4 | PS     | Defines the Serial Port interrupt priority level. PS=1 programs it to the higher priority level.          |
| IP.3 | PT1    | Defines the Timer 1 interrupt priority level. PT1=1 programs it to the higher priority level.             |
| IP.2 | PX1    | Defines the External Interrupt 1 priority level. PX1=1 programs it to the higher priority level.          |
| IP.1 | PT0    | Enables or disables the Timer 0 interrupt priority level. PT0=1 programs it to the higher priority level. |
| IP.0 | PX0    | Defines the External Interrupt 0 priority level. PX0=1 programs it to the higher priority level.          |

MCS-51 Microcontroller Architecture

A microcontroller is a form of application of a microprocessor that can be considered as a computer in a single chip packaged in an Integrated Circuit (IC).


MCS-51 Microcontroller Architecture

MC is unique, including;

  • CPU Central Processing Unit (CPU),
  • Read Only Memory (ROM),
  • Random Access Memory (RAM) and 
  • multiple programmable I/O channels, timers and counters, and serial communications.

MCS-51 family microcontroller

8051, 8031, 8751H, 80C51, 80C31, 8052, and 8032.

MCS-51 has general characteristics:

  • CPU with 8 bits (data path)
  • On-Chip oscillator and clock circuit
  • 32 I/O lines
  • 64 K addresses for external data memory.
  • 64 K addresses for external program memory
  • Two 16 bit timers/counters (three on 8032/8052)
  • Five types of interrupt structures (six on the 8032/8052)
  • Full duplex serial port
  • Boolean processor
  • Control registers: TCON, MOD, SCON, PCON, IP and IE

The 8051 has 40 pins whose names can be seen in Figure 1.2 and the port names in brackets are alternative functions.

8051 Pin Configuration

8051 Programming Model

Memory Organization

Has internal RAM and ROM. 

  • ROM >> memory for program byte code
  • RAM >> for data variables that can be changed when the program is running.

The 128 bytes of internal RAM are arranged into three distinct areas:

  • Thirty-two addresses from address 00h to 1Fh consisting of 32 registers and divided into 4 groups consisting of 8 registers (See Figure 1.3). Each register can be called by using its name or its RAM address. The RS0 and RS1 bits in the PSW indicate the registers from the group that are being used when the program is running, while the unused register groups can be used as general-purpose RAM.
  • The bit-addressable area occupies 16 bytes of RAM with address bytes 20h through 2Fh, providing a total of 128 bit addresses.
  • The general-purpose RAM area is located above the bit area from 30h to 7Fh which is addressed by bytes.

Understanding the MCS51 Microcontroller Serial Port

Generally, people always assume that the serial port on the MCS51 is a UART that works asynchronously, but few realize that the serial port can also work synchronously, even though a serial port that works synchronously is an excellent means of adding input/output for a microcontroller.


Figure 1.17. Serial communication with a computer

There are 2 known ways of serial data transmission. The two methods are distinguished by the pulse signal (clock) used to 'push' the serial data, if the clock is sent together with the serial data, the method is called synchronous serial data transmission. While in asynchronous serial data transmission, the clock is not sent together with the serial data, the data receiver circuit must generate its own clock to drive the serial data.

The MCS51 serial port can be used in 4 different working modes. Of the 4 modes, 1 mode works synchronously and the other 3 work asynchronously. In summary, the four working modes can be distinguished as follows:

Mode 0

This mode works synchronously, serial data is sent and received via pin P3.0 (RxD), and pin P3.1 (TxD) is used to channel the serial data drive clock generated by the MCS51.

Data is sent/received 8 bits at a time, starting from the bit with the smallest weight (bit 0) and ending with the bit with the largest weight (bit 7). The data transmission speed (baud rate) is 1/12 of the crystal oscillator frequency.

Mode 1

This mode and the following modes work asynchronously, data is sent via pin P3.1 (TxD) and received via pin P3.0 (RxD).

In Mode 1, data is sent/received 10 bits at a time, starting with 1 start bit, followed by 8 data bits starting from the bit with the smallest weight (bit 0), ending with 1 stop bit. In MCS51, which functions as a receiver, the stop bit is stored in RB8 in the SCON register. The data transmission speed (baud rate) can be adjusted according to needs.

This mode is commonly known as UART (Universal Asynchronous Receiver/Transmitter).

Mode 2

Data is sent/received 11 bits at a time, starting with 1 start bit, followed by 8 data bits starting from the bit with the smallest weight (bit 0), then the 9th bit which can be further adjusted, ending with 1 stop bit.

On the MCS51 which functions as a sender, bit 9 comes from the TB8 bit in the SCON register. On the MCS52 which functions as a receiver, bit 9 is stored in the RB8 bit in the SCON register, while the stop bit is ignored and not stored. The data transmission speed (baud rate) can be selected between 1/32 or 1/64 of the crystal oscillator frequency.

Mode 3 This mode is the same as Mode 2, except that the data transmission speed (baud rate) can be adjusted according to requirements, as with Mode 1.

In asynchronous mode (Mode 1, Mode 2 and Mode 3), the MCS51 serial port works in full duplex, meaning that at the same time this serial port can send data and receive data.

The SBUF register is a serial port connecting register. In the four modes above, all instructions that cause changes to the contents of the SBUF will cause the serial port to send data out of the MCS51. In order for the serial port to receive data, the REN bit in the SCON register must be '1'. In mode 0, the data reception process begins with the CLR RI instruction, while in other modes the data reception process begins with the start bit which is '0'. Data received by the serial port from outside the MCS51 is taken with the MOV A,SBUF instruction.

Fetching data from SBUF and storing data into SBUF actually works on two different registers, even though the register name is the same as SBUF.

1. MCS51 Serial Port Registers

MCS51 is equipped with 2 registers and several additional bits for serial port users.


Serial Data Buffer

SBUF is an SFR (Special Function Register) located in the internal data memory with the number $99. SBUF has a dual function, data stored in SBUF will be sent out of MCS51 via the serial port, while data from outside MCS51 received by the serial port is also taken from SBUF. So even though it only occupies one internal data memory number (number $99), SBUF actually consists of 2 different registers.


Serial Port Control Register

SCON is an SFR (Special Function Register) located in the internal data memory with the number $98, which is the main register for regulating the work of the MCS51 serial port. After resetting all bits in SCON are '0'.

  1. The SM0 bit and SM1 bit (bit 7 and bit 6 in the SMOD register) are used to determine the working mode of the serial port. After reset these two bits are '0'
  2. The REN bit (bit 4) is used to activate the serial port's ability to receive data. In mode 0, the RxD pin (pin P3.0) is used to send serial data (REN='0') and also to receive serial data (REN='1'). This property is also carried over when the serial port works in modes 1, 2 and 3, although in these modes the RxD pin is only used to send data, so that the RxD pin can be used to receive data, REN='1' must first be made. After resetting the REN bit is '0'.
  3. In working mode 2 and working mode 3, the serial port works with 9 bits of data, the SBUF with a capacity of 8 bits is not enough for this purpose. The ninth bit to be sent first is placed in TB8 (bit 3), while the RB8 bit (bit 2) is the bit used to accommodate the ninth bit received by the serial port.
  4. In working mode 1, RB8 is used to accommodate the received stop bit, so if RB8 is '1' then the data is received correctly, otherwise if RB8 = '0' it means a framing error has occurred. If the SM2 bit (bit 5) is '1', if a framing error occurs, RI will not be '1' even though the SBUF already contains data from the serial port. This 9th bit can be used as a parity bit, only the parity bit sent must be determined by the program itself and placed on TB8, and the parity bit received on RB8 is used to determine data integrity by program as well. Unlike in standard UART, all of that is done by hardware in the UART IC.
  5. The TI bit (bit 1) is a marker equivalent to the TDRE (Transmitter Data Register Empty) marker commonly found on standard UARTs. After the serial port has finished sending data stored in the SBUF, the TI bit will be '1' by itself, this bit must be zeroed by the program so that it can be used to monitor the state of the SBUF in the next data transmission. 
  6. The following SerialOut subroutine is used to send serial data, can be used for all serial port modes. Line 02 waits for TI to become '1', intended to ensure that the previous data transmission has been completed. The data to be sent has previously been stored in A, in line 03 the data is sent via the serial port by placing it in the SBUF. So that TI can be used to monitor the state of the SBUF on the next data transmission, in line 04 TI is set to zero.
01: SerialOut:
02: JNB TI,$ ; tunggu data sebelumnya selesai dikirim
03: MOV SBUF,A ; kirim data baru
04: CLR TI ; petanda ada pengiriman baru
05: RET

The RI bit (bit 0) is a marker that is equivalent to the RDRF (Receiver Data Register Full) marker commonly found on standard UARTs. After the SBUF receives data from the serial port, the RI bit will be '1' by itself, this bit must be zeroed by the program so that it can be used to monitor the state of the SBUF in receiving the next data.

The following SerialIn subroutine is used to receive serial data, applicable to all serial port modes. Line 02 waits for RI to become '1', intended to ensure that there is new data received on the SBUF. In line 03 the data on the SBUF is fetched to A. So that RI can be used to monitor the state of the SBUF on the next data transmission, in line 04 RI is set to zero.

01: SerialIn:
02: JNB RI,$ ; tunggu SBUF berisi data baru
03: MOV A,SBUF ; ambil data
04: CLR RI ; pentanda data sudah diambil
05: RET


Power Control Register

Serial port mode 0

UART is a standard used for serial data communication with computers, serial data communication with modems and so on.

Synchronous serial data communication, such as mode 0, is a serial data communication that is widely used to connect digital ICs in a system, for example in Serial EEPROM ICs. This method has recently become increasingly popular because the circuit is simple and does not take up space.

In the digital world, there are 3 types of synchronous serial data transmission techniques for the above purposes, the most famous of which is the technique created by Philips called I2C (Inter IC Communication), Motorola introduced a technique called SPI (Serial Peripheral Interface) and National Semiconductor created MicroWire.

Serial data transmission used in mode 0 is not equivalent to the 3 techniques mentioned above, but with careful design, mode 0 can be connected to SPI, so it can be used to connect the MCS51 with the Motorola MC68HC11 microcontroller.

The synchronous serial data signals on pins P3.0 and P3.1 are actually purely signals that are commonly used to control shift registers, so by connecting a shift register to the serial port, you can easily add input ports and output ports.

Baud Rate

Baud rate in mode 0 is certain: in mode 0, Baud Rate = 1/12 x Oscillator Frequency. Baud rate in mode 2 depends on the SMOD bit value in SFR PCON. If SMOD = 0, baud rate is 1/64 oscillator frequency. If SMOD=1, baud rate is 1/32 oscillator frequency. Determination of baud rate in mode 2 is as follows:

While the baud rate in modes 1 and 3 is determined by the overflow rate value of Timer 1.

Using Timer 1 to generate Baud Rate

When timer 1 is used to generate the baud rate clock, the baud rate in modes 1 and 3 is determined by the timer 1 overflow rate and the value of SMOD. The baud rate determination for modes 1 and 3 is as follows:

Timer 1 interrupt must be disabled in this application. In most applications, this timer is operated as a timer, with auto reload mode 2. In this case the baud rate is given by the following formula:

MICROPROCESSOR Pin / Collector / Leg Configuration

| SMKN 2 YOGYAKARTA                 | Kompetensi                 | Kode            : 01/PDTM/KL-XII/1 |
|-----------------------------------|----------------------------|------------------------------------|
| Prog. Keahlian : Tek. Audio Video | KONFIGURASI MIKROPROSESSOR | Waktu          :      menit        |
| Prog. Diklat     : PDTM           |                            | Nama Siswa :                       |
| Kelas                : XII AV     |                            | Tanggal        :                   |

Z-80 Microprocessor Configuration

| SIMBOL     | KAKI NOMOR                  | SINYAL Masuk / Keluar | FUNGSI                                                                                                                                                                                                            |
|------------|-----------------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| A0 ... A15 | 1 ... 5 30 ... 40           | Keluar                | Saluran alamat A0 sampai A15 membentuk 16 bit bus alamat , melaluinya CPU dapat menunjuk memori data sampai 64 k Byte. Untuk menunjuk alamat I/O, CPU hanya menggunakan 2 bit A0 dan A1.                          |
| D0 ... D7  | 7, 8, 9, 10, 12, 13, 14, 15 | Masuk / Keluar        | Tiga keadaan ( 3 state ) D0 sampai D7 membentuk 8 bit  saluran  (bus) data. Melalui saluran data ini pemindahan data dari dan ke memori, I/O ke memori, memori ke accumulator.                                    |
| M1         | 27                          | Keluar                | Mechin cycle one keluaran rendah pada saluran ini menandakan siklus op-code pada pelaksanaan perintah. Pada satu perintah dengan dua op-code, M1 pada setiap op-code memberikan sinyol rendah (logic 0).          |
| MREQ       | 19                          | Keluar                | Memory request Tiga keadaan (3 state)  sinyal rendah pada saluran ini menunjukkan bahwa pembacaan data dari memori atau penulisan data seharusnya terjadi.                                                        |
| IORQ       | 20                          | Output                | Input-output request Sinyal 0 pada saluran ini menunjukkan bahwa saluran keluaran 8 bit pada I/O telah siap.                                                                                                      |
| RD         | 21                          | Keluar                | Read Sinyal 0 pada saluran ini memberitahukan bahwa proses pembacaan data dari memori terjadi.                                                                                                                    |
| WR         | 22                          | Keluar                | Write Sinyal 0 pada saluran ini memberitahukan bahwa proses penulisan data pada memori terjadi.                                                                                                                   |
| RFSH       | 28                          | Keluar                | Refresh Sinyal 0 pada keluaran ini, CPU memberitahukan bahwa pada 7 bit terendah dari saluran alamat ada suatu   refresh alamat untuk memori dinamis dan sinyal MREQ digunakan untuk operasi pembacaan.           |
| HALT       | 18                          | Keluar                | Sinyal 0 pada HALT memberi tahukan bahwa CPU telah melaksanakan perintah dan sekarang menunggu interupt. Selama   HALT, CPU menyelesaikan perintah NOP untuk mempertahankan refresh.                              |
| WAIT       | 24                          | Keluar                | Sinyal 0 pada saluran WAIT, menyebabkan CPU periperal hard ware dalam pelaksanaan siklus tunggu, dimana CPU belum siap untuk mengirimkan atau menerima data.                                                      |
| INT        | 16                          | Masuk                 | Interupt Komponen periperal menyampaikan tuntutan pemu-tusan. Masukan diterima setelah akhir dari pelaksa-naan program                                                                                            |
| NMI        | 17                          | Masuk                 | Non Maskable Interupt Bila ada permintaan NMI, kaki NMI berada pada logik 0. Sinyal ini mengakibatkan suatu lompatan ke 0066 Hex. Alamat ini secara otomatis disimpanb pada state.                                |
| RESET      | 26                          | Masuk                 | Sinyal 0 pada RESET, alamat pada program counter   kembali ke 0000 Hex dan CPU inisialisir yang berarti isi register R juga pada 0000 Hex.                                                                        |
| BUSRQ      | 25                          | Masuk                 | Bus request Logic 0 pada masukan BUSRQ menjadikan alamat dan saluran data (bus data) dalam keadaan bertahan tunggu, sehingga pengontrolan sistem komponen yang lain dapat dilakukan melalui kedua penghantar tsb. |
| BUSACK     | 23                          | Keluar                | Bus Acknowledge Sinyal 0 pada saluran BUSACK memberitahukan bahwa CPU dalam keadaan bertahan tinggi dan pengambil alihan saluran sistem dapat dilaksanakan.                                                       |


Z-80 Microprocessor Configuration

Microprocessor Physical Configuration

| SMKN 2 YOGYAKARTA                 | Kompetensi                       | Kode            : 01/PDTM/KL-XII/1 |
|-----------------------------------|----------------------------------|------------------------------------|
| Prog. Keahlian : Tek. Audio Video | KONFIGURASI FISIK MIKROPROSESSOR | Waktu          :      menit        |
| Prog. Diklat     : PDTM           |                                  | Nama Siswa :                       |
| Kelas                : XII AV     |                                  | Tanggal        :                   |

Performance Criteria:

  • Knowing the main parts/components of a microprocessor.
  • Mention the uses of the keyboard buttons on the microprocessor.

1. Basic Understanding

The microprocessor is physically a microelectronic integrated circuit (IC) chip in a very large scale guide. Functionally, the microprocessor is designed to work as an instruction or program executor, system controller, as a digital data processing center better known as the Central Processing Unit (CPU).

2. Physical Configuration

Hardware Specifications

Z80 CPU (Central Processing Unit)

Operations that can be performed are:

  • Arithmetic operations consist of addition and subtraction operations.
  • Logical operations consist of AND, OR and XOR operations.
  • The Z-80 CPU from Zilog has 158 instructions and a maximum clock of 2.5 MHz. For the u-Pro-1 the clock used is 1.79 MHz.

ROM (Read Only Memory)

  • Mema\ori whose data can only be read. The stored data is permanent (even if the power source is turned off, the data stored in it is not lost).
  • The EPROM used is type 27256 which has a memory of 32 K Bytes. Address: 0000 -- 17FF Hex.

RAM (Random Access Memory)

  • Memory that can be read or written to. The stored data is non-permanent (if the power source is turned off, the stored data will be lost).
  • The RAM used is type 6116 RAM which has 2 K Bytes of memory. Address : 1800 -- 1FFF Hex.

PORT I/O (Input-Output)

The interface component is a device used to connect the world outside the processor with the processor.

PPI 2855 with a total of 24 parallel I/O lines. Consisting of Port A, Port B, and Port C. Each port has 8 bites of parallel lines.

  • I/O Address ; Port A = 00 Hex.
  • Port B = 01 Hex.
  • Port C = 02 Hex.
  • Control word = 03 Hex.

PIO Z-80 with a total of 16 bits of parallel I/O lines.

  • I/O Address : Port A = 80 hex.
  • Port B = 81 Hex.
  • Control port A = 82 Hex.
  • Control port B = 83 Hex.

CTC with 4 stand alone counter timers.

  • I/O Address : CTC 0 = 40 Hex.
  • CTC 1 = 41 Hex.
  • CTC 2 = 42 Hex.
  • CTC 3 = 43 Hex.

DISPLAY

The display uses 6 red 7-segment displays.

SPEAKERS

Speaker with a diameter of 1.6 inches, maximum power of 0.3 watts and an internal impedance of 4 Ohms

POWER

The power supply used is 5 Volt DC and a current of 500 mA.

AUDIO TAPE INTERFACE (MIC and EAR)

Used to connect the uPro-1 to an audio tape recorder.

KEYBOARD

Consisting of 36 buttons, namely 19 function buttons, 16 hexadecimal buttons and 1 button whose function can be determined by the user.

Software Specifications

The keys on the keyboard and their functions:

Hexadecimal Button

Hexadecimal and Register Name button groups.

| No. | Nama Tombol | Fungsi Layanan                                                      |
|-----|-------------|---------------------------------------------------------------------|
| 1.  | 0 / AF      | Tombol angka 0 atau register A (Accu) dan register F (Flag)         |
| 2.  | 1 / BC      | Tombol angka 1 atau register B dan register C                       |
| 3.  | 2 / DE      | Tombol angka 2 atau register D dan register E                       |
| 4.  | 3 / HL      | Tombol angka 3 atau register H dan register L                       |
| 5.  | 4 / AF’     | Tombol angka 4 atau register Adan register F’                     |
| 6.  | 5 / BC’     | Tombol angka 5 atau register Bdan register C’                     |
| 7.  | 6 / DE’     | Tombol angka 6 atau register Ddan register E’                     |
| 8.  | 7 / HL’     | Tombol angka 7 atau register Hdan register L’                     |
| 9.  | 8 / IX      | Tombol angka 8 atau register I dan register X                       |
| 10. | 9 / IY      | Tombol angka 9 atau register I dan register Y                       |
| 11. | A / SP      | Tombol angka A atau register SP                                     |
| 12. | B / I-IF    | Tombol angka B atau Interupt register Flag                          |
| 13. | C / SZ-H    | Tombol angka C atau untuk menampilkan bit 4, 5, 6, 7, register F    |
| 14. | D / PNC     | Tombol angka D atau untuk menampilkan bit 0, 1, 2, 3, register   F  |
| 15. | E / SZ-H’   | Tombol angka E atau untuk menampilkan bit 4, 5, 6, 7, register F’   |
| 16. | F / PNC’    | Tombol angka F atau untuk menampilkan bit 0, 1, 2, 3, register   F’ |

Task

  1. Explain what is meant by CPU (Central Processing Unit)!
  2. Name the operations that can be run on the CPU?
  3. Explain what is meant by RAM and mention the address bytes that can be used for writing programs?
  4. Explain what is meant by ROM and mention the address bytes that have been used for writing programs in ?
  5. Name the type of Input-Output IC used in the uPRO-1 system and how many channels are available?

Basic Operations of Microprocessors

| SMKN 2 YOGYAKARTA                 | Kompetensi    | Kode            : 02/PDTM/KL-XII/1 |
|-----------------------------------|---------------|------------------------------------|
| Prog. Keahlian : Tek. Audio Video | OPERASI DASAR | Waktu          :      menit        |
| Prog. Diklat     : PDTM           |               | Nama Siswa :                       |
| Kelas                : XII AV     |               | Tanggal        :                   |


Basic Operations of Microprocessor

Performance Criteria:

  1. Performs memory address set.
  2. Filling a memory address with data.
  3. Checking and Changing Register Contents.
  4. Running a simple program.

If the RS button is pressed then the system will be reset. If the system is reset then:

  • Disable interrupt (IFF set to 0).
  • The I-IF register is filled with 0000.
  • The user's PC is set at 1800 H.
  • The user SP is set to 1F9F H.
  • Break point becomes disabled.
  • The uPro-1 logo is displayed simultaneously.

ADDR means address. After this button is pressed, the display will be in the standard format, namely 4 digits on the left for the address, while 2 digits on the right for data. The address area is marked with 4 dots located on each digit. If we enter more than 4 digits, then only the last 4 digits will be accepted. If less than 4 digits, then the first digits are accepted.

If the DATA button is pressed, the index points will move to the 2 digits on the right. The user may enter data. The contents of the RAM will be replaced by the data entered. The plus (+) and minus (-) buttons are useful for increasing and decreasing the 'Program Counter' (address counter) numbers. If the index point is already in the data area, we do not need to press the DATA button anymore. We can directly enter the data. After that, press the plus (+) button to enter data at the next address or press the minus (-) button for data at the previous address.

If you intend to change the contents of the ROM (address 0000 -17FF Hex.) the display will turn off. After the button is released, the display will return to its previous state.

Example 1: View the contents of the address 0000-0003 Hex

Example 2: Filling address 1800 with AB data and address 1801 with DC data.

Example 3: Changing the contents of the 1900 address

Checking and Changing Register Contents -- REG and DATA buttons

When the REG button is pressed, the display will show rEG- you are ready to enter the name of the intended register. Selecting the register name is simply a matter of pressing one button, for example the AF button for Accumulator and Flag, the HL button for register H and register L and so on.

The register name is in the 2 digits on the right, while the register contents are in the four (4) digits on the left, which are divided into two parts. For more details, see the image below (we take the AF register as an example).

Example 1: Viewing the contents of the DE and HL registers

Example 2: Changing the contents of the Accumulator (Register A) with data 02, register F with data 63

Resets the user counter program. The uPro-1 RAM is 2K bytes, but can be expanded to 4K bytes. If the monitor is reset, the monitor will display the uPro-1 logo. If the PC button is pressed after the RS button, the program counter will search for the lowest RAM address, which is address 1800 H and set the user counter program at this address. That is, the left 4 digits of the display (address area) will show address 1800 H.

This button is used to run a program written in RAM memory, namely running the program from the lowest address (address 1800 H). This button only applies when the display is in standard Address-Data format.

Example program fills register A with data 25 H and register C with data 0A H

Program writing:

View the contents of register A and the contents of register C

Task

  1. Explain how to set the address 1A00!
  2. Explain how to fill in EE hex data at address 1C00!
  3. Explain how to view data in register A (Accumulator)!
  4. Explain how to replace the contents of register B with data AA hex. register C with data 00 hex.!
  5. Explain the purpose of pressing the RS - PC - GO buttons to run / execute a program!

Microprocessor Support Functions / Methods

| SMKN 2 YOGYAKARTA                 | Kompetensi              | Kode            : 03/PDTM/KL-XII/1 |
|-----------------------------------|-------------------------|------------------------------------|
| Prog. Keahlian : Tek. Audio Video | FUNGSI-FUNGSI PENUNJANG | Waktu          :      menit        |
| Prog. Diklat     : PDTM           |                         | Nama Siswa :                       |
| Kelas                : XII AV     |                         | Tanggal        :                   |


Microprocessor Support Functions

Performance Criteria:

  1. Move some lines of the program.
  2. Deleting some lines of the program.
  3. Inserting a few lines of program
  4. Save program data to an audio tape recorder.
  5. Reading program data from an audio tape recorder.

If the MOVE button is pressed, the display will show:

S --XXXX, S means the starting address of the data to be moved. You can enter the intended address. After that, press the plus (+) button, the display will show XXXX -A, A means the end of the data address to be moved. Enter the address you mean and then press the plus (+) button again, the display will show; XXXX -- t, t means the destination address of the data to be moved. Enter the destination address, then press the -- GO button. If the transfer process is complete, the display is in the form of ADDR -- DATA. The address area is the last byte to be moved.

Example: Moving data at address 1800-18FF to 1810-190F

Notes:

  1. The transfer can occur upward or downward. If moving downward, the last address is at the bottom of the destination area. If moving upward, the last address is at the top of the destination area. Because microcomputers work so fast, transfers can be done in an instant. After pressing the GO button, the results will be displayed immediately.
  2. If the destination area overlaps with the system stack, the system stack data will be destroyed. The user must press the RS button to reset the system.

This button is only valid if the display is in ADDR-DATA format. Pressing this button will cause the data from the displayed address to be erased. All data below that address will move up one level.

Example: Suppose the current RAM contents are as below, and we want to delete data at address 1802.

Note: The applicable area for the DEL key is address 1800 -- 1DFF. If the deleted data is in this area, all data below it will go up one level, the last data at address 1DFF is filled with 0.

If the display is in the address-data position, the desired data will be inserted after the desired address is on the display. Pressing the INS key will cause all data below the displayed address to be moved down one level, so that the user can insert the desired data.

Example: For example, the current RAM contents are as follows, if you want to insert data 33 at address 1803.

Note: The applicable area for the INS key is address 1800 -- 1DFF. After the data insertion, the last byte of the inserted block is lost.

Cassette is a data storage media with large capacity. In saving files to cassette, it is better to use an audio tape recorder that has a microphone line input.

By pressing the TAPE WR button the display becomes XXXX -F, F means file name. Used to distinguish various groups of data stored on the tape. Also used to read/retrieve data that has been stored.

After that, press the plus/(+) button, the display will be XXXX -S, S means the starting address of the data to be saved, enter the address, then press the plus/(+) button, the display will be XXXX -A, A means the ending address of the data to be saved, enter the data.

Before pressing the GO button, you must first connect the microphone line of the tape to the MIC hole on the uPro-1, after the PLAY and REC buttons on the tape are pressed you can press the GO button to start saving. It is better not to connect the MIC hole and uPro-1, by inserting the CD line on the audio tape recorder because the gain of the CD line input is not large enough, so there will be an error in reading the TAPE READ operation time. If the tape is not ready, but you have pressed the GO button, the data will still be output, but not saved on the tape.

During data transfer, the display will go blank. The TONE-OUT LED lights up and a tone sounds.

Example: storing data at address 1800-18FF Hex. To tape, with which file 1234.

Note: Data that has been stored on the tape will make a rustling sound. If you want to save data, you must be careful, check first whether the place is empty or not, so that you do not damage the data that is already on the tape.

When you press the TAPE RD button, the display will show XXXX -F. Enter the desired file name and read it. Then connect the output to the speaker (using the ear phone jack) with the ear hole on the uPro-1. Place the tape volume at maximum position. Press the GO button then press PLAY on the tape recorder. At first the display will show [. . . . . .], If the searched file has been found, the display will become [. . . . . .].

Example: Reading from a tape recorder, file name 1234.

Notes:

  • The start and last addresses are already stored on tape, so there is no need to enter them again. Only the file name needs to be entered.
  • A check code will also be stored on the tape. The uPro-1 will check when reading data. If it does not match, the display will show -SLH. If it does match, the last address read will be displayed.
  • If data read from tape is stored on the stack system, an error will occur.
  • Connect the speaker output on the audio tape recorder to the EAR input on the uPro-1. It is better not to connect the phone output of the audio tape recorder to the EAR on the uPro-1 because the gain on the phone is not large enough, resulting in errors in reading.
  • When displaying [. . . . . .], the uPro-1 speaker should emit a beep..beep sound. If the sound is not heard, the data will not be read or a reading error will occur.

Task:

From the program above:

  1. Explain how to insert data 06 into address 1802!
  2. Explain how to delete data 00 on addresses 1803 and 1805!
  3. Explain how to move data from address 1803 -- 1805 to address 1808 -- 180A!

How to Load Microprocessor Data

|                                   |                           |                                   |
|-----------------------------------|---------------------------|-----------------------------------|
| SMKN 2 YOGYAKARTA                 | Kompetensi                | Kode            : 05/PDTM/KL10/SR |
| Prog. Keahlian : Tek. Audio Video | LOAD DATA (LD) (BAGIAN 1) | Waktu          :      menit       |
| Prog. Diklat     : PDTM           |                           | Nama Siswa :                      |
| Kelas                : 10 AV      |                           | Tanggal        :                  |


Microprocessor Data Load

Performance Criteria:

  1. Mention the uses of the Load Data (LD) command
  2. Save data in register
  3. Move / copy data

Supporting Theory

The Load Data (LD) command is a microprocessor command used to:

  1. Save data in register
  2. Storing data in register pairs
  3. Move / copy data from one register to another register.
  4. Move / copy data from register to memory.
  5. Move / copy data from memory to register.

1. Save Data in the Register

Format :           LD  r,n


dimana   LD    :           perintah Load Data
         r     :           nama register
         n     :           data tersimpan

Catatan:
Nama-nama register
a)      register A (Accumulator)
b)      register B
c)      register C
d)     register D
e)      register E
f)       register H
g)      register L

Example: Store data 20 H in Accumulator, data 3E H in register B and data CA H is stored in register C.

Answer:

| Alamat Memori | Bahasa    |         | Keterangan                          |
|---------------|-----------|---------|-------------------------------------|
|               | Assembly  | Mesin   |                                     |
| 1800          | LD  A,20  | 3E   20 | Memasukkan data 20 H ke Accumulator |
| 1802          | LD  B,3E  | 06   3E | Memasukkan data 3E H ke register B  |
| 1804          | LD  C,CA  | 0E   CA | Memasukkan data CA H ke register C  |
| 1806          | RST  0038 | FF      | Mengakhiri program                  |

Run the program by pressing the RST-PC-GO buttons.

View the results by pressing the REG button followed by the register name.

Results: 

  • Accumulator = ...........
  • Register B = ............
  • Register C = ............

2. Storing Data on Register Pair

Format             :           LD  Pr,xx yy

dimana   LD    :           perintah Load Data
         Pr    :           nama pasangan register
         xx    :           data ke-1
         yy    :           data ke-2

Catatan:
Nama-nama pasangan register
a)      pasangan register AF (Accumulator dan Flag)
b)      pasangan register BC
c)      pasangan register DE
d)     pasangan register HL

Example: Store the data 0F25 H in the BC register pair, the data EECC H in the HL register pair and the data 0C00 H in the DE register pair.

Answer:

| Alamat Memori | Bahasa     |            | Keterangan                                 |
|---------------|------------|------------|--------------------------------------------|
|               | Assembly   | Mesin      |                                            |
| 1800          | LD BC,0F25 | 01  25  0F | Memasukkan data 0F25 H ke pasangan reg. BC |
| 1803          | LD HL,EECC | 21  CC  EE | Memasukkan data EECC H ke pasangan reg. HL |
| 1806          | LD DE,0C00 | 11  00  0C | Memasukkan data 0C00 H ke pasangan reg. DE |
| 1809          | RST  0038  | FF         | Mengakhiri program                         |

Run the program by pressing the RST-PC-GO buttons.

View the results by pressing the REG button followed by the register name.

Results:  

  • Register B = ...... Register C = ......
  • Register H = ...... Register L = ......
  • Register D = ...... Register E = ......

3. Move / copy data from one register to another register

Format             :           LD  rx,ry

dimana   LD    :           perintah Load Data
        rx      :           nama register tujuan
        ry      :           nama register asal data

Example:

1. In register A, data 02 H is stored, in register B, data 05 H is stored and in register C, data 63 H is stored.
2. Move/copy the data in register A to register D, the data in register B to register L and the data in register C to register H.

Answer:

| Alamat Memori | Bahasa   |        | Keterangan                                       |
|---------------|----------|--------|--------------------------------------------------|
|               | Assembly | Mesin  |                                                  |
| 1800          | LD A,02  | 3E  02 | Memasukkan data 02 H ke Accumulator              |
| 1802          | LD B,05  | 06  05 | Memasukkan data 05 ke register B                 |
| 1804          | LD C,63  | 0E  63 | Memasukkan data 63 ke register C                 |
| 1806          | LD D,A   | 57     | Meng-copy-kan ke register D data dari Accu.      |
| 1807          | LD L,B   | 70     | Meng-copy-kan ke register L data dari register B |
| 1808          | LD H,C   | 61     | Meng-copy-kan ke register H data dari register C |
| 1809          | RST 0038 | FF     | Mengakhiri program                               |

Run the program by pressing the RST-PC-GO buttons. View the results by pressing the REG button followed by the register name.

Results:

  • Accumulator = ...... Register B = ...... Register C = ......
  • Register D = ...... Register H = ...... Register L = ......

Task

1. Create a uPRO-1 program to:

  • Stores AE hex data. in register A, data 00 hex in register B.
  • Enter the EE AA data in the HL register pair.
  • Copy to register C data from Accumulator.

2. After the program is run, write the data in each of the following registers:

Results:  

  • Accumulator = ...... Register H = ...... Register L = ......
  • Register B = ...... Register C = ......
| SMKN 2 YOGYAKARTA                 | Kompetensi                                   | Kode            : 06/PDTM/KL10/SR |
|-----------------------------------|----------------------------------------------|-----------------------------------|
| Prog. Keahlian : Tek. Audio Video | LOAD DATA (LD)   (BAGIAN 2) STRUKTUR PROGRAM | Waktu          :      menit       |
| Prog. Diklat     : PDTM           |                                              | Nama Siswa :                      |
| Kelas                : 10 AV      |                                              | Tanggal        :                  |

Performance Criteria:

  • Mention the use of the Load Data (LD) command.
  • Using program structures to solve problems.
  • Move/copy data from register to memory.
  • Move/copy data from memory to register.

4. Move / copy data from register to memory

Format          :     LD  (HL),r
dimana   LD     :     perintah Load Data
 (HL)     :           alamat memori yang tersimpan pada pasangan Register HL
 r        :           nama register asal data

Example:

  • Register E stores data CC H, register H stores data 00 H
  • Move data from register E to memory address 1A00, move data from register H to memory address 1A01.

Answer: 

According to the format, to indicate a memory address always use the HL register pair, so the data stored in the H register must be saved by moving the data in the H register to another register.

Using program structure to provide the sequence of program execution.

| Mengisi register E dengan data CC                                                       |
|-----------------------------------------------------------------------------------------|
| Mengisi register H dengan data 00                                                       |
| Pindahkan ke register B data dari register H                                            |
| Mengisi pasangan register HL dengan data 1A00                                           |
| Pindahkan ke alamat memori yang ditunjuk oleh pasangan register HL data dari register E |
| Mengisi pasangan register HL dengan data 1A01                                           |
| Pindahkan ke alamat memori yang ditunjuk oleh pasangan register HL data dari register B |
| Akhir program                                                                           |

Program writing/translation Program Structure

| Alamat Memori | Bahasa     |              | Keterangan                                                                                |
|---------------|------------|--------------|-------------------------------------------------------------------------------------------|
|               | Assembly   | Mesin        |                                                                                           |
| 1800          | LD E,CC    | 1E   CC      | Mengisi register E dengan data CC                                                         |
| 1802          | LD H,00    | 26   00      | Mengisi register H dengan data 00                                                         |
| 1804          | LD B,H     | 44           | Memindahkan ke register B data dari register H                                            |
| 1805          | LD HL,1A00 | 21  00  1A   | Mengisi pasangan register HL dengan data 1A00                                             |
| 1808          | LD (HL),E  | 73           | Memindahkan ke alamat memori yang ditunjuk oleh pasangan register HL data dari register E |
| 1809          | LD HL,1A01 | 21   01   1A | Mengisi pasangan register HL dengan data 1A01                                             |
| 180C          | LD (HL),B  | 70           | Memindahkan ke alamat memori yang ditunjuk oleh pasangan register HL data dari register B |
| 180B          | RST 0038   | FF           | Akhir program                                                                             |

Run the program by pressing the RST-PC-GO buttons. View the results by pressing the REG button followed by the register name.

Results:

  • Register E = ......  
  • Register B = ......

Then press the ADDR 1A00 button and press the DATA button.

  • Memory address 1A00 = ......
  • Memory address 1A01 = ......

5. Move / copy data from memory to register

Format         :           LD  r,(HL)

dimana   LD    :           perintah Load Data
         r     :           nama register tujuan
        (HL)   :           alamat memori yang tersimpan pada pasangan Register HL.

Example:

  • Memory address 1900 stores data 00 and memory address 1901 stores data EE H.
  • In register B, the data FF H is stored and in register C, the data AA H is stored.

Task: move to register B the data from memory address 1900, move to register C the data from memory address 1901.

Answer: Because data is filled into the memory address directly using the ADDR and DATA buttons, the program structure starts from:

| Mengisi register B dengan data FF                                                       |
|-----------------------------------------------------------------------------------------|
| Mengisi register C dengan data AA                                                       |
| Mengisi pasangan register HL dengan data 1900                                           |
| Pindahkan ke register B data dari alamat memori yang ditunjuk oleh pasangan register HL |
| Mengisi pasangan register HL dengan data 1901                                           |
| Pindahkan ke register C data dari alamat memori yang ditunjuk oleh pasangan register HL |
| Akhir program                                                                           |

Program

| Alamat Memori | Bahasa     |              | Keterangan                                                                                |
|---------------|------------|--------------|-------------------------------------------------------------------------------------------|
|               | Assembly   | Mesin        |                                                                                           |
| 1800          | LD B,FF    | 06   FF      | Mengisi register B dengan data FF                                                         |
| 1802          | LD C,AA    | 0E   AA      | Mengisi register C dengan data AA                                                         |
| 1804          | LD HL,1900 | 21   00   19 | Mengisi pasangan register HL dengan data 1900                                             |
| 1807          | LD B,(HL)  | 46           | Memindahkan ke register B data dari alamat memori yang ditunjuk oleh pasangan register HL |
| 1808          | LD HL,1901 | 21   01   19 | Mengisi pasangan register HL dengan data 1901                                             |
| 180B          | LD C,(HL)  | 4E           | Memindahkan ke register C data dari alamat memori yang ditunjuk oleh pasangan register HL |
| 180C          | RST 0038   | FF           | Akhir program                                                                             |

Then press the ADDR 1900 button and press the DATA button.

  • Memory address 1900 = 00
  • Memory address 1901 = EE

Run the program by pressing the RST-PC-GO buttons. View the results by pressing the REG button followed by the register name.

Results:

  • Register B = ...... (previously register B = FF)
  • Register C = ...... (previously register C = AA)

Question:

Memory address 1B00 stores CC data and memory address 1B01 stores EE data. In register D stores FF H data and in register E stores AA H data.

Task:

  1. Move to register C the data from memory address 1B00, move to register B the data from memory address 1B01.
  2. Exchange data in register D with data in register E
  3. Write the results of program execution for each register!

Post a Comment

Previous Next

نموذج الاتصال