Vous êtes sur la page 1sur 47

A COURSE ON

BASIC EMBEDDED SYSTEM


TRAINING

What is an embedded
system?
It

is an information processing systems


embedded into a larger product.

It

can perform only that operations ,which it


is designed for

Lets checkout ,,,,,

Characteristics of embedded system


Must be dependable
Reliability
Maintainability
Safety
Security

Characteristics of embedded system


Must be efficient
Energy efficient
Code-size efficient (especially for systems on a chip)
Run-time efficient
Cost efficient
Dedicated towards a certain application

Dedicated user interface (no mouse, keyboard and screen).

What is the difference ?


Embedded Systems

General Purpose Computing

Few applications that are


known at design-time.

Broad class of applications.


Programmable by end user.

Not programmable by end


user.

Faster is better.

Fixed run-time requirements

Criteria:

Criteria:
cost
power consumption
predictability

cost
average speed

et us begin with
CHAPTER 1

DIGITAL FUNDAMENTALS

NUMBER REPRESENTATION
Decimal
0
1
2
3
4
5
6
7
8

Binary
0
01
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111

9
10
11
12
13
14
15
Base

Base 2

Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Base

NUMBER REPRESENTATION
Bit

0/1
0/1

Nibble

0
0 0
0 0
0 0
0

Byte

0
0 0
0 0
0 0
00
0 0
0 0
0 0
0

Word

0
0 0
0 0
0 0
00
0 0
0 0
0 0
00
0 0
0 0
0 0
00
0 0
0 0
0 0
0

Decimal to binary conversion


remainder

23

2
2

11

2
2

1
0

2310 =

BINARY TO DECIMAL CONVERSION

128

64

32

16

Place value

Binary value

0*128+ 0*64+1*32+0*16+ 1*8 + 0*4 +1*2 +0*1 =42

Decimal value

BINARY TO HEX CONVERSION


8

1*1+1*2+1*8=11
MSB

Result =

1*1+1*2
LSB =3

B3 H

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

BINARY NOT
LOGIC

1
0

Not lo
gic
comp
lemen
ts the
voltag
e leve
l

=0
=1

For what???

Binary or logic
1 0 1 1 0 0 0
0 0 0 0 0 1 1
1 0 1 1 0 1 1

For what???

Changing the voltage


level of a pin or value of
a bit without altering
others

Binary and logic

1 1
Masking:
bits
1 1Discarding
1
keeping needed bits
0 1 1 alive

For what ?

Binary xor logic


1

For what ?

Comparing two
sequences

TTL & CMOS

5 Volt Pin of IC

+ve of 1 at this O/P =5V with 60uA


Port OR Out Put
5V
source
-ve of of0aatDigital
this O/P = 0V with 1.6mA
Circuit
5V
sink
(3.2 ma for P0)

GND pin of IC

MICROCONTROLLER GENERAL VIEW

MEMORY ORGANIZATION

7F

INTERNAL RAM
R2
User Ram
0
B7

If r2=3C

Bit addressable Ram

Register bank
07 r7 r6 r5 r4 r3 r2 r1 r0

00
80 TO FF are SFRs

0
B0

3F12

MOV A,r0

3F13

ADD A,#0B
Program memory

Address of P.G

3F14

Address bus

How controller works.


DATA BUS

3F13
3F12
3F14

Program
counter

Instruction decoder

r0

0
EXECUTING

Reading
Decoding
command
commands
OR Fetch cycle

0
0
1
0
0
0
1
1

COMMANDS

1 Commands are binary words.

2. Each command has a specific work.

3. This work is done on MEMORY, REGISTERS,

4. These commands are stored in PROGRAM MEMORY.

5. Controller will read these commands


memory and execute.

6. The result of one command will not be changed


the execution of another command at the same
destination.

or PORTS.

from program

until

JUMP INSTRUCTION
LJMP and SJMP are used to Change the flow of
commands.
Program memory
1F0
0
1F01

ADD
ADD B,#F3
B,#F3
L JMP 3A20

1F02

3A20
Program counter
1F00
1F01
1F02

3A20

MOV A,r1

3A21

MOV P2,A

3A22

02CA

LCALL A018

02CB

MOV A,P2

02CC

vv

CALL Instruction
2101

Program Counter
2100
2101
2102

LCALL A108

A108
02CA
02CB
2100

0B
A108
A109
A10A

MOV A,@R1
RRA
RRA

A10B

RRA

A10C
A10D

RRA
RET

0A
07
07
08

09

Stack
Pointer.

07

08
STACK

Addressing.
1.

Addressing is to which or where OR from which


or where the command should act.
eg: ADD A,#0B
a. A is the address where the ADD
should act. (Register addressing)
b. #0B is not an address. But this method
is immediate addressing.

Expressions used in Instruction


Set and Addressing Modes
Rn:---- Register R7-R0
direct :------8-bit internal RAM address.
location (0-127) or a SFR
@Ri :-----8-bit internal data RAM location (0-255)
addressed indirectly through register

