0% found this document useful (0 votes)
11 views

SY Microcontroller Unit 1 Notes-1

Uploaded by

Abhishek Kapse
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

SY Microcontroller Unit 1 Notes-1

Uploaded by

Abhishek Kapse
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 86

Shri Saibaba Sansthan Trust’s

Shri Saibaba College,


Shirdi

WEL COME
For
Learning academic subjects through
Digital platform
Microcontroller architecture &
programming
By

Prof. M. G. Kundhare
Assistant Professor (SET,NET)
Electronics Science
Structure of S.Y.B.Sc. (Computer Science)
Electronics
S.Y.B.Sc. (Computer Science)
Electronics

Semester III
Paper I (ELC – 231)

Microcontroller Architecture
& Programming
(2 Credits)

Note- All the images are taken from the internet


Microcontroller Architecture &
Programming

Syllabus:-

UNIT- 1: Basics of Microcontroller & Intel 8051 architecture [08]


Introduction to microcontrollers, difference in controller and processor.Architecture
of 8051, Internal block diagram, Internal RAM organization, SFRS, pin functionsof 8051,
I/O port structure & Operation, External Memory Interface.

UNIT-2: Programming model of 8051 [10]


Instruction classification, Instruction set, Addressing Modes: Immediate, register,
direct,indirect and relative, assembler directives (ORG, END), features with examples,
I/O Bit &Byte programming using assembly language for LED and seven segment display
(SSD)
Interfacing. Introduction to 8051 programming in C.
Microcontroller Architecture &
Programming

Syllabus:-

UNIT- 3: Timer /Counter, Interrupts [10]


Timer / counter: TMOD, TCON, SCON, SBUF, PCON Registers, Timer modes,
programming for time delay using mode 1 and mode 2.
Interrupts: Introduction to interrupt, Interrupt types and their vector addresses,
Interrupt enable register and interrupt priority register (IE, IP)

UNIT- 4: Interfacing, Serial Communication [08]


Programming of serial port without interrupt, Serial Communication: Synchronous
and asynchronous serial communication, Use of timer to select baud rate for serial
communication.
Interfacing : ADC, DAC, LCD, stepper motor.
Unit 1...
Basics of Microcontroller & Intel 8051
Architecture
Microprocessors &
Microcontrollers

Introduction to Microprocessor:-

●Microprocessor is a general purpose Central


Processing Unit(CPU) of a digital computer.
●It is also called as Heart of the Computer System.
●A microprocessor consists of an ALU, Control unit
and Register array.
Microprocessor Block Diagram

OR
Dia.2 :-up Block Diagram
2

Dia.1 :-up Block Diagram


1
Introduction to Microcontroller

●Microcontroller is simply described as the


“Computer on Chip”,because it contains all the
features of full computer including Central
Processing Unit (CPU) , inbuilt clock
circuitry,ROM,RAM,input and output ports with
special features such as serial
communication,analog to digital conversion and
more recently signal processing.
●It is also called as Minicomputer.
●Generally it is the Heart of the Embedded system.
●Microcontroller can be used for the measurment
and control applications in industry as well as in
specific application.
Microcontroller Block Diagram :-

Dia. 3:- Basic Block diagram of Microcontroller


Difference Between
Microprocessor & Microcontroller
Microprocessor Microcontroller
∙Microprocessor is heart of ∙Microcontroller (Minicomputer) is
computer system. heart of embedded system.
∙Block diagram:- ∙Block diagram:-

∙It consists of only Central ∙It consists of the total circuitery of


Processing Unit (CPU). microprocessor (CPU) as well as the
It has no RAM,ROM,I/O inbuild RAM,ROM,I/O
port,Timer, Serial port on chip.They port,Timer/Counter, Serial port etc.
have to be connected externally.
Microprocessor Microcontroller
∙Since memory and I/O are ∙Since memory and I/O are
externally connected ,the circuit inbuilt , the circuit is small.
becomes large.

∙Cost of entire system is more. ∙Cost of entire system is less.


∙Due to external components, the ∙Since external components are
entire power consumption is High. low,the power consumption is Less.

∙Most of the microprocessors do ∙Most of the microcontroller have


not have power saving features. the power saving modes like idle
mode and power saving mode.

∙Since memory and I/O ∙Since memory and I/O


components are all external,each components are inbuild,most of the
instruction need extenal operations are internal
operation,hence its operating speed operation,hence its operating speed
is relatively slow. is relatively high.

