Professional Documents
Culture Documents
A system designed with a combination of hardware and software for a specific task
is called Embedded Systems.......
Examples:
1. TV Remote control
2. DVD players
3. Printers
4. Scanners
5. Pagers
6. Washing Machines
7. Microwave Ovens
8. Automatic Teller Machines
9. Modems
10. Digital Cameras
11. Network Cards
12. Routers
13. Video Games
14. Set-top boxes
15. Stereo systems
16. Home Security Systems
CPU memory Timers Ports Interrupts Microprocessor
I/O
Memory TIMERS
Ports
Micro Controller
Serial
CPU Interrupts
Ports
Definition: A programmable device which has a CPU along with inbuilt memory, I/O, timers, serial
port and interrupt is called a Microcontroller….
Microprocessors vs Microcontrollers
Microprocessor Microcontroller
PHILIPS
MOTOROLA
ZILOG, etc.,
Features of Intel 8051 Microcontroller: It is an 8-bit microcontroller
Interrupts: 5 Interrupts
Comparison with other basic versions of microcontrollers
Timers 2 2 3
Serial Port 1 1 1
Interrupts 3 5 6
Elevator - Example to show the need of interrupts, timers and programmable memory within a chip
Going up
Timer < 10 sec
Timer = 10 sec
Req = floor
Going down
Req< floor
Port 0 Port 2
8051 Architecture: latch latch
Address
RAM RAM Port 0 Port 2 EPROM
REG Drivers Drivers Program
Address
Register
ALU TH1,TL1,PCON,SCON,
Program
IE,IP,SBUF,SCON Counter
FLAG
Other Registers
DPTR
PSEN
Instruct
ALE Timing
ion
EA Control
Register
RST Port 1 Port 3
latch latch
Oscillator
Port 1 Port 3
Drivers Drivers
PIN CONFIGURARTION of 8051
VCC
P1.0
1 40 P0.0 [AD0]
P1.1
2 39 P0.1[AD1]
P1.2
3 38 P0.2[AD2]
P1.3
4 37
P1.4 P0.3[AD3]
5 36
P1.5 P0.4[AD4]
P1.6
6 35
P1.7
7 34 P0.5[AD5]
RESET
8 33 P0.6[AD6]
P3.0
9 32 P0.7[AD7]
10 31 EA
P3.1
P3.2 11 8051 30 ALE
P3.3 12 29 PSEN
P3.4 13 28 P2.7 [A15]
CY AC F0 RS1 RS0 OV F1 P
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0
Note: The value presented by the RS0 and RS1 selects the corresponding register banks
7F H
Memory Organization of 8051
Internal ROM
Internal RAM is of size 128 bytes
EPROM - 4 KB
Range of address 00 H – 7F H 30 H
2F H
1. 00 H – 1F H - Memory Bank
general purpose registers
{ Bank 0 – R0 – R7}
{ Bank 1 – R0 – R7}
{ Bank 2 – R0 – R7} 20 H
{ Bank 3 – R0 – R7} 1F H
{ Bank 1 – R0 – R7}
{ Bank 0 – R0 – R7}
00 H
SFRs [SPECIAL FUNCTION REGISTERS]
External Memory Organization
External ROM up to 64 KB
External RAM up to 64 KB
Port Structures of 8051
VCC
P1.0
1 40 P0.0 [AD0]
P1.1
2 39 P0.1[AD1]
P1.2
3 38 P0.2[AD2]
P1.3
4 37
P1.4 P0.3[AD3]
5 36
P1.5 P0.4[AD4]
P1.6
6 35
P1.7
7 34 P0.5[AD5]
RESET
8 33 P0.6[AD6]
P3.0
9 32 P0.7[AD7]
10 31 EA
(RXD)P3.0
(TXD)P3.1
P3.1
P3.2 11 8051 30 ALE
(INT0)P3.2 P3.3 12 29 PSEN
(INT1)P3.3 P3.4 13 28 P2.7 [A15]
(T0)P3.4 14 27 P2.6 [A14]
P3.5
(T1)P3.5
(WR)P3.6 P3.6 15 26 P2.5 [A13]
INTERNAL INTERRUPTS – 3
EXTERNAL INTERRUPTS
IE.5 Reserved.
ES IE.4 Enables or disables the serial port interrupt. If ES=0, the serial port interrupt is
disabled.
ET1 IE.3 Enables or disables the Timer 1 Overflow interrupt. If ET1=0, the Timer 1 interrupt
is disabled.
EX1 IE.2 Enables or disables External interrupt 1. If EX1=0, External interrupt 1 is disabled.
ET0 IE.1 Enables or disables the Timer Overflow interrupt. If ET0=0, the Timer 0 interrupt is
disabled.
EX0 IE.0 Enables or disables External interrupt 0. If EX0=0, External interrupt 0 is disabled.
INTERRUPT PRIORITY REGISTER [ IP]
(MSB) (LSB)
X X X PS PT1 PX1 PT0 PX0
Arithmetic Instructions
Logical Instructions
Boolean/Bitwise Instructions
Branching Instructions
Data Transfer Instructions:
DIV :Divide
DIV AB ;Fixed instruction
Dividend will be stored in A& divisor will be stored in B. After division, the quotient will
beheld with A& remainder with B.
Logical Instructions:
Branching Instructions:
Unconditional branch:
Program :
ADD R1,R2
It is invalid to memory registers directly
Program:
Mov A, R1
Add A, R2
PROGRAMS USING SUBROUTINES
Writing Delays in a Program Generate a wave at P1.5
ORG 00H
ACALL DELAY ; call a delay fro subroutine to make the state exist
for some time
SJMP Again ; Continue the signal
DELAY :
MOV R3, # 50
DJNZ R3, $ ; $ symbol puts the loop in the same line
(or)
BACK: DJNZ R3, BACK ;
RET
END
TIMERS
• 8051 has two 16-bit on-chip timers that can be used for timing durations
or for counting external events
• The high byte for timer 1 (TH1) is at address 8DH while the low byte
(TL1) is at 8BH
• The high byte for timer 0 (TH0) is at 8CH while the low byte (TL0) is at
8AH.
• Timer Mode Register (TMOD) is at address 88H
TIMER MODE REGISTER [ TMOD REG]
GATE C/T bar M1 M0 GATE C/T bar M1 M0
Timer 1 Timer 0
GATE When TRx is set and GATE=1,TIMER/COUNTER will run only while INTx pin is high (hardware control).When
GATE=0, TIMER/COUNTER will run only while TRX=1 pin is high(software control).
C/T bar Timer or Counter selector. Cleared for timer operation(input from internal system clock).Set for counter
operation(input from TX input pin)
Delay [ in ms or µ s] = [ Maximum count (16 or 8 bit) - Given Count + 1] x 1.085 µsec [ in Hexa-Dec]
MODE 2: used for Maximum of 8 bit count and used in Serial Data Communication [ 00 H - FF H]
Timer in Mode 1[ 16 bit] and Mode 0 [13 bit] Timer in Mode 2 [8 bit]
Formula for Delay is
Delay [ in ms or µ s] = [ Maximum count (16 or 8 bit) - Given Count + 1] x 1.085 µsec [ in Hexa-Dec]
Count = EE00 H
STEPS of Timer Programming
Generate a wave at P1.5 WITH 5 ms Delay
1. Select the timer [ 1 or 0] and its mode by TMOD Reg
2. Set the count by loading the Timer Regs. [ by calculating delay time]
3. START the Timer [ SETB TR]
4. Wait until TF is Raised [ BACK : JNB TF1, Back ]
5. Clear TR and TF for next time operation
ORG 00H P1.5
Again : SETB P1.5 ; Set the bit P1.5
ACALL DELAY ; call a delay fro subroutine to make the state exist 8051
for some time
CLR P1.5 ; Clear the bit P1.5 to 0
ACALL DELAY ; call a delay fro subroutine to make the state exist
for some time
SMOD PCON.7 Double baud rate bit. If SMOD=1,teh baud rate is doubled when the serial port is
used in mode1,2 and 3.
- PCON.6 Not implemented, reserved for future used*
- PCON.5 Not implemented, reserved for future used*
- PCON.4 Not implemented, reserved for future used*
GF0 PCON.3 General purpose bit.
GF1 PCON.2 General purpose bit.
PD PCON.1 Power Down bit. If set the oscillator is stopped. A reset or an interrupt(83C154 and
83C154D only) can cancel this mode(Note 1)
IDL PCON.0 IDLE bit. If set the CPU activity is stopped. A reset or an interrupt(83C154 can cancel
this mode(Note 1)
Timer frequency is the 12th part of the Operational Frequency of 8051 [ i.e 11.0592 MHz]
THI = 3
Count to be loaded in THI = FF – 3 = FC H [ always used in mode 2 of timer 1]
Serial Port Frequency is 32nd part of Timer Clock frequency
Timer frequency is the 12 th part of the Operational Frequency of 8051 [ i.e 11.0592 MHz]
THI = 3
Count to be loaded in THI = FF – 3 = FC H [ always used in mode 2 of timer 1]
Program to Transfer the word “ECE” at speed of 9600 baud rate
MOV TMOD, # 20 H; 0 0 10 0000 [ TIMER 1 IN MODE 2]
TRANS:
MOV SBUF,A ; Set data to go out from SBUF
SETB TR1 ; Start data transfer
Back: JNB TI, BACK ; wait for transfer complete
CLR TI
CLR TR1
RET
END
Conclusions:
1. Microcontrollers when compared with microprocessors share many synonymous names like ALU, Flags,
Timers, etc but differ in their arrangements and usage.
2. Intel 8051 is an early basic model which still, stands as an example to many new microcontrollers.
3. From its theoretical observations the major features stand as
Operational Frequency – 11.0592 MHz
Data width of 8 bit
Inbuilt Memories, Timers, Serial Ports , Interrupt Structures, I/O Ports.
4. It is the most beneficial and simple programmable controller for various types of Interfaces.