The basic idea of all memory is the ability to store information. Of course, the stored information can be recalled or processed when needed. As an analogy, memory is like a group of mailboxes in a large apartment. A person can put information in a mailbox with a certain number on it. If the owner wants to retrieve the information, the owner can look in the mailbox with the correct number and retrieve the information.
In an 8-bit CPU, each mailbox in the above analogy consists of eight sets of on-off switches. The data or information provided is the condition of each switch. Each switch only has two conditions, namely on and off, so the information contained in it is a combination of on-off. In the eight switches, each switch represents one binary digit (bit). Bit one represents the on switch and bit zero represents the off switch. Each set of 8 switches has a specific address so that writing and reading data can be done correctly and properly.
In analogy, an apartment may have mailbox numbers 100-175 for the first floor and 200-275 for the second floor. These decimal numbers represent the number of people who have mailboxes. Since computers operate in binary, the number of addresses of data in memory is a multiple of two of the address lines. Suppose a computer has four address lines, then it has 24 or 16 addresses because four binary bits have 16 combinations. This computer will map 16 addresses from $0 to $F.
In the MC68HC05 microcontroller, there are ten address lines so that 1024 memory locations are obtained. While the MC68HC11 microcontroller has 16 address lines so that it can address 65536 memory locations. An 8-bit computer with ten address lines will have a memory map with 1024 addresses and each address has 8 data bits. The first address of the memory location is 00 0000 00002 and the last address is 11 1111 11112. The ten address bits are generally expressed in hexadecimal, so the range of the memory address is $0000 to $03FF. The computer determines which memory location to use by placing a binary combination on the 10 address lines and then sending a read or write signal. As a result, the desired information at the particular memory address above will appear in eight data lines.
Types of Memory
Computers use several types of information and therefore require several different types of memory. The instructions that control the operation of the microcontroller are stored in non-volatile memory so that the system does not need to be reprogrammed if the system power is lost. Temporary variables and results can be stored in memory that can be written easily and quickly while operations are in progress. It is not necessary to continue to remember information written when power is lost (volatile).
RAM (Random Access Memory) is a form of volatile memory that can be read and written by the CPU. As the definition suggests, RAM locations can be accessed in various (random) sequences. This type of memory is the most commonly used by personal computers. RAM requires a wider chip area compared to ROM, so only a small portion of RAM is included in the microcontroller system.
ROM (Read Only Memory) is filled during the production process. The information written must be ordered by the customer before the chip is delivered. In a microcontroller system, this information can be read by the CPU but cannot be changed. ROM is the simplest, smallest, and cheapest memory.
PROM (Programmable ROM) is similar to ROM except that it can be programmed after the chip is manufactured. Some variations of PROM are EPROM, OTP, and EEPROM.
EPROM (Erasable PROM) can be erased by shining ultraviolet light on it. Microcontrollers with erasable EPROM have a small window through which the light can be applied. The number of erasing operations allowed is limited depending on the type. Special procedures are used to program information into the EPROM memory. Most microcontrollers with EPROM use +12 volts DC during the EPROM write operation. The CPU cannot write data to the EPROM location as it can write to RAM. Some microcontrollers have a built-in EPROM writer circuit.
OTP (One Time Programming) is an EPROM that is not equipped with a window for ultraviolet irradiation. Although the contents of the OTP are the same as EPROM that has an erase window, OTP cannot be erased because it does not provide a window. OTP is marketed because it is cheaper than windowed EPROM.
EEPROM (Electrically EPROM) can be erased electrically with a command in the microcontroller. In order to program a new price to this memory location, the erasure process must first be carried out and then several programming steps are carried out. Although similar to RAM, EEPROM still has the non-volatile nature of ROM which does not lose its data even if power is lost.
I/O As Memory Type
Status and control information from I/O is a type of memory location that allows a computer system to obtain information from and to the outside world. This type of memory location is unlike regular memory because the information contained therein can change due to influences other than the CPU.
The simplest types of I/O memory locations are simple input and output ports. In an 8-bit microcontroller, a simple input port consists of eight pins that can be read by the CPU. A simple output port consists of eight pins that can be controlled by the CPU. In reality, a simple output port is implemented with eight latches and a feedback path that allows the CPU to read back what was previously written to the output port.
The figure below shows the equivalent circuit of one bit of RAM, one bit of input port, and one bit of output port that is common and has read-back capability. In a real microcontroller, there are eight of these circuits to form eight bits of RAM, input ports, and output ports. When the clock signal is high, data from the D input goes to the Q output. When the clock input is low, data is held at the Q output leg.
Output Port with Read-Back
When the CPU stores information into the RAM in figure (a), the WRITE signal is activated to hold the data from the data bus line into the flip-flop [1]. The latch will continue to remember the data that has been given until it is written back or power is removed. When the CPU reads data from this RAM, the READ signal is activated, which then activates the multiplexer [2]. The multiplexer makes the data from the latch output reappear onto the data bus line.
When the CPU reads data from the input port as shown in figure (b), the READ signal is activated, which will activate the multiplexer [3]. This multiplexer will send the data in the buffer to the data bus line. The write signal has no effect in this circuit.
When the CPU stores data to an output port as shown in figure (c), the WRITE signal is activated to hold the data from the data bus to the flip-flop [4]. The output of this latch, which is buffered by the buffer driver [5], appears as a digital value on the output leg. When the CPU wants to read data from the output port, the READ signal is activated, which activates the multiplexer [6]. This multiplexer will channel the data from the flip-flop output to the data bus line.
Internal Control and Status Registers
Internal control and status registers are special I/O memory locations. In addition to the external sensor and control leg actions, these registers also perform sensor and control actions on internal logic level signals. Look at the picture and compare RAM with an output port. The only visible difference is that the output port has a buffer to connect the state of the flip-flop to the external leg. In the case of an internal control bit, the output of the buffer is connected to a specific internal control signal. An internal status bit is similar to an input port bit but it only performs sensor actions on internal register signals.
The M68HC05 microcontroller has parallel I/O pins. The path direction of each pin can be programmed with control bits through software. The figure below illustrates bi-directional I/O with latch output and data direction control bits. A port pin is configured as an output if the corresponding DDR (Data Direction Register) bit is set to logic one. A pin is configured as an input if the corresponding DDR bit is set to logic zero. When first turned on or during reset, all DDR bits are zeroed, so the configuration of all port pins is as input. This DDR can be written and read by the processor.
Memory Map
Since there are thousands and even more memory locations in a microcontroller system, it becomes important to have a convenient way to handle the addresses of each data in memory. A memory map is a representation of all the spaces in the microcontroller's memory. The figure below is a typical memory map depicting the memory in the MC68HC705K1.
The four hexadecimal digits on the left side of the image below are addresses that start at $0000 at the top and continue up to $03F at the bottom. The address $0000 corresponds to the beginning of the memory location while the address $03FF corresponds to the end of the memory location. The information in the boxes indicates the type of memory and its contents (RAM, EPROM, I/O registers, and so on). Some areas, such as the I/O registers, need to be explained in more detail because it is important to know the name of each location. Each of the 1024 memory locations has eight bits of data as shown in the image below.
The first 256 memory locations ($0000-$00FF) can be accessed by the computer in a special way called direct addressing mode. The on-chip I/O registers and 32 bytes of RAM are located in the $0000-$00FF area.
I/O and Memory Structure
The 89C51 microcontroller is a microcontroller with MCS51 architecture like 8031 with PEROM (Programmable and Erasable Read Only Memory) Flash memory.
89C51 Microcontroller
Pin Description
| Nomor Pin | Nama Pin | Alternatif | Keterangan |
|-------------------------|-----------------------------------------|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 20 | GND | | Ground |
| 40 | VCC | | Power Supply |
| 32…39 | P0.7…P0.0 | D7…D0 & A7…A0 | Port 0 dapat berfungsi sebagai I/O biasa, low order multiplex address/data ataupun menerima kode byte pada saat Flash Programming Pada fungsi sebagai I/O biasa port ini dapat memberikan output sink ke delapan buah TTL Input atau dapat diubah sebagai input dengan memberikan logika 1 pada port tersebut Pada fungsi sebagai low order multiplex address/data port ini akan mempunyai internal pull up Pada saat Flash Programming diperlukan external pull up Terutama pada saat verifikasi program |
| 1…8 | P1.0…P1.7 | | Port 1 berfungsi sebagai I/O biasa atau menerima low order address bytes selama pada saat Flash Programming Port ini mempunyai internal pull up dan berfungsi sebagai input dengan memberikan logika 1 Sebagai output port ini dapat memberikan output sink ke empat buah input TTL |
| 21…28 | P2.0…P2.7 | A8…A15 | Port 2 berfungsi sebagai I/O biasa atau high order address, pada saat mengakses memory secara 16 bit (Movx @Dptr) Pada saat mengakes memory secara 8 bit, (Mov @Rn) port ini akan mengeluarkan isi dari P2 Special Function Register Port ini mempunyai internal pull up dan berfungsi sebagai input dengan memberikan logika 1 Sebagai output port ini dapat memberikan output sink Ke empat buah input TTL |
| 10…17 | | Port 3 | Sebagai I/O biasa Port 3 mempunyai sifat yang sama dengan Port 1 maupun Port 2 Sedangkan sebagai fungsi spesial port-port ini mempunyai keterangan sebagai berikut |
| 10 11 12 13 14 15 16 17 | P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 | RXD TXD INT0 INT1 T0 T1 WR RD | Port Serial Input Port Serial Output Port External Interrupt 0 Port External Interrupt 1 Port External Timer 0 Input Port External Timer 1 Input External Data Memory Write Strobe External Data Memory Read Strobe |
| 9 | RST | | Reset akan aktif dengan memberikan input high selama 2 cycle |
| 30 | ALE | PROG | Pin ini dapat berfungsi sebagai Address Latch Enable (ALE) |
| | | | yang me-latch low byte address pada saat mengakses |
| | | | memori eksternal Sedangkan pada saat Flash Programming (PROG) berfungsi sebagai pulse input untuk Pada operasi normal ALE akan mengeluarkan sinyal clock sebesar 1/16 frekwensi oscillator kecuali pada saat mengakses memori eksternal Sinyal clock pada pin ini dapat pula didisable dengan men-set bit 0 dari Special Function Register di alamat 8EH ALE hanya akan aktif pada saat mengakses memori ekster- nal (MOVX & MOVC) |
| 29 | PSEN | | Pin ini berfungsi pada saat mengeksekusi program yang ter- letak pada memori eksternal. PSEN akan aktif dua kali setiap cycle |
| 31 | EA | VP | Pada kondisi low maka pin ini akan berfungsi sebagai EA yaitu mikrokontroler akan menjalankan program yang ada pada memori eksternal setelah sistem direset Apabila berkondisi high maka pin ini akan berfungsi untuk menjalankan program yang ada pada memori internal Pada saat Flash Programming pin ini akan mendapat te- gangan 12 Volt (VP) |
| 19 | XTAL1 | | Input Oscillator |
| 18 | XTAL2 | | Output Oscillator |
Memory Structure
The memory of the 89C51 is divided into:
Internal RAM
- Bank Registration
- Bit addressable RAM
- General Purpose RAM
Special Function Register
Flash PEROM
External Memory
Internal RAM & Special Function Registers
internal ram & special function registers
Accumulator (ACC)
- Located at address E0H
- Arithmetic Operations (Add A,#05H)
- Logical Operations (Anl A,#05H)
- External Memory Access (Movx A,@DPTR)
- For general functions.
Register B
- Located at address B0H
- General functions
- Used with Acc for Arithmetic operations (Mul AB).
Status Word Program (D0H)
PSW
Port
- Port 0 (80H)
- Port 1 (90H)
- Port 2 (A0H)
- Port 3 (B0H)
Data Pointer (DPTR)
- Consists of two registers, namely o DPH (82H) o DPL (83H)
- To access data or source code in Flash PEROM memory or External Memory.
Stack Pointer
Flash PEROM
Capacity 4 Kb
Addresses 000H to FFFH - Accessed when:
- EA/VP pin 89C51 is logic high
- There is a command to call the instruction at that address - Can be protected with:
- Lock Bit 1, cannot be read by programs located in external memory
- Lock Bit 2, cannot be read by Programmer equipment o Lock Bit 3, cannot access/be accessed by/from external memory at all.
External Memory
- Needed for: o Large capacity memory o Program Emulation
- Multiplex Addressing addressing system.
Multiplex Addressing
The 89C51's addressing to external memory is split into;
The low byte of the address bus is multiplexed with the data bus by the D Latch.
Control Bus
External Memory Access consists of:
- Data Reading
- Program Reading (Code)
- Data/Code Writing
Reading Process
The reading process can be likened to the process of reading from a certain page of a book where the process requires:
- Page of text to be read = Memory Address
- Command to read = Read signal for Data and PSEN signal for code.
Reading Data from External Memory
Instructions:
MOV DPTR,#[address] ; Penentuan lokasi data yang akan dibaca
MOVX A,@DPTR ; Perintah pembacaan data sekaligus meng-
; ambil data tersebut dan disimpan ke Aku-
; mulator A
Timing
Timing Diagram for Reading Data from External Memory (Taken from AT89C51 Data Sheet)
Reading Code from External Memory
Timing Diagram for Reading Code from External Memory (taken from AT89C51 Data Sheet)
Writing Data to External Memory
The writing process can be likened to writing a text on a specific page in a book where it is needed.
- The text to be written = Data
- Page to be written = Address
- Write command = Write signal
Figure 1.11 Timing Diagram for Writing Data to External Memory taken from the AT89C51 Data Sheet)