∙Mainly used in large applications ∙Mainly used in small applications


like personal computers,laptops etc. like washing machines,MP3
players,stand alone systems etc.
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

1)
Difference between microprocessor &
microcontroller
Introduction to Intel 8051
microcontroller

• In 1981 ,Intel corporation,USA introduced an 8 -


bit Microcontroller called the 8051.

• Intel refers to it as MCS-51.

• The other members of this family are mainly 8031


& 8052.
The 8051 Microcontroller

Features of 8051 Microcontroller:-

• It is an 8 - bit microcontroller i.e. It has 8-bit CPU


• 8 - bit data bus and 16- bit address bus
• 4 k bytes of on-chip program memory (ROM)
• 128 bytes of on-chip RAM
• It has 4 input / output (8 bit) ports which contains 32 bi-directional
I/O lines
• Two 16-bit timer/counter (Timer 0 & Timer 1)
• Total 5 interrupt sources.(Two external interrupts,INT0 & INT1 and
Three internal interrupts,TF0,TF1 &RI/TI)
• It has on chip clock oscillator
• It has one serial port which provides full duplex UART mode
Block diagram of 8051 microcontroller
Block diagram of 8051
microcontroller Architecture
The basic architecture of
8051 uC can be divided into
seven parts :-

1. Processing unit
2. Register set
3. Memory units
4. I/O ports & serial port
5. Interrupt structures
6. Timing and control unit
7. Timers
The 8051 uC architecture consists of
following specific features:-
• 8 - bit CPU with register A
(Accumulator) & register B.
• 16 – bit Program Counter (PC) & Data
Pointer (DPTR) register
• 8 – bit Program Status Word (PSW)
register
• 8 – bit Stack Pointer (SP) register
• Internal ROM of 4 k bytes.
• Internal RAM of 128 bytes.
This RAM is divided into three parts as
i) 32 bytes in 4 Register banks
(R0,R1,R2 &R3) ,each containing 8
registers.
ii) 16 bytes which are bit addressable.
iii) 80 bytes of general purpose data
memory.
The 8051 uC architecture consists of
following specific features:-
• Four 8 – bit ports (P0,P1,P2 & P3)
which contains 32 input/output pins.
• Two 16 – bit timers/counters (T0 & T1)
• Full duplex serial data transmitter/
receiver
• Various Special Function Registers
(SFRs) such as IE, IP, PCON, SBUF,
SCON, TCON, TMOD, TL0, TH0, TL1
& TH1.
• Two external & three internal intuerrept
sources.
• Oscillator and Clock circuits.
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

2)
Features & Block diagram of 8051
microcontroller
Pin diagram of 8051
microcontroller
Pin diagram of 8051
microcontroller
• The pin diagram of 8051 uC IC is
available in 40 pin DIP package.
• In 8051 uC out of 40 pins, 32 pins are
set aside for the four ports P0,P1,P2 &
P3 where each port has 8 pins.
• The rest of the pins are designated as --
Vcc, Ground, XTAL1, XTAL2, RST,
EA,ALE and PSEN.
• These pins must be connected in order
to work the system properly.
• Some pins are used for more than one
function hence these pins are also
called as the multifunction pins.
Pin diagram of 8051
microcontroller
The function of each pin is described
below:-

Vcc (Pin 40):-


• It provides supply voltage to the uC
chip.
• The voltage source is +5 V.

GND (Pin 20):-


• It is the ground pin.
Pin diagram of 8051
microcontroller
XTAL 1 (Pin 19) & XTAL 2 (Pin 18):-
• The 8051 has an On-chip oscillator, But it
requires an external quartz crystal to be
connected to inputs XTAL 1 & XTAL 2
along with capacitors.

• When the internal clock generator facility is


not required,the user can connect external
clock to XTAL 1 input with XTAL 2 pin left
unconnected.
• We can observ the clock frequency on
XTAL2 pin using the oscilloscope.
Pin diagram of 8051
microcontroller
RST (Pin 9) :-

• It is the RESET pin.


• Normally it connected to LOW (Ground /
Logic 0).
• Upon applying HIGH (Vcc /Logic 1) pulse
to this pin, the controller will reset and
terminates all the activities.
• This is also called as power-on reset and is
used for initialization of the system.
• After RESET pin is activated all the values in
the 8051 SFR’s lost and have value 0000 H.
• Except the Stack Pointer (SP) reset to the
value 0007 H.
Pin diagram of 8051
microcontroller
EA (Pin 31) :-

