Microcontroller LATEST VERSION
Microcontroller LATEST VERSION
AND PROGRAMMING
Prof. D. A. Patil
Head
Department of B.Sc. Computer Science (Entire)
Smt. Kasturbai Walchand College, (Arts and Science) Sangli
Structure of Course
Electronics Semester -I
Practical (Annual)
03-Aug-23 Prof. D. A. Patil | Department of B.Sc. Computer Science (Entire) | KWC, Sangli 2
Course Contents
1 Introduction to Microcontroller
3 Facilities in 8051
4 Interfacing Methods
Course Contents
INTRODUCTION TO MICROCONTROLLER
Study of 8051 and its Family(89C51, 8031, 8032, 8052, 8751, Phillips
(RD2)89C51VRD2).
What is Microcontroller ?
Mini Computer System
IO
IO
Device Single
Device
Chip
Memory Memory
RAM
RAM
CPU CPU
ROM
ROM
Microcontroller Microprocessor
Inbuilt RAM and ROM Do not have Inbuilt RAM and ROM
Microcontroller Microprocessor
Program
Data 8
and
CPU
Address 12
Data
Memory
Fundamental Architecture : Harvard
Data 8
Program
Address 12 Memory
CPU
Data 8
Data
Address 16 Memory
UNIT – I
Introduction to Microcontroller
Microcontroller Families
Devices and Families :
MCS - 251
8X251 SA 1K 8K 16 3 32
80930 AX 512-1024 - 12 - -
Architecture of 8051
8051 Microcontroller :
8051 Microcontroller :
Features of 8051
Pin Diagram
Architecture
8051 Microcontroller : Features
• 8 bit Microcontroller
• 16 bit Address Bus - 216 = 64 K
• Built in RAM – 256 bytes
» 128 bytes - Data Memory
» 128 bytes - SFR
• Built in ROM – 4 K (4096 bytes)
• Four 8 bit Bidirectional ports – P0, P1, P2 and P3
• Programmable Serial Port
• Two Timers T0 and T1
• Five Interrupt Sources
• Supports Bit level Boolean logic operations directly applied to
Port, Registers and SFR
• Four separate register banks – Each bank consists 8 registers
UNIT – I
Introduction to Microcontroller
• EA = 0 • =1
– 8051 executes program from P0 = A0 – A7
external memory P2 = A8 – A15
– 64 K (0000 H – FFFF H)
• EA = 1 ( +5 V) • =0
– 8051 executes program from
internal memory P0 = D0 – D7
– 4K (0000 H – 03FF H)
• EA = 1 (+12.75 V) • =0
– Internal EEPROM is Indicated Internal EEPROM is being
programmed programmed
XTAL1 XTAL2
Architecture of 8051
8051 Architecture :
8051 Architecture :
8051 Architecture : ALU
8051 Architecture : Register Bank Select Bits
0 0 Bank 0 00 - 07H
0 1 Bank 1 08 – 0F H
1 0 Bank 2 10 – 17H
1 1 Bank 3 18 – 1FH
8051 Architecture : Data Pointer
8051 Architecture : ALU : Stack Pointer
8051 Architecture : Register Banks
UNIT – I
Introduction to Microcontroller
Memory Organization
8051 Memory Organization :
8051 Memory
Program Memory
Internal External
On Chip Additional
4K 64K Max
8051 Program Memory :
8051 Data Memory :
8051 Memory
• Byte Addressable
✓ Bank 4x8 32
✓ General Purpose 80
• Bit Addressable
16 x 8 128
8051 Data Memory : SFR’s
8051 Memory Organization : Special Function Registers (SFR)
1 Introduction to Microcontroller
3 Facilities in 8051
4 Interfacing Methods
Course Contents
Data transfer,
Arithmetic,
Logical,
JUMP,
Loops & CALL instructions,
Bit manipulation Instructions.
UNIT – II
8051 Instruction Set
Prerequisite
Notations used in Instruction
Notations used in Instruction :
Rn n = 0 to 7
R0, R1, R2, R3, R4, R5, R6, R7
@Ri i = 0, 1
@R0
@R1
Notations used in Instruction :
#8bit Data
MOV R0, #00H
MOV R0, #0F0H
Direct
MOV A, 80H
UNIT – II
8051 Instruction Set
Addressing Modes
Addressing Modes :
Opcode Operands
MOV A, R0
MOV A, #02H
MOV A, 80 H
MOV 80 H, A
Addressing Modes : Indirect
MOV A, @R0
MOV A, @DPTR
Addressing Modes : Register
MOV A, R0
Addressing Modes : External Indirect
MOVX A, @DPTR
MOVX @DPTR, A
UNIT – II
8051 Instruction Set
Instruction Set
Instruction :
Opcode Operands
Opcode : Operation to be performed
Operands : Data on which operation is carried out
MOV A, R0
A = E0H
R0 = 00H
Instruction Set :
Arithmetic Instructions
Data Transfer
Logical Instructions
Logical Instructions with bits
Branch Instructions
UNIT – II
8051 Instruction Set
Instruction Set
Arithmetic Instructions
Instruction Set : Arithmetic Instructions
SUBB A, #03 H
SUBB A, R0
SUBB A, @R0
SUBB A, 80 H
Instruction Set : Arithmetic Instructions
MUL AB DIV AB
B A B A
MSB LSB Remainder Quotient
Instruction Set : Arithmetic Instructions
INC DPTR
UNIT – II
8051 Instruction Set
Instruction Set
Data Transfer Instructions
Instruction Set : Data Transfer Instructions
#05 H
R0 R0
@R0 @R0
80H 80H
Instruction Set : Data Transfer Instructions
MOVC A, @A+PC
MOVC A, @A+DPTR
MOVC A, @DPTR
Instruction Set : Data Transfer Instructions
MOVX A, @DPTR
Instruction Set : Data Transfer Instructions
Instruction Set
Logical Instructions
Instruction Set : Logical Instructions
Instruction Set
Logical Instructions with Bits
Instruction Set : Logical Instructions with bits
Instruction Set
Branch Instructions
Instruction Set : Branch Instructions
Unconditional Conditional
Branch Instructions Branch Instructions
Instruction Set : Unconditional Branch Instructions
JZ <Relative Address>
JC <Relative Address>
Instruction Set
Assembly Language Program
Instruction Set : Assembly Language Program Structure
$INCLUDE (REG51.INC)
ORG 0000 H
END
Instruction Set : Assembly Language Program
1 Introduction to Microcontroller
3 Facilities in 8051
4 Interfacing Methods
Course Contents
FACILITIES IN 8051
Serial Port :
Serial port of 8051, RS-232 standard and IC MAX–232, Baud rate in 8051,
programming for transmitting character through serial port using assembly
and C.
UNIT – III
Facilities in 8051
Prerequisite
8051 Architecture
8051 Architecture :
UNIT – III
Facilities in 8051
Timer
Timer / Counter Concept :
Pulse Count
8051 Register
Internal
Pulses
ftimer Timer / Counter 65,535
0/1
External .
Pulses .
0100
.
1.085
.
µS
.
Pulse Count Register = 100 Counter
0000
Time = 100 x 2 (1.085 µS) = 217 µS Timer
Timers :
ഥ : 𝑪Τ𝑻𝟏 , 𝑪Τ𝑻𝟎
𝑪Τ𝑻
Selects source of clock pulses to be counted up
M1 M0 Mode Description
0 0 0 13 bit Timer
0 1 1 16 bit Timer
1 1 3 Split Timer
UNIT – III
Facilities in 8051
TF : TF1 / TF0
Timer Overflow Flag ( 1/0 )
Whenever timer (T0 / T1) overflows this flag is set (TF1=1 / TF0=1).
16 bit mode – Overflows from FFFF – 0000 H
8 bit mode – Overflows from FF – 00 H
Timer Control Register : TCON
TR : TR1 / TR0
Timer Run Flag ( 1/0 )
IE : IE1 / IE0
External Interrupt Enable ( 1/0 )
IT : IT1 / IT0
Interrupt Type ( 1/0 )
Timer Clock
Timer Clock :
8051
1 1
𝑓𝑜𝑠𝑐 = 𝑓𝑥𝑡𝑎𝑙 = 11.0592 𝑥 106 𝑇𝑡𝑖𝑚𝑒𝑟 = =
𝑓𝑡𝑖𝑚𝑒𝑟 0.9216 𝑥 106
𝑓𝑜𝑠𝑐 11.0592 𝑥 106
𝑓𝑡𝑖𝑚𝑒𝑟 = = 𝑇𝑡𝑖𝑚𝑒𝑟 = 1.085 𝑥 10−6
12 12
Timer
Timer Data Register :
How to Start a
Timer
How to Start Timer :
16 bit Mode
65,535
.
100 Pulses
.
Overflow 65,435 Initial Count
TF = 1 . FF 9B
Interrupt TH0 TL0
.
.
0000
Timer Data Register : What it means ?
Find the data register content so that T0 counts 100 pulses
255
Overflow .
TH0 100 Pulses
.
TF = 1
TL0 Interrupt 155 Initial Count
. 9B
. TH0
.
TL0
000
UNIT – III
Facilities in 8051
𝑇𝐻0 = 𝐹𝐶 𝐻 𝑇𝑀𝑂𝐷 = 01 𝐻
𝑇𝐿0 = 66 𝐻
Timer Delay Generation : ALP 𝑇𝐻0 = 𝐹𝐶 𝐻 𝑇𝐿0 = 66 𝐻 𝑇𝑀𝑂𝐷 = 01 𝐻
𝑇𝐻0 = 𝐷1 𝐻 𝑇𝑀𝑂𝐷 = 02 𝐻
𝑇𝐿0 = 𝐷1 𝐻
UNIT – III
Facilities in 8051
𝑇𝑀𝑂𝐷 = 01 𝐻
UNIT – III
Facilities in 8051
Tx
Rx
GND
Serial Transmission : Synchronous Data Transfer Techniques
Serial Transmission : Asynchronous Data Transfer Techniques
Asynchronous Transmission : Modes
UNIT – III
Facilities in 8051
0 1 0 1 0 0 0 0
8 bit Data
SCON = 50 H
Transmit and Receive
UNIT – III
Facilities in 8051
8051
28,800
For Baud rate of 2400 2400 = TH1 = TL1 = -12 = F4 H
12
28,800
For Baud rate of 9600 9600 = TH1 = TL1 = -3 = FD H
3
Serial Communication : Program
Write a program to transmit ‘A’ continuously. Use crystal frequency of
11.0592 MHz
𝑓𝑡𝑖𝑚𝑒𝑟1 = 28,800 𝐻𝑧
TMOD = 20 H
Serial Communication Program : TH1 = TL1 = FD H SCON = 50 H TMOD = 20 H
$INCLUDE (REG51.INC) #include <reg51.h>
ORG 0000 H
void main() {
MOV SCON, #50H SCON = 0x50;
MOV TMOD, #20H
MOV TH1, #-3 TMOD = 0x20;
MOV TL1, #-3 TH1 = -3;
SETB TR1 TL1 = -3;
AGAIN: MOV SBUF, #’A’ TR1 = 1;
RS232
RS-232 :
Pin Description
1 Data Carrier Detect (DCD)
2 Received Data (RxD)
3 Transmitted Data (TxD)
4 Data Terminal Ready (DTR)
5 Ground (GND)
6 Data Set Ready (DSR)
7 Request to Send (RTS)
8 Clear to Send (CTS)
9 Ring Indicator (RI)
MAX-232 :
MAX 232
Interfacing Circuit :
Course Contents
1 Introduction to Microcontroller
3 Facilities in 8051
4 Interfacing Methods
Course Contents
INTERFACING METHODES
Interfacing
LED, Relay, Optocoupler, Switch
Interfacing : LED, Relay, Optocoupler, Switch
UNIT – IV
Interfacing Methods
Interfacing
Outputs
Digit CODE
dp g f e d c b a
0 1
1 1 1 1 1 1
2 1 1
3 1 1
4 1 1 1
5 1 1
6 1
7 1 1 1 1
8
9 1
7 Segment : Design - CA
Outputs
Digit CODE
dp g f e d c b a
0 0 1 0 0 0 0 0 0
1 0 1 1 1 1 0 0 1
2 0 0 1 0 0 1 0 0
3 0 0 1 1 0 0 0 0
4 0 0 0 1 1 0 0 1
5 0 0 0 1 0 0 1 0
6 0 0 0 0 0 0 1 0
7 0 1 1 1 1 0 0 0
8 0 0 0 0 0 0 0 0
9 0 0 0 1 0 0 0 0
7 Segment : Design - CA
Outputs
Digit CODE
dp g f e d c b a
0 0 1 0 0 0 0 0 0 40
1 0 1 1 1 1 0 0 1 79
2 0 0 1 0 0 1 0 0 24
3 0 0 1 1 0 0 0 0 30
4 0 0 0 1 1 0 0 1 19
5 0 0 0 1 0 0 1 0 12
6 0 0 0 0 0 0 1 0 02
7 0 1 1 1 1 0 0 0 78
8 0 0 0 0 0 0 0 0 00
9 0 0 0 1 0 0 0 0 10
UNIT – IV
Interfacing Methods
Interfacing
Stepper Motor
Stepper Motor : Theory
Stepper Motor : Working
Stepper Motor : How to rotate : Full Step Sequence
1 0 0 1 9
1 1 0 0 C
0 1 1 0 6
0 0 1 1 3
Stepper Motor : How to rotate : Half Step Sequence
Anti
Step Angle Steps per Revolution Clock
A B C D Clock
wise
wise
0.72 500
1 0 0 1
1.8 200
1 1 0 0
2.0 180 0 1 1 0
2.5 144 0 0 1 1
90 4
Stepper Motor : Interfacing
UNIT – IV
Interfacing Methods
Interfacing
DC Motor
DC Motor : Working
DC Motor : PWM
Duty Voltage
Cycle
10 % 0.5 V
50 % 2.5 V
90 % 4.5 V
DC Motor : PWM Frequency Filter
DC Motor : Interfacing
DC Motor : PWM Generation
100
mS
UNIT – IV
Interfacing Methods
Interfacing
LCD
LCD : Pin Diagram
RS = 0 Command Register
RS = 1 Data Register
RW = 0 Write
RW = 1 Read
E = 1 -> 0 Enable
VSS = 5V
Data
VDD = GND 8 bit mode = D0-D7
VEE = Contrast Voltage 4 bit mode = D4-D7
LCD : Our Connection
RS = 0 Command Register
RS = 1 Data Register
RW = 0 Write
RW = 1 Read
E = 1 -> 0 Enable
VSS = 5V
Data
VDD = GND
8 bit mode = D0-D7
VEE = Contrast Votlage 4 bit mode = D4-D7
LCD : Commands
Code
Command to LCD
(Hex)
01 Clear display screen
02 Return home
06 Shift Cursor to Right
0C Display on cursor on
0F Display on cursor blinking
80 Force cursor to beginning of 1st line
C0 Force cursor to beginning of 2nd line
32 2 lines and 5x7 matrix font
28 4 bit mode
LCD : Interfacing
THANK YOU
?
Prof. D. A. Patil
Department of B.Sc. Computer Science (Entire)
Smt. Kasturbai Walchand College, Sangli
100%