Sunteți pe pagina 1din 43

Definition of Embedded Systems:

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

It is used for multi processing It is used for Specific processing

Needs every circuitry externally Every feature is internally present

Very expensive Cost is very affordable


8051
DEVELOPED BY INTEL CORPORATION,
IN THE YEARS AROUND 1978-1980.

THERE ARE MANY OTHER CORPORATIONS THAT


DEVELOP MICROCONTROLLERS, LIKE,

PHILIPS
MOTOROLA
ZILOG, etc.,
Features of Intel 8051 Microcontroller: It is an 8-bit microcontroller

It is a 40 pin IC , 5 volts of Vcc


11.0592 MHz clock frequency [Operational Frequency]
8 bit data lines, 16 bit address lines

Memory: 4 KB ROM and 128 bytes of RAM [Internal Memory]

Up to 64 KB of ROM and RAM [External Memory]

I/O Ports : Four 8 bit I/O Ports

Timers : 2 Timers, each of size 16 bit

Serial Ports: 1 Serial Port

Interrupts: 5 Interrupts
Comparison with other basic versions of microcontrollers

Features 8031 8051 8052

Data 8 bit 8 bit 8 bit

RAM 128 bytes 128 bytes 256 bytes

ROM ----- 4 KB 4KB

Timers 2 2 3

Serial Port 1 1 1

Interrupts 3 5 6
Elevator

Req > floor

Going up
Timer < 10 sec

Timer = 10 sec

idle Door open

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

STACK POINTER BUFFER


A
Program
T1 T2
B Incrementer
TCON,TMOD,TH0,TL0
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
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]

XTAL2 18 23 P2.2 [A10]

19 22 P2.1[A9]
XTAL1
20 21 P2.0 [A8]
GND
Operations of 8051 microcontroller

Accumulator (8bit register)


B register
 R0,R1,R3,R4,R5,R6,R7 data memory registers
 Special Function Registers– TMOD TCON SCON SBUF, etc
 5 interrupts--- 2 timer, 2 external, 1 serial port
 2 timers
 4 bi directional 8 bit I/O ports total 32 pins of I/O ports
Port 0 [P0]
Port 1 [P1]
Port 2 [P2]
Port 3 [P3]
Program Status word [ PSW], Flag Register
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

2. 20 H – 2F H - Bit Addressable Area { Bank 3 – R0 – R7}

3. 30 H – 7F H – General Purpose Area { Bank 2 – R0 – R7}

{ 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]

(RD)P3.7 P3.6 16 25 P2.4 [A12]


P3.7 17 24 P2.3 [A11]

XTAL2 18 23 P2.2 [A10]

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

FROM TIMER 1 AND TIMER0


SERIAL PORT

EXTERNAL INTERRUPTS

FROM EXTERNAL PINS [ INT0 AND INT1]


INTERRUPT ENABLE REGISTER [ IE]
INTERRUPT PRIORITY REGISTER [ IP]
ADDRESSING MODES

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

@ is used to represent indirect addressing


Instruction Set :

Data Transfer Instructions

Arithmetic Instructions

Logical Instructions

Shift and Rotate 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

CALL Instruction : ACALL[ Absoulute call ] , LCALL [ 16 bit]: Call a subroutine

RET : Return from a Subroutine


RETI : Return from a interrupt sub routine

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:

ADD R1 =05 h and R2 = 03 H

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

Again : SETB P1.5 ; Set the bit P1.5


P1.5
ACALL DELAY ; call a delay fro subroutine to make the state exist
for some time
8051
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 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

E[ Enable] P2.7 to RS [Register Select]