• It is the External Access input pin


and is active LOW pin.
• It must be connected to either Vcc or
GND ;it can not be left unconnected.
• The 8051 uC has on-chip ROM, hence
EA pin is connected to Vcc.
• In some microcontrollers like 8031,
there is no on-chip ROM, hence it
requires external memory interfaced to
it.
• In the case of external memory
interfacing the EA pin is connected to
ground.
Pin diagram of 8051
microcontroller
ALE(Pin 30) :-
• The ALE stands for Address Latch Enable.

• When 8051 uC is connected with the


external memory, the Port P0 provides
both Address and Data.
• To demultiplex (separate) address and data
ALE pin is used.

• It is connected to the latch enable input.

• When ALE = 0, it provides data &


• When ALE = 1, it provides address.
Pin diagram of 8051
microcontroller
PSEN(Pin 29) :-

• PSEN stands for Program Store


Enable.

• This is an Active Low output pin.

• When the external ROM is used to


store the program code, this pin is
connected to the Output Enable (OE)
pin of ROM.

• It enables ROM for read operation.


Pin diagram of 8051
microcontroller
I/O Port pins :-

• The 8051 uC contains four 8 – bit


ports P0, P1, P2 & P3.
• Upon reset all the port’s are
configured as the Output port.
• To use any of these port as an input
port ,it must be programmed by
writing 1 to all bits.
• Port P0 is an open drain port hence it
requires external pull - up resistors
to each pin.
• While the port’s P1, P2 & P3 does not
requires external pull – up.
Pin diagram of 8051
microcontroller
Port 0 (P0) :-

• It occupies pin 32 to pin 39 known as


P0.7 to P0.0
• It can be used as Input or Output.

• The Port P0 is also designated as


AD0 - AD7
• i.e. Port P0 is used to provide both Address
and Data.

• When ALE = 0, it provides data D0-D7.


• When ALE = 1, it provides address A0-A7.

• In short the port P0 can be used to form


Address/Data bus.
Pin diagram of 8051
microcontroller
Port 1 (P1) :-

• It occupies pin 1 to pin 8 known as


P1.0 to P1.7

• It can be used as Input or Output.


Pin diagram of 8051
microcontroller
Port 2 (P2) :-
• It occupies pin 21 to pin 28 known as
P2.0 to P2.7
• It can be used as Input or Output.
• The port P2 is also used along with P0 to
provide 16-bit address for external memory.

• It is also designated as A8 – A15


• It provides high order bits of address in
output mode.

• When P2 is used for this function it can not


be used for Input/Output.
Pin diagram of 8051
microcontroller
Port 3 (P3) :-

• It occupies pin 10 to pin 17 known as


P3.0 to P3.7

• It can be used as Input or Output.

• The port P3 has additional functions of


providing some extremely important
signals such as interrupts, timer inputs,
serial data transfer and control signals.
Pin diagram of 8051
microcontroller

P3 bit (Pin no. ) Function - Description


P3.0 (Pin no. 10) R x D :- Receive Data
P3.1 (Pin no. 11) T x D :- Transmit Data
P3.2 (Pin no. 12) INT0 :- Interrupt 0
P3.3 (Pin no. 13) INT1 :- Interrupt 1
P3.4 (Pin no. 14) T0 :- Timer 0
P3.5 (Pin no. 15) T1 :- Timer 1
P3.6 (Pin no. 16) WR :- Write data
P3.7 (Pin no. 17) RD :- Read data
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

3)
Pin diagram of 8051 microcontroller
Internal RAM Organization of 8051
microcontroller

• The 8051 uC has 128 bytes of On-chip RAM.


• The internal RAM has assigned addresses from 00 H to 7F H.

• These 128 bytes are divided into 3 different parts such as :-

1. Register Banks

2. Bit Addressable RAM

3. General Purpose RAM


Internal RAM Organization of 8051
microcontroller
Register Bank in 8051 :-

• In 8051 uC the internal RAM area from address 00


H to 1F H is used for register banks.

• These 32 bytes are divided into 4 banks of register


in which each bank contains 8 registers R0 – R7.

• The RAM locations from 00 H to 07 H are set


aside for Bank 0 of R0 – R7.

• 08 H to 0F H is for Bank 1.

• 10 H to 17 H is for Bank 2.

• 18 H to 1F H is for Bank 3.
Internal RAM
Organization of 8051
microcontroller
Register Bank in 8051 :-

• When 8051 uC is powered up then bank 0 is


