Documente Academic
Documente Profesional
Documente Cultură
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
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
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
P0.3[AD3]
P1.4
5 36
P1.5
6 35 P0.4[AD4]
P1.6
7 34 P0.5[AD5]
P1.7
8 33 P0.6[AD6]
RESET 9 32 P0.7[AD7]
P3.0 10 31 EA
P3.1 11 8051 30 ALE
P3.2 12 29 PSEN
P3.3 13 28 P2.7 [A15]
P3.4 14 27 P2.6 [A14]
P3.5 15 26 P2.5 [A13]
P3.6 16 25 P2.4 [A12]
P3.7 17 24 P2.3 [A11]
19 22 P2.1[A9]
XTAL1
20 21 P2.0 [A8]
GND
Operations of 8051 microcontroller
{ 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
P0.3[AD3]
P1.4
5 36
P1.5
6 35 P0.4[AD4]
P1.6
7 34 P0.5[AD5]
P1.7
8 33 P0.6[AD6]
RESET 9 32 P0.7[AD7]
P3.0 10 31 EA
(RXD)P3.0
(TXD)P3.1
P3.1 11 8051 30 ALE
(INT0)P3.2 P3.2 12 29 PSEN
(INT1)P3.3 P3.3 13 28 P2.7 [A15]
(T0)P3.4 P3.4 14 27 P2.6 [A14]
(T1)P3.5
(WR)P3.6
P3.5 15 26 P2.5 [A13]
19 22 P2.1[A9]
XTAL1
20 21 P2.0 [A8]
GND
Ports
• Port 0 - external memory access
• low address byte/data
• Port 2 - external memory access
• high address byte
• Port 1 - general purpose I/O
• pins 0, 1 for timer/counter 2
• Port 3 - Special features
• 0 - RxD: serial input
• 1 - TxD: serial output
• 2 - INT0: external interrupt
• 3 - INT1: external interrupt
• 4 - T0: timer/counter 0 external input
• 5 - T1: timer/counter 1 external input
• 6 - WR: external data memory write strobe
• 7 - RD: external data memory read strobe
INTERRUPTS
INTERNAL INTERRUPTS – 3
EXTERNAL INTERRUPTS
Immediate A M
MOV A, #05 h
# is a symbol used to represent a value to be immediate
Register A M
MOV A,R1
Direct A M
MOV A,05 H
Register Indirect A M
MOV A,@R1
Arithmetic Instructions
Logical Instructions
Boolean Instructions
Branching Instructions
Data Transfer Instructions:
MOV Move ; copy a data byte from a memory/ register
MOVC Move from Code [Internal ROM] memory
MOVX Move for External Memory[ RAM or ROM]
Push Reg number
Pop Reg Number [ only from BANK 0]
HLT halt ; Stop processing and wait
NOP No operation ; do not perfrom any operation
Arithmetic Operations:
ADD : addition
SUBB : subtract
INC : Increment
DEC : Decrement
MUL AB
DIV AB
Logical Instructions:
ANL : AND operation
ORL : OR
XRL: X-OR
CPL: complement
RL: Rotate Left
RLC : Rotate Left Through Carry
RR : Rotate Right
RRC: Rotate Right Through carry
BOOLEAN Instructions:
SETB ; Set a Bit
CLR ; Clear a bit
CPL ; Compliment
Branching Instructions:
Unconditional branch:
Jump instruction : SJMP [ 8 bit] , LJMP[ Long jump 16 bit] : Jump to the specific address
Conditional branch:
DJNZ : DECREAMENT AND JUMP IF NOT ZERO [syntax : DJNZ reg, label]
CJNE : COMPARE AND JUMP IF NOT EQUAL [ Syntax: CJNE Reg1, Reg2/Imm_value, Label]
A simple program:
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
LCD Interfacing with 8051
RS [Register Select]
If RS = 1
Command Register Vcc GND Vcc P2.7 P2.6 P2.5 P1.0 -- P1.7
( Setting Register)
If RS = 0
Data Register / Buffer Port 1 to Data Lines
RW [Read/Write]
1 = Read 8051
0 = Write
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]
TIMER CONTROL REGISTER [ TCON REG]
Timer frequency is the 12th part of the Operational Frequency of 8051 [ i.e 11.0592 MHz]
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
SJMP Again ; Continue the signal
DELAY :
MOV TMOD , # 10 H ; 0 0 01 0 0 00 [ Ex: TIMER 1 IN MODE 1]
MOV TL1, # 00 H
MOV TH1, # 0EE H ; COUNT EE00 H FOR A DELAY OF 5 ms
SETB TR1 ; START TIMER 1
BACK : JNB TF1, BACK ; WAIT UNTIL COUNT COMPLETES
CLR TR0
CLR TF1
RET
END
Serial Data Communication
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]
Program to Transfer the word “ECE” at speed of 9600 baud rate
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