R1or R0.

#data :------8-bit constant included in instruction.


#data 16:------ 16-bit constant included in
instruction.

Expressions used in Instruction


Set and Addressing Modes
addr 16 :-------16-bit

address. Used by LCALL and LJMP. A

branch can be
anywhere within the 64K byte Program Memory address space.
addr 11:------- 11-bit destination address. Used by ACALL and
AJMP. The branch will be
within the same 2K byte page of program memory as the first byte
of the
following instruction.
rel :------Signed (twos complement) 8-bit offset byte. Used by
SJMP and all
conditional jumps. Range is -128 to +127 bytes relative to first byte
of the
following instruction.
Bit:----- Direct Addressed bit in Internal Data RAM or Special
Function Register.

Examples of instructions.
MOV A,Rn

Move register to Accumulator.


Eg:---MOV A, r2---- the contents of r2 will
move to Accumulator.

MOV A,direct ----

Move contents of RAM to A.


Eg:- MOV A, 6A ---the contents of RAM
location 6A will move to A

MOV

A, @Ri ---Contents of RAM indicated by Ri will


move to A.
Eg:-- MOV A, @r1--- If r1=3B, the
contents of RAM location 3B will move to A.

Examples of instructions.

* MOV

A, #direct---- move the data immediate to A.


eg:-- MOV A, #2B-- the content of A will
be 2B.
INC --- increment.
DEC---- Decrement.
MUL---- Multiply.
ANL -----Logical AND.
ORL --- Logical OR

INPUT OUTPUT PORTS

*OPEN COLLECTOR PORT0

OSCILLATOR

TIMER/COUNTER

SERIAL COMMUNICATION

COUNTERS & TIMERS

8051 has 2 timers/counters T0 and T1


They can measure time, count intervals, and
generate baud rate.

Timer T0

If the content of the timer T0 is equal to 0 (T0=0)


then both registers will contain 0. If the timer
number 2580 (hex), then the TH0 register (high
byte) will contain the number 25, while the TL0
register (low byte) will contain number 80. (Upon

TMOD Register(Timer Mode)

GATE enables and disables Timer by means of a signal brought to


the INTx pin
1 - Timer operates only if the INTx bit is set.
0 - Timer operates regardless of the logic state of the INTx bit.
C/T selects pulses to be counted up by the timer/counter :
1 - Timer counts pulses brought to the T0/T1pin
0 - Timer counts pulses from internal oscillator.
T1M1,T1M0
Timer0/1.
T1M1 T1M0
0 0 0
0 1 1
1 0 2
1 1 3

These two bits select the operational mode of the


MODE
DESCRIPTION
13-bit timer
16-bit timer
8-bit auto-reload
Split mode

TIMER-0 IN MODE 0 (13 BIT)

This mode configures timer 0 as a 13-bit timer which consists of all 8


bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses
only 13 of 16 bits.

TIMER-0 IN MODE 1(16 BIT)

Mode 1 configures timer 0 as a 16-bit timer comprising all the


bits of both registers TH0 and TL0. That's why this is one of the
most
commonly used modes.

TIMER-0 IN MODE 2 (8 BIT AUTO RELOAD)

TL0 register operates as a timer, while TH0 register stores the


value from which the counting starts.

TIMER-0 IN MODE 3(SPLIT MODE)

Mode 3 configures timer 0 so that registers TL0 and TH0 operate as


separate 8-bit timers. The TL0 timer turns into timer 0, while the TH0
timer turns into timer 1.

TCON Register(Timer Control)

TF1 bit is automatically set, on the Timer 1 overflow.


TR1 bit enables the Timer 1.
1 - Timer 1 is enabled.
0 - Timer 1 is disabled.
TF0 bit is automatically set, on the Timer 0 overflow.
TR0 bit enables the timer 0.
1 - Timer 0 is enabled.
0 - Timer 0 is disabled.

TIMER-0 PROGRAMMING
1 . M O D E C O N F I G U R AT I O N

The timer 0 operates in mode 1 and counts


pulses generated by internal clock the
frequency of which is equal to 1/12 the quartz

2.TURN ON TIMER

The TR0 bit is set and the timer starts operation. If the
quartz crystal with frequency of 12MHz is embedded then
its contents will be incremented every microsecond.

TIMER-0 OVERFLOW DETECTION


Constant reading of timer is in efficient.
Only need to monitor overflow* (FFFF 0000)
When it occurs, the TF0 bit of the TCON register will be
automatically set.
The state of this bit can be constantly checked from within the
program or by enabling an interrupt which will stop the main
program execution when this bit is set.

Delay using timer


Required delay = 0.05 seconds (ie 50,000 machine cycles,
0.05/1uS)
Assuming XTAL Freq = 12Mhz
Find value to be loaded into timer registers( TH & TL)

15536 3CB0

Timer T1

Timer 1 only have UART circuitry in


8051

Vous aimerez peut-être aussi