automatically selected hence it is known as Default
register bank.
• We can select our desired bank by set / reset the
RS1 & RS0 bits of PSW register as follows
RS 1 (PSW. 4) RS 0 (PSW.3) Register Bank
0 0 Reg. Bank 0
0 1 Reg. Bank 1
1 0 Reg. Bank 2
1 1 Reg. Bank 3
Internal RAM Organization of 8051
microcontroller
Bit Addressable RAM :-

• The 16 bytes of internal RAM from locations 20


H to 2F H are bit addressable.
• These 16 bytes provides us 128 bits.

• Microcontroller has given addresses to the bits


ranging from 00 H to 7F H.

• The bit addressable facility is used when only


single bit binary event is used e.g. Switch ON ,
OFF etc.

• This memory area is both byte addressable and


bit addressable.
Internal RAM Organization of 8051
microcontroller
General Purpose RAM :-

• The 80 bytes from locations 30 H to 7F H


of internal RAM are used for read and write
storage.

• This is known as General Purpose RAM or


Scratch Pad RAM.

• It is only Byte addressable.


Internal RAM Organization of 8051
microcontroller
Internal RAM Organization of 8051
microcontroller
Programming Model of 8051
microcontroller

The Programming Model of 8051 uc consists of

1. Internal RAM of 128 bytes

2. Internal ROM of 4 k bytes

3. Special Function Registers (SFR’s)


Programming Model of 8051
microcontroller
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

4)
Internal RAM organization of 8051
microcontroller
The Registers of 8051
microcontroller
The 8051 Registers :-

• The 8051 uC contains different 8 – bit & 16 – bit programmable


registers.

• The 8051 registers are classified into two types as

1. General Purpose Registers(GPR’s) / Working registers :-


• These registers are used to store the information (data/address)
temporarily during execution.

2. Special Function Register’s (SFR’s):-


• These registers are used to carry out some specific function.
The Registers of 8051
microcontroller
Accumulator :-

• The accumulator is a general purpose 8-bit register and


is abbreviated as register A or Acc.

• Structure of Acc register :-


The Registers of 8051
microcontroller
Accumulator :-

• The accumulator is the most Versatile register of the


8051 microcontroller.
• Because it is used for all the arithmetic & logical
operations, for all data transfer operations etc.

• It is used to store the final result of operation generated


by the 8051 uC’s ALU.

• It is byte and bit addressable.


The Registers of 8051
microcontroller
Register B:-
• The register B is an 8-bit register and is used with
register A during multiplication and division
operations.
• For other instructions it can be treated as the general
purpose memory or Scratch pad register where data
may be stored.
• Structure of register B :-
The Registers of 8051
microcontroller
Program Counter(PC)
• It is a 16 – bit register i.e. It can access external memory
address 0000 H to FFFF H (64 k bytes).
• The PC is the only register in 8051 uC which does not
have an internal address.
• The PC keeps the sequential track of the execution of
program.
• It is used to provide address for the memory.
• The PC points to the address of the next instruction to be
executed.
• When the CPU fetches the opcode from program ROM,
the PC is automatically incremented by 1.
The Registers of 8051
microcontroller
Data Pointer (DPTR) :-
• DPTR is meant for Pointing to data.
• DPTR is a 16 – bit register.
• It is made up of two 8 – bit registers DPH & DPL.
(Where DPH is High byte & DPL is Low byte)

• It is used to access external memory by indicating the address


from where data is to be read or where data is to be write.
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

5)
Register A, B, PC & DPTR of 8051
microcontroller
The Flags and PSW Register of
8051 microcontroller
The Flags of 8051 uC :-
• The Flags are 1 – bit registers provided to store the result of
certain program instructions.
• The other instructions can test the condition of flags and make
decision based on the flags states.
• The 8051 has four condition flags namely carry(CY), auxillary
carry(AC), overflow (OV) and Parity(P).
• These flags are affected by the arithmetic and logical
operations.
• In addition to this the 8051 uC has three General Purpose user
flags named as FO, GF0 & GF1.
• In 8051 uC, these flags are grouped into the PSW and PCON
registers.
The Flags and PSW Register of
8051 microcontroller
The PSW register:-
• The PSW (Program Status Word) register is an 8 – bit register .
• It is also known as the Flag register.
• Structure of PSW register :-
The PSW register contains –
• Four conditional flags (CY, AC, OV, P)
• Two register bank select bits (RS1 & RS0)
• One user flag (F0)

