Introduction to Micro Controllers Embedded System Design MicroprocessorMicrocontroller
Introduction to Micro Controllers & Embedded System Design Microprocessor/Microcontroller Department of Electrical & Computer Engineering Missouri University of Science & Technology hurson@mst. edu A. R. Hurson 1
Introduction to Micro Controllers & Embedded System Design • Microprocessor: a general purpose computer that is contained in a single integrated circuit (all peripherals are off the CPU chip). In another words, it is a CPU on chip. • A system designer using a microprocessor must add memory, I/O devices, … on need basis, externally. • Examples include Intel’s x 86 family, Motorola’s 860 x 0 family, … A. R. Hurson 2
Introduction to Micro Controllers & Embedded System Design • A sample microprocessor • Block diagram of the architecture of the Z 80 microprocessor showing: the arithmetic and logic section, register file, control logic section, and buffers to external address and data lines. A. R. Hurson 3
Introduction to Micro Controllers & Embedded System Design • A sample microprocessor • Z 80 Architecture A. R. Hurson Source: https: //en. wikipedia. org 4
Introduction to Micro Controllers & Embedded System Design • Originally, the concept of microprocessor introduced in early 70 s (4 -bit Intel 4004) • As the technology advanced and chip density increased, so did the functionality and complexity of a microprocessor. • Word size changed from 4 -bit to 64 -bit, • Floating point operations were added, and • CPU caches were introduced. A. R. Hurson 5
Introduction to Micro Controllers & Embedded System Design • Microcontroller: A microprocessor with a number of integrated peripherals, typically used in controloriented applications (everything is on one chip). • Typically, it contains a CPU (could be more than one), memory, and I/O peripherals. • Microcontrollers are designed for embedded applications. A. R. Hurson 6
Introduction to Micro Controllers & Embedded System Design • General architecture of a Microcontroller A. R. Hurson Source: elprocus. com 7
Introduction to Micro Controllers & Embedded System Design • General architecture of a Microcontroller • • • CPU: Central Processing Unit • Timers: to be used for various functions such as, lock functions, modulations, pulse generation, … • Interrupt RAM: Random Access Memory ROM: Read Only Memory I/O ports: Parallel I/O port and Serial I/O port ADC: Analog to Digital Converter and Digital to Analog Converter A. R. Hurson 8
Introduction to Micro Controllers & Embedded System Design • Embedded systems: An embedded system is a computer system with a dedicated functionality within a larger mechanical or electrical system, often with real-time computing constraints. • It is embedded as part of a complete device often including hardware and mechanical parts. • • Embedded systems control many devices in common use today. Ninety-eight percent of all microprocessors are manufactured as components of embedded systems. A. R. Hurson Source: https: //en. wikipedia. org 9
Introduction to Micro Controllers & Embedded System Design • Embedded systems • Compared to general-purpose computers, typically embedded computers are low power consumption, small size, rugged operating ranges, and low per-unit cost. • These advantages comes at the cost of limited processing capabilities, which make them significantly more difficult to program and to interact with. • Embedded systems are commonly found in consumer, cooking, industrial, automotive, medical, commercial, and military applications. A. R. Hurson 10
Introduction to Micro Controllers & Embedded System Design • Attributes of Embedded devices • Embedded system is something that was not designed to be general purpose, • • • Embedded devices are usually tuned for one or a few applications, • Embedded systems are devices users purchase for a reason that is not thought of as “computing”. Most embedded devices embody the capability they perform, Embedded systems are often commodities rather than capital items themselves, A. R. Hurson 11
Introduction to Micro Controllers & Embedded System Design • Block diagram of a microprocessor/microcontroller system Address bus (16 lines) Data bus (8 lines) C P U Control bus (6 lines) RAM ROM Interface circuitry Peripheral devices A. R. Hurson 12
Introduction to Micro Controllers & Embedded System Design • Intel 8051 family Company Processor Year Intel 4004 4 -bit 1971 Intel 8085 8 -bit 1974 Intel 8048 8 -bit 1976 Intel 8031 8 -bit (ROM less) Intel 8051 8 -bit (Mask ROM) 1980 Intel 8086 16 -bit 1978 Atmel At 89 C 51 8 -bit (Flash Memory) 1984 Microchip PIC 16 C 64 8 -bit 1985 Motorola 68 HC 11 8 -bit (ON chip ADC 1985 AVR 8 -bit RISC 1996 A. R. Hurson 13
Introduction to Micro Controllers & Embedded System Design • Features of various Intel microcontroller 8051 8052 8031 8032 8751 8752 4 K bytes ROM 8 K bytes ROM 0 K ROM 4 K bytes EPROM 8 K bytes EPROM 128 bytes RAM 256 bytes RAM 2 Timers 3 Timers A. R. Hurson 14
Introduction to Micro Controllers & Embedded System Design • Features of MCS-51 Feature Quantity ROM 4 K bytes RAM 128 bytes I/O Ports 4 (8 -bit) I/O Pins 32 Serial port 1 Interrupt sources 6 Two 16 bits timers A. R. Hurson External code memory 64 K bytes External data memory 64 K bytes Boolean processor Bit slice Bit-addressable locations 210 Multiply/divide 4 s 15
Introduction to Micro Controllers & Embedded System Design • Detailed block diagram of a microprocessor/microcontroller External clocks External interrupts Serial device Parallel device Serial interface Parallel interface Internal clocks Timer C P U Interrupt control Address, data, and control buses RAM A. R. Hurson ROM 16
Introduction to Micro Controllers & Embedded System Design • Central Processing Unit: Monitors and controls all operations performed. On the microcontroller. It reads program instructions from ROM memory and executes them. A. R. Hurson 17
Introduction to Micro Controllers & Embedded System Design • Interrupts • It is a subroutine call that interrupts (pauses) the Intel 8051’s main operations or work and causes it to execute any other program, which is more important at the time of operation. • Generally five interrupt sources are recognized in 8051 Microcontroller. • When a subroutine is completed, the execution of main program resumes. A. R. Hurson 18
Introduction to Micro Controllers & Embedded System Design • Memory • Read Only Memory (ROM) or program memory is 4 K bytes. • Random Access Memory (RAM) or data memory is 128 bytes. A. R. Hurson 19
Introduction to Micro Controllers & Embedded System Design • BUS • Address Bus is a 16 -bit bus to address memory location • Data Bus is an 8 -bit bus to transfer data A. R. Hurson 20
Introduction to Micro Controllers & Embedded System Design • Input/Output Port: Intel 8051 has four 8 -bit parallel and one serial I/O ports. A. R. Hurson 21
VCC Introduction to Micro Controllers & Embedded System Design 40 XTL 1 Pin Configuration A. R. Hurson P 0. 7 P 0. 6 P 0. 5 P 0. 4 P 0. 3 P 0. 2 P 0. 1 P 0. 0 19 XTL 2 18 PSEN 29 ALE 30 EA 31 RST 9 RD WR T 1 T 0 INT 1 INT 0 TXD RXD 17 16 15 14 13 12 11 10 P 3. 7 P 3. 6 P 3. 5 P 3. 4 P 3. 3 P 3. 2 P 3. 1 P 3. 0 20 32 33 34 35 36 37 38 39 P 1. 7 P 1. 6 P 1. 5 P 1. 4 P 1. 3 P 1. 2 P 1. 1 P 1. 0 8 7 6 5 4 3 2 1 P 2. 7 P 2. 6 P 2. 5 P 2. 4 P 2. 3 P 2. 2 P 2. 1 P 2. 0 28 27 26 25 24 23 22 21 AD 7 AD 6 AD 5 AD 4 AD 3 AD 2 AD 1 AD 0 A 15 A 14 A 13 A 12 A 11 A 10 A 9 A 8 22 VSS
Introduction to Micro Controllers & Embedded System Design • Port 0 (Pins 32 to 39) is a dual-purpose port. In minimum configuration design, it is a general purpose I/O port. For larger designs with external memory, it becomes a multiplexed address and data bus. • Port 1 (Pins 1 to 8) is a dedicated I/O port and available to external devices as required. In 8032/8052 configurations, P 1. 0 and P 1. 1 are used either as I/O lines or as an external inputs to the third timer. • Port 2 (Pins 21 to 28) is also a dual-purpose port serving as general purpose I/O or as the high byte of the address bus for designs with external code memory or more than 256 bytes of external data memory. A. R. Hurson 23
Introduction to Micro Controllers & Embedded System Design • Port 3 (Pin 10 to 17) is another dual purpose port. It is either a general purpose I/O or they are multifunctional, each having alternate purpose as follows: Bit Name Bit address Alternate function P 3. 0 RXD B 0 H Receive data for serial port P 3. 1 TXD B 1 H Transmit data for serial port P 3. 2 B 2 H External interrupt P 3. 3 B 3 H External interrupt P 3. 4 T 0 B 4 H Timer/counter external input P 3. 5 T 1 B 5 H Timer/counter external input P 3. 6 B 6 H External data memory write strobe P 3. 7 B 7 H External data memory read strobe P 1. 0 T 2 90 H Timer/counter external input P 1. 1 T 2 EX 91 H Timer/counter capture/reload A. R. Hurson 24
Introduction to Micro Controllers & Embedded System Design • Program Store Enable (Pin 29) is a co troll signal that enables external program memory (note: 8051 has four dedicated control signals). It is usually connected to an EPROM output enable pin. • PSEN signal pulses low during the fetch cycle of an instruction stored in external program memory. The op. code is read from memory, travels across data bus, and latches into instruction register for decoding. When executing program from internal ROM memory PSEN remains in inactive (high) state. A. R. Hurson 25
Introduction to Micro Controllers & Embedded System Design • Address Latch Enable (Pin 30) is used de-multiplexing the address and data bus when port 0 is used in its alternate modes (i. e. , as the data bus and the low-byte of the address bus). • ALE is the signal that latches the address into an external register during the 1 st half of a memory cycle. Then the port 0 lines are available for data input or output during the 2 nd half of the memory cycle when data transfer takes place. A. R. Hurson 26
Introduction to Micro Controllers & Embedded System Design • External Access (Pin 31) is generally tied high (+5 volts) or low (ground). If high the 8051/8052 executes programs from internal ROM memory. If low, programs execute from external memory only. • On-chip Oscillator inputs (Pins 18 & 19) − These pins are used for interfacing an external crystal to get the system clock. A. R. Hurson 27
Introduction to Micro Controllers & Embedded System Design • Reset (Pin 9) is the master RESET for 8051. When this signal is high for at least two machine cycles, the 8051 internal registers are loaded with initial values in an orderly system start-up. For normal operation, RST is low. • Power connection (Pines 20 & 40) 8051 operate from a signal +5 volts supply. The Vcc connection is on pin 40 and Vss connection (ground) is on pin 20. A. R. Hurson 28
Introduction to Micro Controllers & Embedded System Design • Memory organization • Most microprocessors like other computers use a random access memory for both programs and data (i. e. , stored program machine). This is not the case for microcontroller systems (say why? ). • In case of 8051/8052 internal memory consists of on-chip ROM (program memory) and on-chip RAM (data memory). • The on-chip RAM contains a rich arrangement of generalpurpose storage, bit addressable storage, register banks, and special function registers. A. R. Hurson 29
Introduction to Micro Controllers & Embedded System Design • Memory organization • Note: Registers and Input/Output ports are memory mapped and accessible like any other memory location. • Stack resides within the internal RAM. A. R. Hurson 30
Introduction to Micro Controllers & Embedded System Design • Memory organization • In general, RAM memory can be partitioned into three groups: • 32 bytes from locations 00 H to 1 FH are register banks and stack. These 32 bytes are divided into four banks of registers. • 16 bytes from locations 20 H to 2 FH are bit addressable memory. • 80 bytes from locations 30 H to 7 FH are scratch pad memory. This section is used for the purpose of storing data and parameters by the programmers. A. R. Hurson 31
Introduction to Micro Controllers & Embedded System Design • Memory organization Byte address 7 F General purpose RAM 30 2 F Bit addressable locations 20 1 F 18 17 10 0 F A. R. Hurson 08 07 00 Bank 3 Bank 2 Bank 1 Bank 0 32
Introduction to Micro Controllers & Embedded System Design Byte address 90 P 1 F 0 B E 0 ACC D 0 PSW B 8 IP B 0 P 3 A 8 IE A 0 P 2 DPH DDL SP 99 33 SBUF P 0 98 SCON 8 D TH 1 8 C TH 0 8 B TL 1 8 A TL 0 89 TMOD TCON PCON 88 87 83 82 81 80 A. R. Hurson FF
Introduction to Micro Controllers & Embedded System Design • Memory organization • Example: State the contents of RAM locations after execution of the following sequence of instructions. MOV MOV MOV R 0, #99 H R 1, #85 H R 2, #3 FH R 7, #63 H R 5, #12 H ; Load R 0 with value 99 H ; Load R 1 with value 85 H ; Load R 2 with value 3 FH ; Load R 7 with value 63 H ; Load R 5 with value 12 H RAM location 0 has value 99 H RAM location 1 has value 85 H RAM location 2 has value 3 FH RAM location 7 has value 63 H RAM location 5 has value 12 H A. R. Hurson 34
Introduction to Micro Controllers & Embedded System Design • Memory organization • Example: State the contents of RAM locations after execution of the following sequence of instructions. SETB MOV MOV MOV PSW, 4 R 0, #99 H R 1, #85 H R 2, #3 FH R 7, #63 H R 5, #12 H ; Select bank 2 ; Load R 0 with value 99 H ; Load R 1 with value 85 H ; Load R 2 with value 3 FH ; Load R 7 with value 63 H ; Load R 5 with value 12 H RAM location 10 has value 99 H RAM location 11 has value 85 H RAM location 12 has value 3 FH RAM location 17 has value 63 H RAM location 15 has value 12 H A. R. Hurson 35
Introduction to Micro Controllers & Embedded System Design • Bit addressable RAM • 8051 has 210 bit addressable locations, of which 128 are at byte addresses 20 H through 2 FH and the rest are the special function registers. • Bit addressability allows one to set, clear, perform AND, OR, … operations at bit level with a single instruction. This is a powerful feature, otherwise, bit processing should have been done as a sequence of read, modify, and write. Finally, I/O ports are bit addressable, as well. A. R. Hurson 36
Introduction to Micro Controllers & Embedded System Design • Bit addressable RAM • For example: SETB 67 H • sets bit 67 H, which is the most significant bit of “byte address 2 CH”. If bit addressability did not exist, one had to write the following code to accomplish the aforementioned task: MOV A, 2 CH ORL A, #10000000 B MOV 2 CH, A A. R. Hurson 37
Introduction to Micro Controllers & Embedded System Design • Register Banks are located at the lower 32 words of internal RAM memory. The instruction set of 8051 supports 8 registers R 0 through R 7 which are at addresses 00 H-07 H. A. R. Hurson 38
Introduction to Micro Controllers & Embedded System Design • Register Banks • Example MOV A, R 5 is a byte instruction using register addressing mode. • Similarly, we can perform the same operation using the following instruction: MOV A, 05 H which is a 2 byte instruction (since it is using a direct addressing) A. R. Hurson 39
Introduction to Micro Controllers & Embedded System Design • Register Banks • The active register bank can be altered by changing the register bank select bits in the program status word. • Example: Assuming register bank 3 is active then, MOV R 0, A Writes the content of accumulator into location 18 H. A. R. Hurson 40
Introduction to Micro Controllers & Embedded System Design • Special function registers • Internal registers can be implicitly accessed by instructions. • For example INC A increments the accumulator. • There are 21 special function registers located at address 80 H to FFH. • Most of the special function registers are accessed via direct addressing. A. R. Hurson 41
Introduction to Micro Controllers & Embedded System Design • Program Status Word is at address D 0 H and contains status bits as follows: Bit Symbol Address Semantic PSW. 7 CY D 7 H Carry flag PSW. 6 AC D 6 H Auxiliary carry flag PSW. 5 F 0 D 5 H Flag 0 PSW. 4 RS 1 D 4 H Register bank select 1 PSW. 3 RS 0 D 3 H Register bank select 0 PSW. 2 OV PSW. 1 A. R. Hurson PSW. 0 P 00 bank 0 00 H-07 H 01 bank 1 08 H-0 FH 10 bank 2 10 H-17 H 11 bank 3 18 H-1 FH D 2 H Overflow flag D 1 H Reserved D 0 H Even Parity flag 42
Introduction to Micro Controllers & Embedded System Design • Carry flag has a dual purpose: • It is used to hold the carry out (borrow out) for addition (subtraction) operation. • For example, if accumulator has the value FFH then ADD A, #1 sets the accumulator to 00 H and sets the carry flag in PSW. • It is also used as a “Boolean accumulator” • For example, ANL C, 25 H ANDs bit 25 H with the carry flag and places the result back in carry flag. A. R. Hurson 43
Introduction to Micro Controllers & Embedded System Design • Auxiliary carry flag is used when performing BCD operations. • Flag 0 is a general-purpose flag bit available for user application. A. R. Hurson 44
Introduction to Micro Controllers & Embedded System Design • Register Bank Select determines the active register bank. • For example: SETB RS 1 SETB RS 0 MOV A, R 7 makes register bank 3 active and moves contents of R 7 (at address 1 FH) to accumulator. A. R. Hurson 45
Introduction to Micro Controllers & Embedded System Design • Overflow flag is set after addition or subtraction operation, if there was an arithmetic overflow (underflow). • For example the following operation 0 F + 7 F = 8 E sets the OV bit. A. R. Hurson 46
Introduction to Micro Controllers & Embedded System Design • Parity bit is automatically set or cleared in each machine cycle to establish even parity of accumulator, i. e. , the number of 1 s in accumulator plus the P bit is always even. • For example is accumulator contains 10101101, P will be set to 1. A. R. Hurson 47
Introduction to Micro Controllers & Embedded System Design • Example Show the status of CY, AC, and P after the following operations: MOV A, #38 H ADD A, #2 FH CY = 0 AC = 1 P=1 A. R. Hurson + 38 2 F 00111000 00101111 67 01100111 ; Since there is no carry out ; Since there is a carry from D 3 to D 4 ; Since accumulator has five 1 s (an odd number of 1 s) 48
Introduction to Micro Controllers & Embedded System Design • Example Show the status of CY, AC, and P after the following operations: MOV A, #9 CH ADD A, #64 H 9 C + 64 100 CY = 1 AC = 1 P=0 A. R. Hurson 10011100 01100100 0000 ; Since there is a carry out ; Since there is a carry from D 3 to D 4 ; Since accumulator has 0 1 s (an even number of 1 s) 49
Introduction to Micro Controllers & Embedded System Design • Example Show the status of CY, AC, and P after the following operations: MOV A, #88 H ADD A, #93 H 88 + 93 11 B CY = 1 AC = 0 P=0 A. R. Hurson 1000 10010011 00011011 ; Since there is a carry out ; Since there is no carry from D 3 to D 4 ; Since accumulator has 4 1 s (an even number of 1 s) 50
Introduction to Micro Controllers & Embedded System Design • B register is a sort of accumulator at address F 0 H. It is used along with accumulator for multiply and divide operations. The MUL AB multiplies contents of A and B and stores the 16 bit result in A (low-byte) and B (highbyte). • The DIV AB divides A by B leaving the quotient in A and remainder in B. • B can be also treated as a general-purpose register. It is also bit addressable through bit addresses F 0 H to F 7 H. A. R. Hurson 51
Introduction to Micro Controllers & Embedded System Design • Stack pointer is an 8 -bit register at address 81 H. It contains the address of data item currently on top of stack. The default value (i. e. , when the 8051 is powered up) for stack pointer is 07 H. This means that RAM location o 8 is the first location used by the stack. • • Stack operations are Push and Pop. • The stack in 8051 is kept in internal RAM (the first 128 bytes of onchip RAM) and is limited to addresses accessible by indirect addressing. Pushing an item to stack increments SP before writing the data and popping from stack reads data and then decrements SP. A. R. Hurson 52
Introduction to Micro Controllers & Embedded System Design • Example: • Initializing the SP with the stack beginning at 60 H we have: MOV SP, #5 FH (say why? ) Note to push an element into stack, stack pointer is incremented first) • This limits the stack to 32 bytes (say why? ) A. R. Hurson 53
Introduction to Micro Controllers & Embedded System Design • Example: • Show the snap shots of the stack and stack pointer after execution of the following instructions : A. R. Hurson MOV MOV PUSH R 6, #25 H R 1, #12 H R 4, #0 F 3 H 6 1 4 54
Introduction to Micro Controllers & Embedded System Design MOV MOV PUSH 6 0 B 0 A 09 08 Start SP=07 A. R. Hurson 0 B 0 A 09 08 25 SP=08 R 6, #25 H R 1, #12 H R 4, #0 F 3 H 6 1 4 PUSH 1 0 B 0 A 09 08 12 25 SP=09 PUSH 4 0 B 0 A 09 08 F 3 12 25 SP=0 A 55
Introduction to Micro Controllers & Embedded System Design • Example: • Show the snap shots of the stack and stack pointer after execution of the following instructions: A. R. Hurson POP POP 3 5 2 ; Pop stack into R 3 ; Pop stack into R 5 ; Pop stack into R 2 56
Introduction to Micro Controllers & Embedded System Design POP POP 3 5 2 ; Pop stack into R 3 ; Pop stack into R 5 ; Pop stack into R 2 Initial Configuration POP 3 POP 5 POP 2 0 B 0 A 09 08 54 F 9 76 6 C SP=0 B A. R. Hurson 0 B 0 A 09 08 F 9 76 6 C SP=0 A 0 B 0 A 09 08 76 6 C SP=09 0 B 0 A 09 08 6 C SP=08 57
Introduction to Micro Controllers & Embedded System Design • Note: Locations 08 to 1 FH can be used for the stack. If in a program, we need more than 24 bytes of stack, then we need to set the stack pointer to point to any locations of 30 to 7 FH. A. R. Hurson 58
Introduction to Micro Controllers & Embedded System Design • Example: • Show the snap shots of the stack and stack pointer after execution of the following instructions : MOV SP, #5 FH MOV MOV PUSH A. R. Hurson ; Make RAM location 60 H ; the first stack location R 2, #25 H R 1, #12 H R 4, #0 F 3 H 6 1 4 59
Introduction to Micro Controllers & Embedded System Design MOV SP, #5 FH MOV MOV PUSH R 2, #25 H R 1, #12 H R 4, #0 F 3 H 6 1 4 PUSH 2 63 62 61 60 Start SP=5 F A. R. Hurson 63 62 61 60 25 SP=60 ; Make RAM location 60 H ; the first stack location PUSH 1 63 62 61 60 12 25 SP=61 PUSH 4 63 62 61 60 F 3 12 25 SP=62 60
Introduction to Micro Controllers & Embedded System Design • Data pointer is used to access external code or external data memory. It is 16 -bit register at addresses 82 H (DPL-low byte) and 83 H (DPHhigh point). • For example MOV A, #55 H MOV DPTR, #1000 H MOVX @DPTR, A Writes 55 H into external RAM at location 1000 H. A. R. Hurson 61
Introduction to Micro Controllers & Embedded System Design • Port registers: In 8051 I/O ports consists of port 0 at address 80 H, port 1 at address 90 H, port 2 at address A 0 H, and port 3 at address B 0 H. Ports 0, 2, and 4 may not be available for I/O if external memory is used. • Note: p 1. 2 to p 1. 7 are always available as general purpose I/O lines. A. R. Hurson 62
Introduction to Micro Controllers & Embedded System Design • All ports are bit addressable which provides a powerful interfacing possibilities (it could be turned on and off using a single instruction). • For example, if a motor is connected to port 1 bit 7 SETB P 1. 7 might turn the motor on and CLR P 1. 7 might turn it off. A. R. Hurson 63
Introduction to Micro Controllers & Embedded System Design • The aforementioned instructions use “dot operator” to address a bit within a bit addressable byte location. The assembler performs the necessary conversion. • The following two instructions are equivalent: CLR P 1. 7 CLR 97 H A. R. Hurson 64
Introduction to Micro Controllers & Embedded System Design • For example: Consider the interface to a device with a status bit called BUSY, which is set when the device is busy and clear when it is ready. If BUSY is connected to say port 1 bit 5, then the following loop could be used to wait for the device to become ready: WAIT: JB P 1. 5, WAIT A. R. Hurson 65
Introduction to Micro Controllers & Embedded System Design • Timer registers: 8051 has two 16 -bit Timer/counters for timing intervals or counting events. Timer 0 is at address 8 AH (TL 0, low-byte) and 8 CH (TL 0, highbyte), and timer 1 is at address 8 BH (TL 1, low-byte) and 8 DH (TL 1, high-byte). • Time operation is set by the timer mode register (TMOD) at address 89 H and timer control register (TCON) at address 88 H. • Note, only TCON is bit-addressable. A. R. Hurson 66
Introduction to Micro Controllers & Embedded System Design • Serial port register: 8051 contains an on-chip serial port for communication with serial devices. One register, the serial data buffer (SBUF) at address 99 H holds both the transmit and receive data. A. R. Hurson 67
Introduction to Micro Controllers & Embedded System Design • Interrupt register: 8051 has a 5 -source, 2 priority level interrupt structure. Interrupts are disabled after a system reset and then enabled by writing to the interrupt enable register (IE) at address A 8 H. The priority level is set through the interrupt priority register (IP) at address B 8 H. • Both registers are bit-addressable. A. R. Hurson 68
Introduction to Micro Controllers & Embedded System Design • Power Control Register at address 87 H contains different control bits as follows BIT Symbol Semantic 7 SMOD Double baud rate bit 6 Undefined 5 Undefined 4 Undefined 3 GF 1 General-Purpose flag bit 1 2 GF 0 General-Purpose flag bit 0 1 PD Power down, set to active power down mode 0 IDL Idle mode, set to activate idle mode A. R. Hurson 69
Introduction to Micro Controllers & Embedded System Design • External Memory • When external memory is used port 0 is unavailable as an I/O port. It becomes a multiplexed address (A 0 -A 7) and data (D 0 -D 7) bus with ALE latching the low-byte of the address at the beginning of each external memory cycle. Port 2 is usually (but not always) employed for the high-byte of the address bus. A. R. Hurson 70
Introduction to Micro Controllers & Embedded System Design • Accessing External Code Memory PSEN • External ROM is enabled by the signal. When an external EPROM is used, both ports 0 and 2 are unavailable as general purpose I/O ports. A. R. Hurson 71
Introduction to Micro Controllers & Embedded System Design • Accessing External Code Memory D 0 -D 7 Port 0 EA 8051 ALE Port 2 PSEN A. R. Hurson Latch A 0 -A 7 EPROM A 8 -A 15 OE 72
Introduction to Micro Controllers & Embedded System Design • Accessing External Code Memory • During first half of memory cycle. The low-byte of the address is provided on port 0 and is latched using ALE. • During the second half of the memory cycle, port 0 is used as the data bus and data is read or written depending on the operation. A. R. Hurson 73
Introduction to Micro Controllers & Embedded System Design • Accessing External Code Memory • 8051 machine cycle is 12 oscillator periods. If the on- chip oscillator is driven by a 12 MHz crystal, a machine cycle is 1 s. During a typical machine cycle ALE pulses twice and 2 bytes are read from program memory (if the current instruction is a 1 -byte instruction, the 2 nd byte is discarded). A. R. Hurson 74
Introduction to Micro Controllers & Embedded System Design • A. R. Hurson 75
Introduction to Micro Controllers & Embedded System Design • Accessing External Data Memory D 0 -D 7 Port 0 EA +5 V Latch 8051 ALE A 0 -A 7 1 K RAM P 2. 0 P 2. 1 A 8 RD WR OE W PSEN A. R. Hurson A 7 (no connection) CS 76
Introduction to Micro Controllers & Embedded System Design • Accessing External Data Memory • Port 2 is relieved of its alternate function in minimum component systems (configurations that do not use external code memory and only a small amount of external data memory). • 8 -bit address can access 256 -byte page of RAM. If more than one page of RAM is used, then a few bits from port 2 can be used to select a page. A. R. Hurson 77
Introduction to Micro Controllers & Embedded System Design • Example • Assume port 2 bits 0 and 1 are initialized to select a page, the following two instructions reads the contents of the external RAM at address 0050 H into the accumulator: MOV R 0, #50 H MOV A, @R 0 A. R. Hurson 78
Introduction to Micro Controllers & Embedded System Design • Example • Assume port 2 bits 0 and 1 are initialized to select a page, the following instructions reads the last address (03 FFH) of the external RAM: SETB P 2. 0 SETB P 2. 1 MOV R 0, #0 FFH MOV A, @R 0 A. R. Hurson 79
Introduction to Micro Controllers & Embedded System Design • Some 8 -bit registers A R 0 B R 1 R 2 R 3 R 4 R 5 R 6 R 7 A. R. Hurson 80
Introduction to Micro Controllers & Embedded System Design • Some 16 -bit registers DPTR Program Counter A. R. Hurson DPH DPL PC 81
- Slides: 81