Файл: Embedded Controller Hardware Design (Ken Arnold, 2001).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2667
Скачиваний: 0
32EMBEDDED CONTROLLER
Hardware Design
The lower 128 byte half of the 256 byte internal data memory address space contains four blocks of eight CPU registers, R0-7. In the 8032 CPU, the upper 128 bytes of the internal data memory address space are shared between data memory and the SFRs, depending upon the address mode. The upper 128 bytes of data memory must be accessed using the indirect register 0/1 (@R0 or @R1 operands) or stack accesses, and all other references to addresses of 128 or higher will access the SFRs. All registers except the program counter and the four 8-register banks reside in the special function register address space. These memory mapped registers include arithmetic registers, pointers, I/O ports, and registers for the interrupt system, timers and serial channel. There are 128 bit locations in the SFR address space that are addressable as bits. The 8031 contains 128 bytes of internal data RAM and 20 special function regis ters (SFRs), while most other processor family variants include an additional 128 bytes of internal data memory overlapped with the SFR addresses.
8051 CPU Hardware
The 8051 is classified as an 8-bit machine, since the internal ROM, RAM, special function registers, arithmetic/logic unit and external data bus are each eight bits wide. The 8031 is identical to the 8051, except that it does not have any internal program ROM. The 8051 performs operations on bit, nibble, byte and double-byte data types. It excels at bit handling since data transfer, logic and conditional branch operations can be performed directly on the bit address able SFRs.
This section describes the hardware architecture of the 805l CPU. A detailed 8051 functional block diagram is displayed in Figure 2-7.
Internal |
||||||||||||
Data |
||||||||||||
Control |
Instruction |
|||||||||||
Memory |
||||||||||||
Unit |
Register |
Port 3 |
||||||||||
ACC |
||||||||||||
B |
||||||||||||
PSW |
Program |
Port 2 |
||||||||||
I/O Ports |
Counter |
|||||||||||
Timers |
Internal |
|||||||||||
Dater Pointer |
Program |
Port 1 |
||||||||||
Stack Pointer |
Arithmetic |
Memory |
||||||||||
ROM |
||||||||||||
G.P. Memory |
Logic |
Port 0 |
||||||||||
Registers |
Unit |
|||||||||||
Figure 2-7: 8051 CPU block diagram.
33CHAPTER TWO
Microcontroller Concepts
Control Unit
Each program instruction is decoded by the control unit, which is also called the instruction decoder. This unit generates the internal signals that control the functions of all the other units within the CPU section. All instructions are fetched from the program memory ONLY. Instructions can be fetched from either the internal program memory (for those devices which possess one)
or from external program memory. Instruction fetch operations are indicated when the CPU activates (lowers) the /PSEN line (NOT program strobe enable). A program memory fetch cycle lasts as long as /PSEN stays low. External program memory must only drive the data bus with the addressed instruction while /PSEN is low.
Program Counter
This is the pointer to the next instruction to be executed. The 16-bit program counter (PC) controls the sequence in which the instructions stored in pro gram memory are executed.
Instruction Register
This is the register that contains the instruction that is currently being executed.
Internal Program Memory
The 8051 family has 16 address lines, and can directly address 216 = 64 kilobytes of program memory. The original 8051 has 4 kilobytes of program memory resident on-chip, the 8031 has no on-chip program memory, and the 8052 has 8 kilobytes of program memory. Other variants of the family are available with 1 to 64 kilobytes of various types of non-volatile program memory built in. The 64 kilobyte program memory address space is composed of a combina tion of internal and external program memory (external program memory only on the 8031 and 8032). When external program memory is accessed, and the processor is fetching an instruction to be executed, the external pro gram read cycle is signaled by activating the CPU’s /PSEN control line. The MOVC instruction also activates /PSEN to enable reading the code memory
34 EMBEDDED CONTROLLER
Hardware Design
into the accumulator for accessing lookup tables |
Program |
||
(Code) |
|||
and other unchanging data stored in the program |
Memory |
||
FFFF |
|||
memory space. Figure 2-8 shows a program |
External |
||
memory map. |
Figure 2-8: |
Program |
|
Memory |
|||
Program |
/PSEN |
||
The processor can fetch instructions from internal |
memory map. |
||
Pulses |
|||
or external program memory. There is a control |
Low |
||
MOVC a |
|||
input pin, /EA (external access), which forces all |
2000 |
||
instructions to be fetched from the external |
1FFF |
Internal |
|
program memory when the pin is pulled low. |
Program |
||
Memory |
|||
If the /EA pin is pulled high, then the processor |
Reset Vector: 0000 |
||
will fetch instructions from any available internal
program memory. When the processor first powers up and receives a reset signal, it begins by executing the instruction at location 0000 in program memory. When the processor fetches instructions from external program memory, it puts the instruction address out on the address bus, pulses the /PSEN (program strobe enable) pin low to enable the external program memory to place the instruction on the data bus to the processor.
The generic part numbering scheme is as follows:
•8xxx: NMOS logic
•8xCxx: CMOS logic
•803x: No internal program memory
•805x: Factory programmed internal ROM program memory
•87xx: Internal user programmable EPROM program memory
•89xx: Internal flash EPROM program memory
•8xx1: 4 kilobyte internal program memory, 128 byte internal RAM
•8xx2: 8 kilobyte internal program memory, 256 byte internal RAM
For example, the 80C32 used as the standard processor in the SDK board is a CMOS part with no internal program ROM, and 256 bytes of internal data RAM.
Internal Data Memory
Figure 2-9 shows the data memory spaces in the 8051. The internal data RAM provides a convenient 128 byte scratch pad memory that includes the register
35CHAPTER TWO
Microcontroller Concepts
banks, SFRs, and general-purpose data storage. The programmer (or com piler) may also use this scratch pad memory for storing intermediate calcula tions on a temporary basis. The 8031 contains a 128 byte internal data RAM (addresses 0-7Fh, which includes registers R0-R7 in each of four banks), in addition to the memory-mapped special function register (locations 80-FFh). The 8032 has an additional 128 bytes of internal data RAM also at locations 80-FFh, which can only be accessed by using indirect register addressing (@R0, @R1) and the stack. The lower 128 byte half of the 256 byte internal data memory address space contains four blocks of eight CPU registers, R0-7. In the 80x2 CPU, the upper 128 bytes of the internal data memory address space are shared between data memory and the SFRs, depending upon the address mode. The upper 128 bytes of data memory must be accessed using the indirect register 0/1 (@R0 or @R1 operands) or stack accesses, and all other references to addresses of 128 or higher will access the SFRs. All regis ters, except the program counter and the four 8-register banks, reside in the special function register address space. These memory mapped registers in clude arithmetic registers, pointers, I/O ports, and registers for the interrupt system, timers and serial channel. There are 128 bit locations in the SFR
address space that are address- |
External |
|||||
able as bits. The 8031 contains |
Data |
|||||
Memory |
||||||
128 bytes of internal data |
Figure 2-9: Data memory |
FFFF |
||||
RAM and 20 special function |
address spaces in the 8051. |
|||||
registers (SFRs), while most |
External |
|||||
other processor family variants |
Internal |
Special |
Data |
|||
Memory |
||||||
include an additional 128 bytes |
Data |
Function |
||||
Memory |
Registers |
/RD |
||||
of internal data memory over |
See below |
See separate |
or |
|||
address map |
/WR |
|||||
lapped with the SFR addresses. |
FF |
FF |
Pulse |
|||
80 |
MOV @R0/1 |
80 |
MOV 80-FF |
Low |
||
7F |
Some SFRs |
MOVX a |
||||
MOV 00-7F |
||||||
00 |
are also bit |
0000 |
||||
Data Memory |
addressable |
|||||
The 8051 family devices have two data memories, internal and external. With 16 address bits, there is a maximum of 64 kilobytes of external data memory, which is useful for storing large blocks of variable information that will not fit in the internal data RAM. It is enabled when the processor reads or writes data from the external data memory, signaled by activating the /RD and /WR control lines. This occurs only when a MOVX instruction is used to read or write from external memory.
36EMBEDDED CONTROLLER
Hardware Design
The internal data address space has two different parts, as shown in Figure 2-10. One part contains the general-purpose registers and general-purpose data storage RAM, and the other part contains all the special registers and I/O devices, such as the parallel and serial ports, and timers. These registers are called special func tion registers. There is a maximum of 256 bytes of internal RAM (128 bytes for the ’31/’51, 256 bytes for the ’32/’52) and special function registers (SFR). Four register banks (each bank has eight registers), 128 individually addressable memory bits, and the stack all reside in the internal data RAM. The stack depth is limited only by the available internal data RAM. The 8-bit stack pointer determines the stack’s location.
FF |
Shared: |
|||
SFRS and |
||||
Indirect |
||||
80 |
@R0 OR @R1 |
|||
7F |
General |
|||
30 |
Purpose |
|||
2F |
Bit |
|||
20 |
Addressable |
|||
1F |
R7 |
3 |
||
18 |
• |
Bank |
||
R0 |
||||
• |
||||
• |
||||
17 |
||||
R7 |
2 |
|||
• |
Bank |
|||
• |
||||
10 |
• |
|||
R0 |
||||
0F |
R7 |
1 |
||
08 |
• |
Bank |
||
R0 |
||||
• |
||||
• |
||||
07 |
||||
R7 |
MOV R7 |
|||
06 |
R6 |
|||
05 |
R5 |
0 |
Current Bank |
|
04 |
R4 |
Number is |
||
|
Bank |
||||
RS1, RS0 Bits |
||||
03 |
R3 |
Selected by |
||
02 |
R2 |
in PSW |
||
01 |
R1 |
MOV R1 |
||
(PSW.R, PSW.R |
||||
00 |
R0 |
MOV R0 |
||
Figure 2-10: The internal data memory.
The internal data RAM provides a convenient 128 byte scratch pad memory which includes the register banks, SFRs, and general purpose data storage.
RAM locations 00-7F hex
•Register banks: There are four register banks within the internal data RAM. Each register bank contains registers R7-R0.
•128 addressable RAM bits: In the 8031, there are 128 addressable software flags in the internal data RAM. They are located in the 16 byte locations starting at byte address 20h and ending with byte location 2Fh of the RAM address space.
Special Function Register (SFR) locations 80-FF hex
•General registers A, B, and other registers are mapped here.
•Parallel I/O ports: The 8031 has four 8-bit ports.
37CHAPTER TWO
Microcontroller Concepts
•Serial I/O port: The serial I/O port built into the 8031.
•Timer/counters: There are counters that can count external events or count processor clock cycles to operate as timers. Many of the SFRs are also bit addressable.
Bit Addressable Memory
Figure 2-11 shows the organization of bit addressable space in the internal data memory. The bit address space has a total of 256 possible bit addresses. The first 128 bits, 00 to 7F hex, are used to access individual bits of the inter nal memory from location 20 to 2F hex. The second 128 bits, from 80 to FF hex, allow selected bits in the special function registers to be accessed at the bit level. Not all SFRs are bit addressable, and not all bit addresses are used in
most processors. |
Byte |
Bit Number |
||||||||||
Internal |
7 |
2 |
1 |
0 |
||||||||
Data |
Addr |
6 |
5 |
4 |
3 |
|||||||
Memory |
2F |
7F |
7E |
7D |
7C |
7B |
7A |
79 |
78 |
|||
2E |
77 |
76 |
75 |
74 |
73 |
72 |
71 |
70 |
||||
7F |
2D |
6F |
6E |
6D |
6C |
6B |
6A |
69 |
68 |
|||
2C |
67 |
66 |
65 |
64 |
63 |
62 |
61 |
60 |
||||
30 |
2B |
5F |
5E |
5D |
5C |
5B |
5A |
59 |
58 |
|||
2A |
57 |
56 |
55 |
54 |
53 |
52 |
51 |
50 |
||||
2F |
29 |
4F |
4E |
4D |
4C |
4B |
4A |
49 |
48 |
|||
Bit |
28 |
47 |
46 |
45 |
44 |
43 |
42 |
41 |
40 |
|||
3F |
3E |
3D |
3C |
3B |
3A |
39 |
38 |
|||||
Addressable |
27 |
|||||||||||
26 |
37 |
36 |
35 |
34 |
33 |
32 |
31 |
30 |
||||
20 |
25 |
2F |
2E |
2D |
2C |
2B |
2A |
29 |
28 |
|||
24 |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
||||
1F |
||||||||||||
23 |
1F |
1E |
1D |
1C |
1B |
1A |
19 |
18 |
||||
21 |
17 |
16 |
15 |
14 |
13 |
12 |
11 |
10 |
||||
22 |
0F |
0E |
0D |
0C |
0B |
0A |
09 |
08 |
||||
00 |
20 |
07 |
06 |
05 |
04 |
03 |
02 |
01 |
00 |
|||
Figure 2-11: Bit addressable |
MOV C<->bit# |
CPL bit# |
||||||||||
CLR |
bit# |
JB |
bit#, addr |
|||||||||
space in the internal data memory. |
SETB bit# |
JNB bit#, addr |
||||||||||
Bit addressable memory allows the manipulation and test of individual bits, which is a very common operation in embedded systems. Almost every appli cation requires that some output bits be used to control an on/off device, such as an indicator or relay. Likewise input bits are used to sense the status of some external device, such as a switch or sensor. The bit addressable address space allows the programmer to operate on information at the bit level just as easily as at the byte level. This is contrasted by most other processors, in which the programmer must write multiple instructions to select the appropriate bit in a byte before processing or testing it.