The PSW register is bit and byte addressable register.


Bit 7 : PSW.7 : CY : Carry Flag :-
• This flag is set (CY=1) whenever there is a carry
out from D7 bit of the Accumulator.
• This flag bit is affected after an 8 - bit addition or
substraction.
• It is also affected by rotate, jump and Boolean
operations.
• It can be set to 1 or 0 directly by an instruction
such as “ SETB C ” and “ CLR C”
Bit 6 : PSW.6 : AC : Auxillary Carry :-
• This flag is set (AC=1) whenever there is a carry
out from D3 bit to D4 bit during an ADD or SUB
operation.
• This flag is used by instructions that perform BCD
arithmetic.

Bit 5 : PSW.5 : F0 :- User Flag


Bit 4 & 3 : PSW.4 & 3 : RS1 & RS0: Register Bank
Selector bits
• These bits are used to select desired register bank
PSW.4 (RS1) PSW.3 (RS0) Register Bank
0 0 Register Bank 0
0 1 Register Bank 1
1 0 Register Bank 2
1 1 Register Bank 3
Bit 2 : PSW.2 : OV : Overflow Flag :-
• This flag is set whenever the result of a signed
number operation is too large.
• This causes the high order bit to overflow.
• i.e. When the results in the Accumulator is more
than 8- bit ,OV=1

Bit 1 : PSW.1 : User defined flag, reserved for


future use.
Bit 0 : PSW.0 : P : Parity Flag :-
• The Parity flag reflects the number of 1’s in the
accumulator register only.
• If the register A contains the odd number of 1’s
then P = 1.
• If the register A contains the even number of 1’s
then P = 0.
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

6)
The PSW Register of 8051
microcontroller
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Stack and Stack Pointer Register
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

7)
The Sack and SP register of 8051
microcontroller
SFR’s of 8051 microcontroller

Special Function Registers of 8051 uC:-

• Special Function Register’s (SFR’s) are placed in the


address space immediately above the 128 bytes of
RAM, from addresses 80 H to FF H.

• Not all of these addresses are used for SFR’s.

• The empty or unused locations can’t be used by the


programmer, because it generates unpredictable
results.
SFR’s of 8051 microcontroller
The Reset circuit of 8051
microcontroller

• The Reset circuit of


8051 uC :-

Reset :-
• It is active high input pin.

• Upon applying high pulse


to this pin, the uC will
reset and terminates all
the activities.
The Oscillator & Clock of 8051
microcontroller
• The Oscillator and Clock of 8051 uC :-
Oscillator :-
The Oscillator & Clock of 8051
microcontroller
The Clock of 8051 uC :-
Machine cycle and the state :-

• The clock frequency establishes the smallest interval of


time within the uC called as Pulse(P) time.
The Oscillator & Clock of 8051
microcontroller

• The smallest interval of time to execute any instruction is


known as Machine Cycle (MC).

• The machine cycle is itself made up of 6 states (S1 to S6)


• Each state consists of two oscillator periods (P1 & P2).
• The 8051 machine cycle takes 12 Oscillator periods.
• During each machine cycle 2 ALE pulses are generated.
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

8)
The SFR’s & Clock signal of 8051
microcontroller
The External Memory interfacing to
the 8051 microcontroller

External memory interfacing with 8051 uC :-

• When the internal memories of the microcontroller are


not sufficient, the external memory is needed.

• As PC of 8051 uC is 16-bit, it is capable of addressing


64 k bytes external memory.
External memory interfacing with 8051 uC
Important Points :-

• EA pin :- In the case of external


memory interfacing connect EA pin
to ground.( Normally it is
connected to the Vcc)

• PSEN pin :-Connect it to the OE


pin & CE pin of external memories.
External memory interfacing with 8051 uC
Important Points :-
• P0 & P1 provides 16-bit address to the
external memory.
• P0 provides lower 8-bit address (A0 to
A7) & P2 provides higher 8-bit address
(A8 to A15).
• P0 is also used to provide the 8-bit data
bus (D0 to D7).
• ALE pin :- The ALE pin is used to
demultiplex Address & Data from P0.

When ALE = 1,P0 provides address


When ALE = 0,P0 provides data.
Interfacing 8051 uC with external Program ROM
Interfacing 8051 uC with external Data RAM
Interfacing 8051 uC with external Data ROM
Video Lecture Notes
Chapter 1- Basics of Microcontroller & Intel 8051
architecture

9)
External memory interfacing with 8051
microcontroller

You might also like