Microcontroller Electronics Engineering Sem 4MODULE 1.pptx
itsmeaswin03
38 views
52 slides
May 17, 2024
Slide 1 of 52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
About This Presentation
Microcontroller for Electronics Engineering
Size: 1.51 MB
Language: en
Added: May 17, 2024
Slides: 52 pages
Slide Content
MICROCONTROLLER AND INTERFACING MODULE I
MICROPROCESSOR It is the Central Processing Unit (CPU) of a general purpose microcomputer. It contains an Arithmetic and Logic Unit(ALU), a Program Counter(PC),a Stack Pointer(SP), a few working registers, a clock timing circuit and interrupt circuits. It doesn’t contain RAM, ROM,I/O ports, Timers etc on the chip and hence called General Purpose CPU’s.
Contd.. A system designer using a general purpose microprocessor must add the RAM, ROM, I/O ports, and timers externally to make them functional. Although the external RAM, ROM, I/O ports makes these systems bulkier and much more expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM, and I/O ports needed to fit the task at hand.
Block diagram of a microprocessor
microcontroller A microcontroller has a CPU (microprocessor) in addition to a fixed amount of ROM,RAM,I/O ports and timer all are embedded together on single chip. Therefore the designer cannot add any external memory ,I/O or timer to it. The fixed amount of on-chip RAM, ROM, and the number of I/O ports makes them ideal for many applications in which the cost and space are critical.
CONTD..
Block diagram of 8051
Contd.. Central Processor Unit (CPU) is the brain of any processing device of the microcontroller. It monitors and controls all operations that are performed on the Microcontroller units. The User has no control over the work of the CPU directly . It reads program written in ROM memory and executes them and do the expected task of that application.
Contd.. Interrupts It is a subroutine call that interrupts the microcontroller’s main operations or work and causes it to execute any other program, which is more important at the time of operation. . An Interrupts gives us a mechanism to put on hold the ongoing operations, execute a subroutine and then again resumes to another type of operations.
Contd.. Five interrupt sources are there in 8051 Microcontroller. There are 5 vectored interrupts are shown in below INTO TFO INT1 TF1 R1/T1
Contd.. Memory Microcontroller requires a program which is a collection of instructions. This program tells microcontroller to do specific tasks. These programs require a memory on which these can be saved and read by Microcontroller to perform specific operations of a particular task. The memory which is used to store the program of microcontroller is known as code memory or Program memory of applications .
Contd.. It is known as ROM memory of microcontroller It also requires a memory to store data or operands temporarily of the micro controller. The data memory of the 8051 is used to store data temporarily for operation is known RAM memory. 8051 microcontroller has 4K of code memory or program memory( 4KB ROM) and also 128 bytes of data memory or RAM.
Contd.. BUS Basically Bus is a collection of wires which work as a communication channel or medium for transfer of Data. There two types of buses that are shown in below Address Bus Data Bus
Contd.. Address Bus : Microcontroller 8051 has a 16 bit address bus . It is used to address memory locations and to transfer the address from CPU to Memory of the microcontroller. Data Bus : Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of particular applications.
Contd.. Oscillator The microcontroller requires clock pulses for its operation . For this purpose, microcontroller 8051 has an on-chip oscillator which works as a clock source for Central Processing Unit of the microcontroller.
Contd.. Input/Output Port The microcontroller 8051 has 4 input, output ports to connect it to the other peripherals
Contd.. Timers/Counters 8051 microcontroller has two 16 bit timers and counters. These counters are again divided into a 8 bit register. The timers are used for measurement of intervals to determine the pulse width of pulses .
The salient features of 8051 Microcontroller i . 4 KB on chip program memory (ROM or EPROM)). ii. 128 bytes on chip data memory(RAM). iii. 8-bit data bus iv. 16-bit address bus v. 32 general purpose registers each of 8 bits vi. Two -16 bit timers T0 and T1 vii. Five Interrupts (3 internal and 2 external). ix. Four Parallel ports each of 8-bits (PORT0, PORT1,PORT2,PORT3) with a total of 32 I/O lines. x. One 16-bit program counter and One 16-bit DPTR ( data pointer) xi. One 8-bit stack pointer xii. One Microsecond instruction cycle with 12 MHz Crystal. xiii. One full duplex serial communication port.
Architecture of 8051
22
A and B registers 8051 contain 34 general purpose registers. Two of these, namely A and B registers hold results of many mathematical and logical instructions, and therefore can be considered as a part of ALU. The other 32 registers are arranged as a part of internal RAM. A or accumulator register is the most versatile of the CPU registers and is used for operations like addition, subtraction, multiplication, division and almost all boolean logical operations. A-register is also used for all data transfers between 8051 and any external memory. B-register is used with A register for multiplication and division operation 23
PC and DPTR PC or program counter is a 16-bit register that stores the address of memory location from which the instruction bytes are to next fetched PC is automatically incremented after every byte is fetched. PC does not have any internal address. DPTR or data pointer is made up of two 8-bit registers namely DPH and DPL which are used to furnish memory addresses for internal and external data access. 24
PSW (PROGRAM STATUS WORD) OR FLAG REGISTER
CY[Carry or Borrow Bit] = 1 indicates a CARRY has occurred out of higher order nibble of accumulator or borrow has occurred into higher order nibble of accumulator. AC[Auxiliary Carry or Borrow Bit] = 1 indicates a CARRY has occurred out of lower order nibble of accumulator or borrow has occurred into lower order nibble of accumulator F0 – General Purpose User Definable Flag
OV[Overflow or Sign] bit = 1 , Indicates the result in the accumulator is a negative number in case of signed addition and the result has exceeded the capacity of accumulator in case of unsigned addition. P[Parity] bit = 1 , indicates the result in the accumulator has ODD PARITY.
Intel 8051 Microcontroller Architecture 28 Internal Ram (data memory) 128 bytes of internal RAM is organised into 3 distinct areas : 32 bytes ranging from addresses 00H to 1FH that make up 32 working registers (each of 8 bits) organised as 4 banks (bank0, bank1, bank2 & bank3) of 8 registers namely R0, R1, R2…. R7 Bits RS0, RS1 of PSW register determine which registers are currently in use. By default, register bank is used. ●
Internal Ram (data memory) 128 bytes of internal RAM is organised into 3 distinct areas: A bit addressable area of 16 bytes occupies RAM addresses ranging from 20 to 2Fh, forming a total of 128 addressable bits. Individual bits of a memory location can be manipulated 80 bytes of general purpose area ranging from 30h to 7FH used for read/write storage and is normally called as SCRATCHPAD 12
12
SFRs 8051 has a group of specific internal registers (21nos) each called Special Function Registers (SFR) and occupy another 128 bytes of memory (80 to FF) . All operations that do not use 128 bytes (00h to 7Fh) of internal RAM are done by SFRs. SFR include A-register, B-register, DPH, DPL, IE, IP, P0,P1,P2,P3, PCON, PSW, SCON, SBUF, SP, TMOD, TCON, TL0, TL1, TH0, TH1
Intel 8051 Microcontroller Architecture Special Function Registers of 8051 32
Stack & Stack Pointer Stack is an area of internal RAM that is used in conjunction with certain opcodes to store and retrieve data quickly. 8 bit Stack Pointer (SP) is used by 8051 to hold an internal RAM address which is called the top of the Stack and is the address where last byte of data is stored. When data is to be placed on the stack SP is incremented just before the data is stored on stack, so that the stack grows upwards. As the data is retrieved from the stack, SP d ecrements after the retrieval of data. The size of stack is limited to the size of internal RAM. 15
Intel 8051 Microcontroller Architecture 34 Internal ROM (program memory) 8051 has 4KB of on-chip ROM (2 2 x2 10 bytes) This is used for storing system program and has addresses ranging from 000h to FFFh (0 to 4095). Program addresses higher than 0FFFh, that is those exceeding internal ROM capacity will cause 8051 to automatically fetch code bytes from external program memory . Fetching from external memory is enabled by keeping EA pin External Access pin) of 8051 to ground.
I/O PORTS : There are totally four 8-bit I/O Ports namely PORT 0 , PORT 1 , PORT 2 , PORT 3. Three out of four ports namely PORT 0 , 2 and 3 are multifunctional PORTS
COMPARISON BETWEEN 8051 FAMILY MEMBERS
PROGRAM MEMORY (ROM) OF 8051 MICROCONTROLLER In 8051 Microcontroller, the code or instructions to be executed are stored in the Program Memory, which is also called as the ROM of the Microcontroller. The original 8051 Microcontroller by Intel has 4KB of internal ROM. In case of 4KB of Internal ROM, the address space is 0000H to 0FFFH. If the address space i.e. the program addresses exceed this value, then the CPU will automatically fetch the code from the external Program Memory.
CONTD..
CONTD.. when the EA Pin is high, the CPU first fetches instructions from the Internal Program Memory in the address range of 0000H to 0FFFFH and if the memory addresses exceed the limit, then the instructions are fetched from the external ROM in the address range of 1000H to FFFFH .
CONTD.. There is another way to fetch the instructions: ignore the Internal ROM and fetch all the instructions only from the External Program Memory (External ROM). For this, the EA Pin must be connected to GND. In this case, the memory addresses of the external ROM will be from 0000H to FFFFH.
CONTD..
DATA MEMORY OF 8051
CONTD.. The Data Memory or RAM of the 8051 Microcontroller stores temporary data and intermediate results that are generated and used during the normal operation of the microcontroller. Original Intel’s 8051 Microcontroller had 128B of internal RAM. But almost all modern variants of 8051 Microcontroller have 256B of RAM.
CONTD.. In this 256B, the first 128B i.e. memory addresses from 00H to 7FH is divided in to Working Registers (organized as Register Banks), Bit – Addressable Area and General Purpose RAM (also known as Scratchpad area). In the first 128B of RAM (from 00H to 7FH), the first 32B i.e. memory from addresses 00H to 1FH consists of 32 Working Registers that are organized as four banks with 8 Registers in each Bank.
CONTD.. The 4 banks are named as Bank0, Bank1, Bank2 and Bank3. Each Bank consists of 8 registers named as R0 – R7. Each Register can be addressed in two ways: either by name or by address. To address the register by name, first the corresponding Bank must be selected. In order to select the bank, we have to use the RS0 and RS1 bits of the Program Status Word (PSW) Register (RS0 and RS1 are 3 rd and 4 th bits in the PSW Register).
CONTD.. The next 16B of the RAM i.e. from 20H to 2FH are Bit – Addressable memory locations. There are totally 128 bits that can be addressed individually using 00H to 7FH or the entire byte can be addressed as 20H to 2FH. The final 80B of the internal RAM i.e. addresses from 30H to 7FH, is the general purpose RAM area which are byte addressable. These lower 128B of RAM can be addressed directly or indirectly .
CONTD.. The upper 128B of the RAM i.e. memory addresses from 80H to FFH is allocated for Special Function Registers (SFRs). SFRs control specific functions of the 8051 Microcontroller. Some of the SFRs are I/O Port Registers (P0, P1, P2 and P3), PSW (Program Status Word), A (Accumulator), IE (Interrupt Enable), PCON (Power Control), etc. SRFs Memory addresses are only direct addressable.
8051 PIN FUNCTIONS 48
Pins 1 – 8 (PORT 1): Pins 1 to 8 are the PORT 1 Pins of 8051. PORT 1 Pins consists of 8 – bit bidirectional Input / Output Port with internal pull – up resistors Pin 9 (RST): Pin 9 is the Reset Input Pin. It is an active HIGH Pin i.e. if the RST Pin is HIGH for a minimum of two machine cycles, the microcontroller will be reset. It will reset PC register to 0000h. Pins 10 – 17 (PORT 3): Pins 10 to 17 form the PORT 3 pins of the 8051 Microcontroller. PORT 3 also acts as a bidirectional Input / Output PORT with internal pull-ups. Additionally, all the PORT 3 Pins have special functions 49
Pins 18 & 19: Pins 18 and 19 i.e. XTAL 2 and XTAL 1 are the pins for connecting external oscillator. Generally, a Quartz Crystal Oscillator is connected here Pin 20 (GND): Pin 20 is the Ground Pin of the 8051 Microcontroller. It represents 0V and is connected to the negative terminal (0V) of the Power Supply. Pins 21 – 28 (PORT 2): These are the PORT 2 Pins of the 8051 Microcontroller. PORT 2 is also a Bidirectional Port i.e. all the PORT 2 pins act as Input or Output. Additionally, when external memory is interfaced, PORT 2 pins act as the higher order address byte 50
Pin 29 (PSEN): Pin 29 is the Program Store Enable Pin (PSEN). Using this pins, external Program Memory can be read. Pin 30 (ALE/PROG): Pin 30 is the Address Latch Enable Pin. It is an active high pin. ALE indicates if port0 provides address or data. ALE=0 indicates port0 provides data and if 1 port0 provides address. Pin 31 (EA/VPP): Pin 31 is the External Access Enable Pin i.e. allows external Program Memory. Code from external program memory can be fetched only if this pin is LOW. For normal operations, this pins is pulled HIGH. 51
Pins 32 – 39 (PORT 0): Pins 32 to 39 are PORT Pins. They are also bidirectional Input / Output Pins but without any internal pull-ups. Hence, we need external pull-ups in order to use PORT pins as I/O PORT. In addition to acting as I/O PORT, PORT also acts as lower order address/data bus when external memory is accessed. Pin 40 (VCC): Pin 40 is the power supply pin to which the supply voltage is given (+5V). 52