P2.6 to RW [Read/Write]
Always toggle [ high to P2.5 to E[ Enable]
low]
Program
ORG 00H
MOV A, # 38 H ; SELECT LCD OF 2 X 16 [ 5X7 DIGIT]
ACALL COMMAND
Vcc GND VCCP2.7 P2.6 P2.5
MOV A, # 0E H ; DISPLAY ON CUSOR ON P1.0 -- P1.7
ACALL COMMAND COMMAND:
MOV A, #01 H ; CLEAR SCREEN MOV P1, A
ACALL COMMAND SETB P2.7 ; SELECT COMMAD REGISTER
MOV A, #06 H ; CURSOR GO RIGHT SIDE CLR P2.6 ; WRITE TO COMMAND REGISTER
ACALL COMMAND SETB P2.5
MOV A, #84 H ; 1ST ROW, 5TH COLUMN CLR P2.5 ; ENABLE H – L
ACALL COMMAND RET
ACALL DELAY DATA:
MOV P1, A
MOV A, # ‘E’ CLR P2.7 ; SELECT DATA REGISTER
ACALL DATA CLR P2.6 ; WRITE TO COMMAND REGISTER
ACALL DELAY SETB P2.5
MOV A, # ‘C’ CLR P2.5 ; ENABLE H – L
ACALL DATA RET
ACALL DELAY DELAY:
MOV A,#’E’ MOV R7, #255
ACALL DATA HERE: MOV R6, #255
DJNZ R6, $ ; LOOP IN THE SAME LINE UNTIL R6 IS 0
DJNZ R7, HERE
EXIT: SJMP EXIT
RET

END
TIMERS

Timer 1 [16 bit] Timer 0 [16 bit]


{ THI and TL1 (8 bit each)} { TH0and TL0 (8 bit each)

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]

So Timer frequency is 11.0592 MHz / 12

= 921.6 KHz = 1.085 µsec

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]

= [ Maximum count (16 or 8 bit) - Given Count + 1] x 1.085 µsec [ in DECIMAL]


MODE 0: used for Maximum of 13 bit count [ 0000 H - 1FFFH]

MODE 1: used for Maximum of 16 bit count [ 0000 H - FFFFH]

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]

= [ Maximum count (16 or 8 bit) - Given Count + 1] x 1.085 µsec [ in DECIMAL]

CALCULATE the Delay or Count using the Formula

Given Delay is 5 ms, calculate the Count Required

5 ms = [ 65535 - Count +1 ] x 1.085 µsec

4608= 65536 – count

Count = 65536 - 4608

Count = 60928 = EE00 H

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

• TxD: Port 3, pin 1


• Transmit data shifted out
• RxD: Port 3, pin 0
• Receive data shifted in
• Full duplex: both operate in parallel
• SBUF[8 – bit] – Serial Buffer is used for TxD and RxD operations
• We will use Mode 2 only
• asynchronous
• 10 bit transfer: 1 start, 8 data, 1 stop
• Look at documentation for other modes
• Clock for serial shift provided by timer 1
• i.e. programmable baud rate
• takes away a timer from other uses
Serial Port Control Register (SCON)

NOTE: SCON in 8051 is mostly 0 1 0 1 0 0 0 0 = 50 H


PCON REGISTER [ 8 BIT REG]

Note: For 8051 always SMOD is 0


Serial Port Frequency is 32nd part of Timer Clock frequency

Timer frequency is the 12th part of the Operational Frequency of 8051 [ i.e 11.0592 MHz]

So Timer frequency is 11.0592 MHz / 12

= 921.6 KHz = 1.085 µsec

Serial Port Frequency = 921.6 KHz / 32 = 28800 Hz

Baud Rate = {Osc Freq / Timer Freq}/ Ser_Freq x 2 SMOD / TH 1 value

Example: Baud Rate = 9600, then TH1 = ?, Assuming always SMOD = 0

So 9600 = 28800 x 1/ TH1  TH1 = 28800 / 9600

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]

MOV SCON , # 50 H ; 01(MODE1) 0 1(REN) 0000


STEPS of SERIAL PORT Programming
MOV TH1, #0FC H ; for baud rate 9600, TH1 = 3
1. Select the timer [ 1 ] and its mode 2 by TMOD Reg
MOV A, # ‘E’ 2. Set SCON reg in mode 1 as scon = 50 H
ACALL TRANS 3. Set the count in TH1 by loading the Timer Regs. [ by
MOV A, # ‘C’ calculating BAUD RATE]
ACALL TRANS 4. START the Timer1 [ SETB TR1]
MOV A,#’E’ 5. Wait until TI is Raised [ BACK : JNB TI, Back ]
ACALL TRANS
6. Clear TR and TI for next time operation
EXIT: SJMP EXIT

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

S-ar putea să vă placă și