1
Microcontrollers
Class : 4th Semister E&C and EEESubject Code: 06ES42Chapter : UNIT 1-2Class : 2
Date : 15th Feb 2010
D R Subramanyam [email protected]
Revision of Previous ClassMicroprocessor
Microcontroller
Difference between MP and MC
MC Architecture
RISC
CISC
Harvard
Von Newmann
4
Microprocessors “A microprocessor is a multipurpose, programmable, clock
driven, register – based electronics device that reads binary instructions from a storage device called memory, accepts binary data as input and processes data according to those instructions and provides results as output”
• Example : Intel’s x86, Motorola’s 680x0
CPU
General-Purpose Micro-processor
RAM ROM I/O Port
TimerSerial COM Port
Data Bus
Address Bus
General-Purpose Microprocessor System
Many chips on mother’s board
5
Microcontroller:
• A smaller computer• On-chip RAM, ROM, I/O ports...• Example : Motorola’s 6811, Intel’s 8051, Zilog’s Z8X and PIC 16X
RAM ROM
I/O Port
TimerSerial COM Port
Microcontroller
CPU
A single chip
6
Microprocessor vs Microcontroller
Microprocessor
• CPU is stand-alone, RAM, ROM, I/O, timer are separate
• designer can decide on the amount of ROM, RAM and I/O ports.
• expensive• versatility • general-purpose
Microcontroller
• CPU, RAM, ROM, I/O and timer are all on a single chip
• fix amount of on-chip ROM, RAM, I/O ports
• for applications in which cost, power and space are critical
• single-purpose
8
CISC (Complex Instruction Set Computing Processors)
• Numerous Instruction Group• Numerous Addressing Modes• Microcoded Instructions• Microcontrollers and Microprocessors are
CISC based.• DSP’s are closer to RISC.
12
Microcontroller’s internal Blocks
• CPU ( ALU, Registers, Oscillator/clock, Bus control)• RAM /Data memory• ROM / program memory• I/O ports• Timer/counters• Serial ports• Interrupts
Microcontroller Block Diagram
CPU
On-chip RAM
On-chip ROM for program code
4 I/O Ports
Timer 0
Serial PortOSC
Interrupt Control
External interrupts
Timer 1
Timer/Counter
Bus Control
TxD RxDP0 P1 P2 P3
Address/Data
Counter Inputs
15
Microcontroller Block Diagram
ALU
Internal ROM
I/O Ports
Internal RAM
AccumulatorRegisters
Program CounterStack Pointer
Oscillator
Counter/Timer
Serial Port
Interrupt Logic
Bus Control
Program Counter and Data pointer
Program Counter (PC):
Program counter is a 16 bit Register. It holds the address of the next instruction to be executed.
It does not have internal address (PC is the only register not having the internal address)
Data Pointer (DPTR): DPH and DPL
DPTR is used to furnish memory address for internal and external code access and external data access
A and B CPU Registers
• A and B registers are the two registers among the 34 general purpose registers
• Holds results of many instructions, particularly math and logical operations
• A register (Accumulator) is the most versatile and is used for many operations including addition, subtraction, integer multiplication and division and Boolean bit manipulations
• A register is also used for all data transfer between 8051 and any external memory
• B register is used with A register for multiplication and division operations.
The Stack and Stack pointer(SP)Stack area:Part of Internal RAMIt is limited in height to the size of internal RAM
Stack Pointer (SP): 8 bits wideIncrements unlike many microprocessors where SP decrementsOn RESET it is et to 07H
A Pin of Port 1
8051 IC
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
TB1
TB2
P0.x
Writing “1” to Output Pin P1.X
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
8051 IC
2. output pin is Vcc1. write a 1 to the pin
1
0 output 1
TB1
TB2
Writing “0” to Output Pin P1.X
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pinP1.X
8051 IC
2. output pin is ground1. write a 0 to the pin
0
1 output 0
TB1
TB2
Reading “High” at Input Pin
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pin
P1.X
8051 IC
2. MOV A,P1
external pin=High1. write a 1 to the pin MOV
P1,#0FFH
1
0
3. Read pin=1 Read latch=0 Write to latch=1
1
TB1
TB2
Reading “Low” at Input Pin
D Q
Clk Q
Vcc
Load(L1)
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P1.X pin
P1.X
8051 IC
2. MOV A,P1
external pin=Low1. write a 1 to the pin
MOV P1,#0FFH
1
0
3. Read pin=1 Read latch=0 Write to latch=1
0
TB1
TB2
Other Pins
• P1, P2, and P3 have internal pull-up resisters.– P1, P2, and P3 are not open drain.
• P0 has no internal pull-up resistors and does not connects to Vcc inside the 8051.– P0 is open drain.– Compare the figures of P1.X and P0.X.
• However, for a programmer, it is the same to program P0, P1, P2 and P3.
• All the ports upon RESET are configured as output.
A Pin of Port 0
8051 IC
D Q
Clk Q
Read latch
Read pin
Write to latch
Internal CPU bus
M1
P0.X pinP1.X
TB1
TB2
P1.x
Timer Mode 1
16 Bit Timer / counterTMOD = 01bThe Timer Flag would be set in 1311 seconds using a 6 MHz Crystal
Serial Data Input/Output
Registers used for Serial CommunicationSBUF-Serial Buffer registerSCON-Serial Control registerPCON-Power Control register
Serial Communication Continued
Serial InterruptsData Transmission Data Reception
Baud rate is set using Timer 1Whenever serial port is used in Mode 1 or 3 Timer 1 can not be used for any other purpose other than generating Baud clock
Interrupts
1. Enabling and Disabling Interrupts
2. Interrupt Priority
3. Writing the ISR (Interrupt Service Routine)
Interrupt VectorsInterrupt Vector Address
System Reset 0000H
External 0 0003H
Timer 0 000BH
External 1 0013H
Timer 1 001BH
Serial Port 0023H
Timer 2 002BH