8051 Microcontroller
8051 Microcontroller
Course Outcomes
C501.1:
The student will get basic knowledge of memory structure, SFR
format, working of timer, counter, UART, interrupt in 8051 and ARM
7 microcontroller.
C501.2:
The student will be able to understand the working of different
instruction sets in 8051, ARM7 and interfacing of peripheral devices
such as ADC, DAC, 7segment Display, LCD, Stepper motor, DC
motor, relay to 8051 and ARM7 microcontroller.
C501.3:
The student will be able to apply knowledge of instruction set for
writing code for arithmetic operations, data transfer operation,
timer, counter, UART, interrupt and programming peripheral
devices.
C501.4:
The student will be able to analyze and select suitable instructions
and special function register of 8051 and ARM7 microcontroller for
writing efficient code.
Advantages of microprocessor
Designer can decide on amount RAM,ROM,I/O ports
needed to fit task at hand
Advantages of Microcontroller
Less space requirements
Low power consumption
8051 MC
RAM
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Vcc
P0.0(AD0
)P0.1(AD1)
P0.2(AD2
)P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
)P2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
I/O port
4 I/O port
Each of 8 bit
wide
P0
P1
P3
P2
Pin 1-8
Vcc
10 uF
9
8.2 K
RST
Pin 10
Pin 16
N
C
EXTERNAL
OSCILLATOR
SIGNAL
XTAL2
XTAL1
GND
Pin 20
Pin 29
Pin 32-39
Minimum
connection for 8051
based system
1 MC= 6 State
1 State= 2 oscillator pulses
1MC= 12 clock period
C X 12
Machine cycle
ADD A, R0
MOV A, #23H
LJMP
Registers of 8051
B
R0
R1
R2
DPH
DPL
PC
R3
R4
R5
R6
R7
Some 8-bit
Registers of
the 8051
DPTR
PC
Parity flag
RS1
RS0
0
0
1
1
0
1
0
1
Register
Bank
0
1
2
3
RAM=128 byte
Range=00 to
127
Range=00H to
7FH
7F=1
80
27
1F=3
Byte
7FH
Read/ Write
storage
Scratch pad
8051
Memory
Organizati 16
Byte
on
32
Byte
30H
2F
H
20
1F
H
H
00H
Bit addressable
read/ write
memory
Register Bank
and Stack
128
Byte
1FH
8
Byte
18H
17H
8
Byte
8
Byte
10H
0FH
08H
07
H
8
Byte
00H
Register Bank
3
Register Bank
2
Register Bank
1
R7
R6
R5 Bank
Register
R4
0
R3
R2
R1
R0
32
Byte
ADDRES
S
REG
07 R7
H
R6
06
H
R5
05
R4
H
04
R3
H
R2
03
H
R1
02
R0
H
01
Register
H
Bank 0
00
ADDRES
S
REG
0F
H
R7
0E
H
R6
0D
H
R5
0C
H
0B
H
0A
H
09
H
R4
R3
R2
R1
R0
08
H
Register
Bank 1
ADDRES
S
REG
17 R7
H
R6
16
H
R5
15
R4
H
14
R3
H
R2
13
H
R1
12
R0
H
11
Register
H
Bank 2
10
ADDRES
S
REG
1F
H
R7
1E
H
R6
1D
H
R5
1C
H
1B
H
1A
H
19
H
R4
R3
R2
R1
R0
18
H
Register
Bank 3
How to switch
register bank?
RS1
RS0
0
0
1
1
0
1
0
1
Register
Bank
0
1
2
3
RS1
PSW.4
RS0
PSW.3
Registe
r Bank
CLR PSW.3
MOV A, R0H
SETB PSW.4
MOV A,10H
Stack in 8051
Stack is a section of RAM used by CPU to store information
7FH
temporary
This information could be data or an address
The register used to access stack is called SP(stack
8086
8051
pointer)
register.
SP=16
bit
SP=8
bit
Read/
Write
storage
Scratch
pad
30H
Default value in SP reg. is 07H
Bit
i.e RAM location 08H is the first location used for stack by addressabl
2F
e read/
8051
H
20
Register Bank 1= Default Stack memory
H
1F
Location 08H to 1FH in 8051 RAM can be used for stack.
H
00H
If in given program we need more than 24 bytes ( 08h to
1Fh)
of stack, we can change SP to point RAM location 30 7FH
write
memory
Register
Bank and
Stack
PUS
H
8086
8051
SP 16 bit reg.
SP 8 bit reg.
SP decremented by 2
SP incremented by 1
SP=SP-2
SP=SP+1
8086
POP
8051
SP 16 bit reg.
SP 8 bit reg.
SP incremented by 2
SP decremented by 1
SP=SP+2
SP=SP-1
ADDRES DAT
S
A
0F H
R7
0E H
SP=07H
S
P
S
P
S
P
S
P
REG
R6
0D H
R5
0C H
R4
0B H
R3
0A H
FEH
R2
09 H
12H
R1
08 H
25H
R0
07H
Current status
S
POP 3;
POP 2;
R5=0
FEH
R3=1
2H
R2=2
5H
0F H
P
S
P
S
P
S
P
REG
R7
0E H
R6
0D H
PUSH 4
ADDRES DAT
S
A
R5
0C H
R4
0B H
R3
0A H
FEH
R2
09 H
12H
R1
08 H
25H
R0
07H
Bit addressable
read/ write
memory
16 byte
Range= 20H to
2FH
16 x 8 = 128
Byte
Bit addressable
bits
addressable
Register=8 bit
Byte has address
Register=8 bit
Bit has address
Access registers
in bytes
Access registers
in bits
Ex. SP
Bit addressable
read/ write
memory
MOV A, #03H; copy byte 03h to reg.
A
SETB
CLR
32H
32H
0 0 0 0 0 0
0 1 1
1
MOV P0,
instruction
#0FFH
BYTE addressable
SETB P0.0
instruction
P0
ADDRES
S
BIT addressable
86H
85H
84H
83H
82H
81H
80H
Read/ Write
storage
Scratch pad
Use for read and write
storage
General purpose storing of
data
If we need more registers we
simply use RAM locations 307FH
8051
8052
128 byte of
RAM
256 byte of
RAM
Two different
physical
memories,
but they have
same
addresses
SFR
Bit
addressable
registers
ROM in 8051
4K bytes on chip ROM
Use to store user code
ROM=code memory
Size of PC=16 bit
Therefore maximum size of on chip ROM can be
0000 to FFFFFH i.e 64 Kbytes
4 K bytes of ROM memory has addresses from
0000H to 0FFFH.
Tristate Buffer
Tristate buffer has single input,
single output and enable control pin.
By activating the enable, data at input
is transferred to output.
P
1
PORT
1
Port-1 does not have any alternate function i.e. it is dedicated solely
for I/O interfacing. When used as output port, the pin is pulled up or
down through internal pull-up. To use port-1 as input port, '1' has to
be written to the latch. In this input mode when '1' is written to the
pin by the external device then it read fine. But when '0' is written to
the pin by the external device then the external source must sink
current due to internal pull-up. If the external device is not able to
sink the current the pin voltage may rise, leading to a possible wrong
reading.
0
0
0
1
1
1
1
0
1
0
Active
MOV
A,
P1
ANL P1, A;
Active
1
P1 = A AND
P1
P0
PORT
0
Port 0 =
Data/Address lines
Data/Address
Contr
ol
Read
Latch
VCC
0
P0.
x
1
Intern
al CPU
Bus
Write
Latch
Read
Pin
CLK
Port 0 =
Data/Address lines
Data/Address
Contr
ol
Read
Latch
VCC
1
P0.
x
0
Intern
al CPU
Bus
Write
Latch
Read
Pin
CLK
port
Data/Address
Contr
ol
Port 0 = I/O
VCC
Read
Latch
1
Intern
al CPU
Bus
Write
Latch
Read
Pin
P0.
x
CLK
Floati
ng
PORT
2
P
2
pull-up
capability.
there
is
limited
current
driving
port
Data/Address
Contr
ol
Port 2 = I/O
VCC
Pull up
register
Read
Latch
1
Intern
al CPU
Bus
Write
Latch
Read
Pin
P2.
x
CLK
1
1
Data/Address
Contr
ol
Port 2 =
Address lines
VCC
Pull up
register
Read
Latch
1
Intern
al CPU
Bus
Write
Latch
Read
Pin
P2.
x
CLK
Data/Address
Contr
ol
Port 2 =
Address lines
VCC
Pull up
register
Read
Latch
Intern
al CPU
Bus
Write
Latch
Read
Pin
P2.
x
D
CLK
PORT
3
P
3
Alternate
output
Function
TXD, RD, WR
Port 3 = I/O /
Address lines
Read
Latch
1
Intern
al CPU
Bus
Write
Latch
Read
Pin
VCC
Pull up
register
P2.
x
1
CLK
Timer in
8051
Timer
0
Timer
1
TH TL
0
0
00 03
00
01
02
H H
XTAL
oscillato
r
12
Timer
operating
frequency
C/T
M1
M0
GAT
E
C/T
M1
M0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Timer 1
Timer 0
M
1
M
0
Mod
e
Operating mode
C/T
M1
M0
GAT
E
C/T
M1
M0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Bit
Operating mode
C/T
C/T = 1, counter
C/T =0, timer
GAT
E
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TF1
TR1
TF0
TR0
IE1
interrupt
IT1
interrupt
IE0
interrupt
IT0
interrupt
TMOD
TCON
GAT
E
C/T
M1
M0
GAT
E
C/T
M1
M0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Mode 1
16 bit timer
0000h to FFFFh
After the timer is started, it start to count up. It count up until it
reaches its limit of FFFFH.
When timer rolls over from FFFFH to 0000H , it sets high a flag bit
called TF(timer flag)
XTAL
oscillato
r
12
Timer
operating
frequency
TH TL
0
0
00 03
00
01
02
H H
1 count =
1.085 us
No. of Count
Delay
1.085
us
1.085 us
x2
1.085 us
x3
TL
x
F
F
F
F
TH
x
TL
x
E
E
0
0
TL
0
F
F
F
F
TH TL 0 0
The number of counts0for rollover
0
0 is0FFFF-0000= FFFF(65535
decimal)
One extra clock needed when timer roll over from FFFF to 0 and
rises TF flag.
Maximumgenerated
delay= (65535+1)
x 1.085
=71.1 ms- xxxx
Timer
Delay
= us
( FFFF
+ 1 ) x 1.085 us
TH
x
TL
x
FF
F
F
TH
x
TL
x
4
B
F
D
X 20
F=1/T
Delay
T
Find the value of THx and TLx for generation a frequency
100 KHz ?
TH TL0
0
Square wave Frequency = 100 KHz
F
F
F
F
F
F
F
B
TL0
F=1/T
Delay
T
Minimum frequency means maximum time period
Maximum time period = 71 ms
TH TL0
0
Therefore minimum frequency = 1 / (2 x 71 ms) = 7 Hz
TH
0
TL0
F
F
F
F
0
0
0
0
F=1/T
Delay
T
Minimum frequency means maximum time period
minimum time period = 1.085 us
TH TL0
0
Therefore maximum frequency = 1/(2 x 1.085 us) = 461
KHz
TH
0
TL0
F
F
F
F
F
F
F
B
Mode 0
13 bit timer
0000h to 1FFFh
After the timer is started, it start to count up. It count up until it
reaches its limit of 1FFFH.
When timer rolls over from 1FFFH to 0000H , it sets high a flag bit
called TF(timer flag)
Mode 0 is exactly like mode1 except that it is a 13 bit timer instead
of 16 bit.
Mode 0
8 bit timer, auto reload mode
00h to FFh
After the timer is started, it start to count up. It count up until it
reaches its limit of FFH.
When timer rolls over from FFH to 00H , it sets high a flag bit called
TF(timer flag)
When TLx reg. roll from FFh to 00h and TFx set to 1, TL reloaded
automatically by original value kept by THx register.
1
0
0
TFx
05h
07h
06h
00h
FFh
05h
05h
TLx
THx
FF
THx
00
Mode 3
Timer
1=off
0=on
TF1
8 bit
timer
TH0
TR1
TF0
TL0
TR0
8 bit timer
Counter
Every thing is same as that of timer, the only difference is
clock source.
GAT C/T
M1
M0 GAT C/T
M1
M0
TMOD
E
E
1
External clock
pulse
Counter 0
Counter 1
Mode
1
Mode
2
LED
blinkin
g
TMOD
GAT
E
C/T
M1
M0
GAT
E
C/T
M1
M0
Main code
Subroutine
TL0=00h
TH0=EEh
Turn on Led
ACALL DELAY
Call delay
ACALL DELAY
Call delay
SJMP again1
Short jump to L1
Turn on timer 0
Stop timer
CLR TF0
RET
TMOD
TCON
GAT
E
C/T
M1
M0
GAT
E
C/T
M1
M0
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Timer 0, mode 1, 16
bit mode
Serial communication in
8051
Serial transfer
0 0 1 0 1 1 0 1
Transmitter
Receiver
Parallel transfer
1
0
1
1
Transmitter 0
1
0
0
Receiver
Microcontroller (TTL)
Logic 0
Logic 1
Logic 0
Logic 1
3v to 25v
-3v to -25v
0 to 0.8 v
2v to 5v
RXD
RS232
TXD
CPU
MAX23
2
TXD
(P3.1)
RXD
(P3.0)
microcontro
ller
110
150
300
COM port.
Some of the baud rate supported by
PC
Baud rate in 8051 is programmable with
600
1200
2400
4800
9600
1920
0
SBUF register
Is 8 bit register
Byte of data to be transferred via TXD line, it must be placed in
SBUF register.
Similarly SBUF holds the byte of data when it received by the
8051s RXD line
The moment data is written into SBUF, it is framed with start bit
and stop bit and transferred serially via TXD pin
SBU
F
SCON
register
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
When set, it enables multiprocessor communication in mode 2 and 3, and
eventually mode 1. It should be cleared in mode 0.
Mode 0
serial data are transmitted and received through the RXD
pin, while the TXD pin output clocks. The bout rate is fixed
at 1/12 the oscillator frequency. On transmit, the least
significant bit (LSB bit) is sent/received first.
TRANSMIT
RECEIVE
Mode 1
In mode 1, 10 bits are transmitted through the TXD pin or
received through the RXD pin in the following manner: a
START bit (always 0), 8 data bits (LSB first) and a STOP bit
(always 1). The START bit is only used to initiate data
receive, while the STOP bit is automatically written to the
RB8 bit of the SCON register.
TRANSMIT
RECEIVE
XTAL
oscillato
r
12
32
28,800 Hz
To timer 1
to set
baud rate
921.6KHz
Timer
operating
frequency
11.0592
MHz
TH1=
256
28,800
Baud rate
H
Mode 2
In mode 2, 11 bits are transmitted through the TXD pin or
received through the RXD pin: a START bit (always 0), 8 data
bits (LSB first), a programmable 9th data bit and a STOP bit
(always 1). On transmit, the 9th data bit is actually the TB8
bit of the SCON register. This bit usually has a function of
parity bit. On receive, the 9th data bit goes into the RB8 bit
of the same register (SCON).The baud rate is either 1/32 or
1/64 the oscillator frequency.
TRANSMIT
RECEIVE
Mode 3
Mode 3 is the same as Mode 2 in all respects except the baud
rate. The baud rate in Mode 3 is variable.
SCON
register
REN - Reception Enable bit enables serial reception when set. When cleared,
serial reception is disabled.
TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem
of transmitting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.
RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by
hardware if 9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
SCON
register
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one
byte is sent. It's a signal to the processor that the line is available for a new byte
transmitted. It must be cleared from within the software.
RI - Receive Interrupt flag is automatically set upon one byte receive.
it signals that byte is received and should be read quickly prior to being replaced
by a new data. This bit is also cleared from within the software.
Interrupts in 8051
Interrupt
Polling
Device 1 Device 1
8051
microcontroll
er
Device 1
Device 2
Device 2
Switch pressed: LED on
Switch released: LED off
Interrupt
8051 microcontroller
INT
0
Device 1
Addre Main
ss
code
0400h
0401h
0403h
0404h
0406h
Addre
ss
0003h
0004h
PC=040
3h
L1:SETB
P1.3
ACALL
Delay
CLR P1.3
ACALL
Interrupt
service
Delay
routine
SJMP L1
(ISR)
Square
P1. wave
3
P1.
4
0000h
Reset
0001h
0002h
INT0
0004h
LE
D
0005h
Interru
pt
vector
table
CPL P1.4
RETI
0006h
0007h
0008h
0009h
Stack
memor
y
Addre
ss
RAM
Stack
memor
y
0007h
00
03
00
04
00
0007h
00
03
00
04
00
0009h
Interrup
t
0003h
Addre
ss
RAM
0008h
Addre
ss
0008h
0009h
000Ah
000Bh
000Ch
000Dh
000Eh
TF0
Interrupt
8051 microcontroller
INT
0
Device 1
Addre Main
ss
code
0400h
0401h
0403h
0404h
0406h
Addre
ss
0003h
0004h
PC=040
3h
L1:SETB
P1.3
ACALL
Delay
CLR P1.3
ACALL
Interrupt
service
Delay
routine
SJMP L1
(ISR)
Square
P1. wave
3
P1.
4
0000h
Reset
0001h
0002h
INT0
0004h
LE
D
0005h
0006h
ROM
0007h
0008h
CPL P1.4
RETI
0009h
Stack
memor
y
Addre
ss
RAM
Stack
memor
y
0007h
00
03
00
04
00
0007h
00
03
00
04
00
0009h
Interrup
t
0003h
Addre
ss
RAM
0008h
Addre
ss
0008h
0009h
000Ah
000Bh
000Ch
000Dh
000Eh
TF0
IE (Interrupt enable )
register:
INT
0
INT
1
INT
0
INT
1
INT
0
INT
1
Edge triggered
Interrupt
INT
0
INT
1
TCON
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Timer
Interrupt
Addressing mode
CPU can access data in various ways. The
data could be in register/ memory/ immediate
value
These various ways of accessing data are
called addressing modes
1.
2.
3.
4.
5.
Immediate
Register
Direct
Register indirect
indexed
A<=25h
R0<=F2h
A<= R0
MOV R4, R7
R4<=R7
MOV P2, P1
P2<=P1
MOV 7H, 2H
PUSH 06h
memory
POP 05H
location 05h
MOV @R1, A
Arithmetic operations
Logical operations
Data transfer operations
Boolean variable operations
Program branching operations
Arithmetic Instruction
set
Arithmetic Instruction
set
Arithmetic Instruction
set
RR
RRC
RL
RLC
8051 microcontroller
PC
0400h
0402h
0404h
CLR TR0
0406h
CLR TF0
0408h
ACALL DELAY
040Ah
040Ch
ACALL DELAY
040Eh
SJMP again1
PC
PC
RET
Subroutine
Main
code
PC=040
Ah
Addre
ss
RAM
Stack
memor
y
Addre
ss
RAM
Stack
memor
y
0007h
00
0A
00
04
00
0007h
00
0A
00
04
00
0008h
0009h
0008h
0009h
LCALL
Long call
3 byte instruction
Address: 16 bit
LCALL can be used to call subroutines located anywhere within
64 Kbyte address space of 8051
ACALL
Absolute call
2 byte instruction
Address: 11 bit
ACALL can be used to call subroutines located within 2 Kbyte
address space of 8051
LJMP
Long jump
3 byte instruction
Address: 16 bit
LJMP can be used to jump anywhere within 64 Kbyte address
space of 8051
SJMP
Short jump
2 byte instruction
1st byte: opcode
2nd byte: relative address
Address: 8 bit therefore relative address range= 00 to FFh
Is divided into forward and backward jump, that is within -128
to 127 bytes of memory relative to address of current PC.
AJMP
Long jump
2 byte instruction
Address: 11 bit
AJMP can be used to jump anywhere within 2 Kbyte address
space of 8051
PC
OPCODE
CODE
0002H
7455
MOV A,#55H
0004H
6003
JZ NEXT
0006H
08
INC R0
0007H
04
INC A
0008H
04
INC A
0009H
PC
2477
NEX ADD A, #77H
Relative
address=
target jump
T:
address- PC
OPCODE
CODE
0002H
7455
MOV A,#55H
0004H
04
0005H
08
INC R0
0006H
04
INC A
0007H
60FB
JZ NEXT
0009H
2477
ADD A, #77H
NEX
T:
INC A
16 x 2 LCD
display
LCD interfacing
Instruction command
code register
VCC VS
S
VE
E
RS R/
W
Data register
D8 D7 D6 D5 D4 D3 D2 D1 D0
+5v
VE
E
RS
R/W
0
1
1
0
0
1
1
0
0
0
0
0
0
1
Data
Data register
register
code
command code
Instruction
Instruction command
register
register
VC
C
VSS
+5v
VCC
VEE
RS
R/W
0
1
1
0
0
1
1
0
0
0
0
0
0
1
Data
Data register
register
code
command code
Instruction
Instruction command
register
register
VSS
VCC VS
S
Data
Data register
register
code
command code
Instruction
Instruction command
register
register
R
S1
R/
W
VE
E
R/W
1
0
0
1
0
0
0
0
0
1
Data
Data register
register
code
command code
Instruction
Instruction command
register
register
VE
E
Write
Read
0
RS
0
R/W= 0: write LCD
VCC VS
S
code
command code
Instruction
Instruction command
register
register
1
0
1
0
0
0
1
Data
Data register
register
To display letters
and numbers, we
send ASCII codes
for letter A-Z, a-z
and numbers 0-9
to data pins
RS R/
W
VE
E
480
ns
VCC VS
S
R
S
R/W
E
0
1
1
0
0
1
1
0
0
0
0
0
0
1
Data
register
Instruction
command code
register
VC
C
VS
S
VEE
R
+5v
+5v
LCD
Command
codes
Code (Hex)
Return home
10
14
18
1C
80
C0
38
LCD interfacing
Instruction command
code register
VCC VS
S
VE
E
RS R/
W
Data register
D8 D7 D6 D5 D4 D3 D2 D1 D0
P1.
0
P1.
1
P1.
2
P1.
3
P1.
4
P1.
5
P1.
6
P1.
7
P2.
2
P2.
1
P2.
0
8051
microcontroller
RS BIT P2.0
E BIT P2.2
RW BIT P2.1
send_command: CLR RW
CLR RS
SETB E
ACALL DELAY
CLR E
RET
RS BIT P2.0
E BIT P2.2
RW BIT P2.1
send_data: CLR RW
SETB RS
SETB E
ACALL DELAY
CLR E
RET
ORG 00H
RS BIT P2.0
RW BIT P2.1
E BIT P2.2
;LCD INITIALIZATION
here: MOV P1, #38H ;2 lines and 5x7 matrix
ACALL send_command
MOV P1, #0EH ;display on cursor blink
ACALL send_command
MOV P1, #01H ;clear display screen
ACALL send_command
;PRINTING A CHARACTER
Keyboard
interfacing
Output port
VC
C
R
R
Input port
Output port
VC
C
R
R
Input port
If key
pressed
Output port
VC
C
R
R
1
0
Input port
If key
pressed
Output port
VC
C
R
R
1
0
Input port
Before Key
pressed
after Key
pressed
CJNE
1
If key
pressed
Output port
VC
C
R
R
Input port
If key
pressed
Output port
VC
C
R
R
1
0
Input port
If key
pressed
R
R
Output port
VC
C
Input port
If key
pressed
R
R
Output port
VC
C
Input port
Relatively inexpensive
Ideal for open loop positioning
control
Can be implemented without
feedback
Minimizes sensing devices
Just count the steps!
Torque
Holds its position firmly when
not turning
Eliminates mechanical brakes
Produces better torque than DC
motors at lower speeds
Positioning applications
S
N
P1.
1
P1.
2
P1.
3
P1.
0
S
N
P1.
1
P1.
2
P1.
3
P1.
0
S
N
P1.
1
P1.
2
P1.
3
P1.
0
S
N
P1.
1
P1.
2
P1.
3
P1.
0
S
N
P1.
1
P1.
2
P1.
3
P1.
0
S
N
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
P1.
0
P1.
1
P1.
2
P1.
3
ADC interfacing
1V
111
110
101
100
011
010
001
0V
000
1V
0.875 V
0.75
V
0.625V
0.5
V
0.375
V
0.25 V
0.125
V
0V
n bit ADC
In this case,
n=8
No. of
quantization
levels
=
1-0
n
2
n
2
8 analog inputs
End of
conversions
Reference voltage
Output enable
Start of conversions
3 address pins
ADC 0809/0808
8 bit ADC
If Vref (+)= 2.56 v and Vref (-)=0 v then
2.56 - 0
8
2
Input to ADC
Output from
ADC
0 mv
10 mv
20 mv
2.56 v
00000000
00000001
00000010
11111111
= 10
mv
D
A
T
A
1
0
P2.4
ALE
P2.6
SC
P2.7
EOC
P2.5
OE