58
RANSLAM INSTITUTE OF TECHNOLOGY & MANAGEMENT (MAWANA ROAD,MEERUT) TRAINING REPORT ON  EMBEDDED SYSTEM B.TECH(2011) (DEPA R TMENT OF ELECTRONICS AND COMMUNICA TION)

Complete Embedded Report

Embed Size (px)

Citation preview

Page 1: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 1/59

RANSLAM INSTITUTE OF TECHNOLOGY & MANAGEMENT

(MAWANA ROAD,MEERUT)

TRAINING REPORT

ON

 EMBEDDED SYSTEM 

B.TECH(2011)(DEPARTMENT OF ELECTRONICS AND COMMUNICATION)

Page 2: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 2/59

PERFACE 

First of all it is our proud to express our heartfelt gratitude to

supreme power . The almighty lord, the ultimate creator of thewhole world, who always guards us on the right path of life. 

Without his grace, this task of work would have never been to

a successful end.

We are wishing to express our heartfelt gratitude to my guide,who has been helpful to me in completing this training. We

intent our forthright thanks to staff of the cad arena who

 provide us the final tips that helped us to improve our 

 performance.Finally, we are indwelled to my parents for their love and

moral supports whose encouragement pushed us to achieve

this goal, without which we should have been able to fight out

all odds during my training.

Page 3: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 3/59

ACKNOWLEDGEMENTS

First and foremost, I would like to thank my respectedparents, who always encouraged me and taught me to

think and workout innovatively what so ever be the field

of life. My sincere thanks goes to Mr. Taz (Cad Arena,

Dehradun) for his prodigious guidance, persuasion, andpainstaking attitude, reformative and prudential

suggestion throughout my summer training schedule.

Last but not the least, my sincere thanks to all the staff 

members and friends for instilling in me a sense of self-

confidence.

Page 4: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 4/59

CONTENTS1. Introduction to Embedded System

1.1-Introduction

1.2-What is an Embedded System

1.3-Three criteria choosing Microcontroller 

2. Introduction to 8051 microcontroller2.1-Block diagram of 8051 Microcontroller 

2.2-Pin description of 8051 Microcontroller 

2.3-Pins of I/O Port

2.4-Hardware structure of I/O Pin

2.5-Other Pins

2.6-Port 3 Alternate Function

3. 8051 Timers/Counter3.1-Timer/Counter Programming

3.2-Timer 

3.3-Timer Modes3.4-Delay Length Factors

3.5-Timer Delay Calculation in sec

3.6-Findings THx and TLx when time is known

3.7-Counter 

4. 8051 Interrupts4.1-Interrupt Programming

 

Page 5: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 5/59

5. Serial Communication in 80515.1-Basics of Serial Communication

5.2-Packaging data (Start and Stop bits)

5.3-Serial Control (SCON) Ragister 

5.4-Modes of Operation

6. 8051 Registers6.1-TMOD Register 

6.2-TCON Register 

6.3-Interrupt Enable Register 

7. Programs Examples Using ³C´

7.1-Write a program to toggle all pins of P1 continously

7.2-Write a program to toggle bit D0 of Port P1 (P1.0) 50,000 times

7.3-Write a program to get a byte data from P0,if it is less than 100,send it to

Port1;otherwise send it to port27.4-Write a program to monitor a bit P1.5,if it is high send 55H to P0;otherwise send

AAH to P2

8. Application Of Embedded System

9. Summary

Page 6: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 6/59

Introduction toEmbedded Systems

Page 7: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 7/59

INTRODUCTION

The embedded systems is wide and

varied, and it is difficult to exact

definitions or descriptions. 

Chapter 1 introduces a useful model that

can be applied to any embedded system. 

Chapter 2 introduces and defines thecommon standard com ponents when

 building an embedded system. 

Page 8: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 8/59

What Is an Embedded System?

An embedded system is an applied computer system

"embedded   system", it constantly evolves with

advances in technology and dramatic decreasesin the cost of implementing various hardwareand software components. 

In recent years, the field has outgrown many of its traditional descriptions. 

Following are a few of the more commondescriptions of an embedded system:

Page 9: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 9/59

1. meeting the computing needs of the task efficiently and cost

effectively

speed, the amount of ROM and RAM, the number of I/O

 ports and timers, size, packaging, power consumption easy to upgrade

cost per unit

2. availability of software development tools

assemblers, debuggers, C compilers, emulator, simulator,technical support

3. wide availability and reliable sources of the microcontrollers.

Three criteria in Choosing a Microcontroller 

Page 10: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 10/59

Introduction to 8051

Microcontroller

Page 11: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 11/59

Block DiagramB

lock Diagram

CPU

On-chip

RAM

On-chip ROM

for program

code

4 I/O Ports

Timer 0

Serial

PortOSC

Interrupt

Control

External interrupts

Timer 1

Timer/Counter

Bus Control

TxD RxDP0 P1 P2 P3

Address/Data

Page 12: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 12/59

PinPin DescriptionDescription of of thethe 80518051

1

2

3

4

5

6

78

9

10

11

12

13

14

15

16

17

18

19

20

40

39

38

37

36

35

3433

32

31

30

29

28

27

26

25

24

23

22

21

P1.0

P1.1

P1.2

P1.3

P1.4

P1.5

P1.6P1.7

RST

(RXD)P3.0

(TXD)P3.1

(T0)P3.4(T1)P3.5

XTAL2

XTAL1

GND

(INT0)P3.2

(INT1)P3.3

(RD)P3.7

(WR)P3.6

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)

8051

(8031)

Page 13: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 13/59

Pins of 8051 (1/4)

Vcc pin 40

 ±Vcc provides supply voltage to the chip.

 ± The voltage source is +5V. GND pin 20ground

XTAL1 and XTAL2 pins 19,18

Page 14: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 14/59

Pins of 80512/4

RST pin 9reset

 ± It is an input pin and is active highnormally

low.

The high pulse must be high at least 2machine cycles.

 ± It is a power-on reset.

Upon applying a high pulse to RST, themicrocontroller will reset and all values in

registers will be lost.

Reset values of some 8051 registers

Page 15: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 15/59

Pins of 80513/4

/EA pin 31external access

 ± There is no on-chip ROM in 8031 and 8032 .

 ± The /EA pin is connected to GND to indicate the

code is stored externally.

 ± /PSEN

ALE are used for external ROM.

 ± For 8051, /EA pin is connected toVcc.

 ± ³/´ means active low.

/PSEN pin 29 program store enable

 ± This is an output pin and is connected to the OE pinof the ROM.

Page 16: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 16/59

Pins of 80514/4

ALE pin 30address latch enable ± It is an output pin and is active high.

 ± 8051 port 0 provides both address and data.

 ± The ALE pin is used for de-multiplexing theaddress and data by connecting to the G pin of the 74LS373 latch.

I/O port pins

 ± The four ports P0, P1, P2, and P3. ± Each port uses 8 pins.

 ± All I/O pins are bi-directional..

Page 17: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 17/59

Pins of I/O Port

The 8051 has four I/O ports ± Port 0 pins 32-39P0P0.0P0.7

 ± Port 1 pins 1-8  P1P1.0P1.7

 ± Port 2 pins 21-28P2P2.0P2.7

 ± Port 3 pins 10-17P3P3.0P3.7

 ± Each port has 8 pins.  Named P0.X X=0,1,...,7, P1.X, P2.X, P3.X

ExP0.0 is the bit 0LSBof P0

ExP0.7 is the bit 7MSBof P0

These 8 bits form a byte.

Each port can be used as input or output (bi-direction).

Page 18: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 18/59

Hardware Structure of I/O Pin

Each pin of I/O ports

 ± Internal CPU buscommunicate with CPU

 ± A D latch store the value of this pin

D latch is controlled by³Write to latch´

 ± Write to latch1write data into the D latch

 ± 2 Tri-state buffer 

TB1: controlled by ³Read pin´

 ± Read pin

1

really read the data present at the pin TB2: controlled by ³Read latch´

 ± Read latch1read value from internal latch

 ± A transistor M1 gate

Gate=

0: open Gate=1: close

Page 19: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 19/59

Other Pins P1, P2, and P3 have internal pull-up resisters.

 ± P1, P2, and P3 are not open drain.

P0 has no internal pull-up resistors and does notconnects to Vcc inside the 8051.

 ± P0 is open drain.

 ± Compare the figures of P1.X and P0.X. 

However, for a programmer, it is the same to programP0, P1, P2 and P3.

All the ports upon RESET are configured as output.

Page 20: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 20/59

Port 3 Alternate Functions

1717RDRDP3.7P3.7

1616WR WR P3.6P3.6

1515T1T1P3.5P3.5

1414T0T0P3.4P3.4

1313INT1INT1P3.3P3.3

1212INT0INT0PP33..22

1111TxDTxDP3.1P3.1

1010RxDRxDP3.0P3.0

PinPinFunctionFunctionP3 BitP3 Bit

Page 21: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 21/59

8051

timer/counter 

Page 22: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 22/59

Timers /Counters Programming

The 8051 has 2 timers/counters:

timer/counter 0

timer/counter 1

They can be used as

1. The timer is used as a time delay generator .

 ± The clock source is the internal crystal frequency of the

8051.

2.

An event counter .

 ± Ex ternal input from input pin to count the number of 

events on registers.

 ± These clock pulses cold represent the number of people

 passing through an entrance, or the number of wheel

rotations, or any other event that can be converted to

Page 23: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 23/59

Timer 

Set the initial value of registers

Start the timer and then the 8051 counts up.

Input from internal system clock (machine cycle)

When the registers equal to 0 and the 8051 setsa bit to denote time out

toLCD

P1

8051

TL0

TH0

P2SetTimer 0

Page 24: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 24/59

Timer Mode 1

In following, we all use timer 0 as an example.

16-bit timer (TH0 and TL0)

TH0-TL0 is incremented continuously when TR0 is set

to 1. And the 8051 stops to increment TH0-TL0 when

TR0 is cleared.

The timer works with the internal system clock . In

other words, the timer counts up each machine cycle.

When the timer (TH0-TL0) reaches its maximum of 

FFFFH, it rolls over to 0000, and TF0 is raised.

Programmer should check TF0 and stop the timer 0. 

Page 25: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 25/59

Delay length factors Timer freq.or Machine cycle frequency=1/12 clock frequency (when timer is used for generating delays)

AT89C51 : 12 clocks per machine cycle

DS89C4x0 : 1 clock per machine cycle Delay length depends upon

Crystal frequency

 No.Of clocks per machine cycle

C-compiler 

Page 26: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 26/59

Timer delay calculation in sec.

When the values of Thx and TLx are known :

Suppose hex value is YYXX = TH + TL

Calculation in HEX :

Step1 : [ FFFF-YYXX+1 ] x 1.085uS

Calculation in decimal :

Step1 : Convert YYXX into decimal NNNN.

Step2 : [ 65,536 ± NNNN ] x 1.085 uS

Page 27: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 27/59

Finding THx and TLx when time is

known :

For 11.0592 MHz XTAL frequency :

Step 1 : Desired time delay / 1.085 uS = n

in decimalStep 2 : 65,536 ± n = M

Step 3 : Convert M into hex value YYXX

Step 4 : THx =YY

Step 5 : Tlx = XX

Page 28: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 28/59

Counter 

Count the number of events

 ± Show the number of events on registers

 ± External input from T0 input pin (P3.4) for Counter 

0

 ± External input from T1 input pin (P3.5) for Counter 1

 ± External input from Tx input pin. 

 ± We use Tx to denote T0 or T1.

T0

toLCD

P3.4

P1

8051

a switch

TL0

TH0

Page 29: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 29/59

8051

Interrupts

Page 30: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 30/59

Interrupts Programming

An interrupt is an external or internal event thatinterrupts the microcontroller to inform it that a

device needs its service.

 I nterrupts vs. Polling 

A single microcontroller can serve several devices.

There are two ways to do that:

 ± interrupts

 ±  polling. The program which is associated with the interrupt is

called the interrupt  service routine (ISR) or interrupt 

handler .

Page 31: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 31/59

Steps in executing an interrupt

Finish current instruction and saves the PC on stack .

Jumps to a fixed location in memory depend on type

of interrupt

Starts to execute the interrupt service routine until

RETI (return from interrupt)

Upon executing the RETI the microcontroller returns

to the place where it was interrupted. Get pop PC

from stack 

Page 32: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 32/59

Interrupt Sources

Original 8051 has 6 sources of interrupts ± Reset

 ± Timer 0 overflow

 ± Timer 1 overflow

 ± External Interrupt 0

 ± External Interrupt 1

 ± Serial Port events (buffer full, buffer empty, etc)

Enhanced version has 22 sources ± More timers, programmable counter array, ADC, more

external interrupts, another serial port (UART)

Page 33: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 33/59

Interrupt Enable (IE) register 

All interrupt are disabled after resetWe can enable and disable them bye IE

Page 34: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 34/59

External interrupt type control By low nibble of Timer control register TCON

I  E0 (  I  E1 ): External interrupt 0(1) edge flag.  ± set  by CPU when external interrupt edge ( H-to-L) is detected. 

 ± Does not affected by H-to-L while ISR is executed(no int on int)

 ± C lear ed  by CPU when  R ET  I executed. 

 ± does not  latch low-level triggered interrupt

I T0 (  I T1 ): interrupt 0 (1) type control bit. 

 ± Set/cleared by software

 ± IT=1 edge trigger 

 ± IT=0 low-level trigger 

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Timer 1 Timer0 for Interrupt

(MSB) (LSB)

Page 35: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 35/59

Interrupt Priorities

What if two interrupt sources interrupt at the  same time?

The interrupt with the highest PR IO R I TY gets

serviced first .

All interrupts have a power on default  priority order . 

1. External interrupt 0 (INT0)

2. Timer interrupt0 (TF0)

3. External interrupt 1 (INT1)

4. Timer interrupt1 (TF1)

5. Serial communication (RI+TI)

Priority can also be set to³high´ or 

³low´ by

 I  P reg

.

Page 36: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 36/59

Interrupt Priorities (IP) Register 

IP.7: reserved

IP.6: reservedIP.5: timer 2 interrupt priority bit(8052 only)

IP.4: serial port interrupt priority bit

IP.3: timer 1 interrupt priority bit

IP.2: external interrupt 1 priority bit

IP.1: timer 0 interrupt priority bit

IP.0: external interrupt 0 priority bit

--- PX0PT0PX1PT1PSPT2---

Page 37: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 37/59

Serial

Communication

Page 38: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 38/59

Basics of serial communication

 Parallel : expensive - short distance ± fast ± no modulation

S erial  :cheaper± long (two different cities by modem)-slow

Page 39: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 39/59

Basics of serial communication

Page 40: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 40/59

Packaging DataStart and stop bits

In asynchronous transmission

When there is no transfer the signal is high

Transmission begins with a start (low) bit

LSB first

Finally 1 stop bit (high)Data transfer rate (baud  rate) is stated in b ps

Page 41: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 41/59

Serial control (SCON) Register:-

SM2 : used for multi processor communication

REN : receive enable (by software enable/disable)

TB8 : transmit bit8

R B8 : receive bit 8

TI : transmit interrupt flag set by HW after send , clear by SW

RI : receive interrupt flag set by HW after received ,clear by SW

SM0 RITIR B8TB8RENSM2SM1

7  6 5 4  3 2 1 0

SM0 SM1 MODE operation transmit rate

0 0 0 shift register fixed (xtal/12)

0 1 1 8 bit UART variable (timer1)

1 0 2 9 bit UART fixed (xtal/32 or xtal/64)

1 1 3 9 bit UART variable (timer1)

SM0 : mode specifier 

SM1 : mode specifier 

Page 42: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 42/59

Mode of operation

Mode 0 :

 ± Serial data enters and exits through Rx D

 ± T  x D outputs the shift clock .

 ± 8 bits are transmitted/received(LSB first)

 ± The baud rate is fixed a 1/12 the oscillator frequency.

Application

 ± Port expansion

8051

TXD

R XD Shift register clk 

data

Page 43: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 43/59

Mode of operation

Mode 1 ± Ten bits are transmitted (through TxD) or received (through RxD)

(A start bit (0), 8 data bits (LSB first), and a stop bit (1) )

 ± On receive, the stop bit goes into R B8 in SCON

 ± the baud rate is determined by the Timer 1 overflow rate.

 ± Timer1 clock is 1/32 machine cycle (MC=1/12 XTAL)

Timer clock can be programmed as 1/16 of machine cycle

Transmission is initiated by any instruction that uses SBUF

as a destination register .

Page 44: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 44/59

Mode of operation

Mode 2 : ±  E leven bits are transmitted (through TxD), received (through

RxD)

A start bit (0)

8 data bits (LSB first)

A programmable 9th data bit and a stop bit (1)

 ± On transmit, the 9th bit (TB8) can be assigned 0 or 1. 

 ± On receive, the 9the data bit goes into R B8 in SCON. 

 ± the 9th can be  parity bit

 ± The baud rate is programmable to 1/32 or 1/64 the oscillator frequency in Mode 2 by SM O D bit in  P C ON  register 

Mode 3  ± Same as mode 2

 ± But may have a variable baud rate generated from Timer 1.

Page 45: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 45/59

The 8051

Ragisters

Page 46: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 46/59

TMOD Register:

Gate : When set, timer only runs while INT(0,1) is high.

C/T : Counter/Timer select bit.

M1 : Mode bit 1.

M0 : Mode bit 0.

Page 47: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 47/59

Gate Every timer has a mean of starting and stopping.

 ± GATE=

0 I nternal control

The start and stop of the timer are controlled by way of  software.

Set/clear the TR for start/stop timer .

SETB TR0

CLR TR0

 ± GATE=1

Ex ternal control

The hardware way of starting and stopping the timer by software andan e x ternal source.

Timer/counter is enabled only while the INT pin is high and the TR 

control pin is set (TR).

GATE C/T M1 M0 GATE C/T M1 M0

Timer 1 Timer 0

(MSB) (LSB)

Page 48: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 48/59

TCON Register:

TF1: Timer 1 overflow flag. TR1: Timer 1 run control bit.

TF0: Timer 0 overflag.

TR0: Timer 0 run control bit.

IE1: External interrupt 1 edge flag. IT1: External interrupt 1 type flag.

IE0: External interrupt 0 edge flag.

IT0: External interrupt 0 type flag.

Page 49: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 49/59

TCON Register (1/2)

Timer control register: TMOD ± Upper nibble for timer/counter, lower nibble for 

interrupts

TR (run control bit)

 ± TR0 for Timer/counter 0; TR1 for 

Timer/counter 1.

 ± TR is set by programmer to turn timer/counter 

on/off .  TR =0: off (stop) TR =1: on (start)

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Timer 1 Timer0 for Interrupt

(MSB) (LSB)

Page 50: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 50/59

TCON Register (2/2)

TF (timer flag, control flag) ± TF0 for timer/counter 0; TF1 for timer/counter 1.

 ± TF is like a carry. Originally, TF=0. When TH-TL roll

over to 0000 from FFFFH, the TF is set to 1.

TF=0 : not reach

TF=1: reach

If we enable interrupt, TF=1 will trigger ISR.

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Timer 1 Timer0 for Interrupt

(MSB) (LSB)

Page 51: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 51/59

Interrupt Enable Register :

EA : Global enable/disable. --- : Undefined.

ET2 :Enable Timer 2 interrupt.

ES :Enable Serial port interrupt.

ET1 :Enable Timer 1 interrupt.

EX1 :Enable External 1 interrupt.

ET0 : Enable Timer 0 interrupt.

EX0 : Enable External 0 interrupt.

Page 52: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 52/59

Programs Examples

Using ³C´

Page 53: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 53/59

//Write an 8051 C program to toggle all the bits of P1

continuously.

 S olution:

#include <reg51.h>

void main(void){

for (;;) //Toggle P1 forever 

{

 p1=0x55; p1=0xAA;

}

}

Page 54: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 54/59

//Write an 8051 C program to toggle bit D0 of the port

P1 (P1.0) 50,000 times.

 S olution:

#include <reg51.h>

sbit MYBIT=P1^0;

void main(void)

{

unsigned int z;

for (z=0;z<=50000;z++){

MYBIT=0;

MYBIT=1;

}

Page 55: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 55/59

//Write an 8051 C program to get a byte of data form P0. If it

is less than 100, send it to P1; otherwise, send it to P2.

 S olution:

#include <reg51.h>

void main(void)

{unsigned char mybyte;

P0=0xFF;

while (1)

{mybyte=P0;

if (mybyte<100)

P1=mybyte;

else=  

Page 56: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 56/59

//Write an 8051 C program to monitor bit P1.5. If it is high,

send 55H to P0; otherwise, send AAH to P2.

 S olution:

#include <reg51.h>

sbit mybit=P1^5;

void main(void){

mybit=1; //make mybit an input

while (1)

{if (mybit==1)

P0=0x55;

else

P2=0xAA;

Page 57: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 57/59

Application Of Embedded System

Page 58: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 58/59

Applicaton Of Embedded System:-

Consumer Electronics

Medical.

Industrial Automation and Control

 Networking and Communications

Automotive.

Aerospace and Defense Commercial Office/Home Office

Automation

S

Page 59: Complete Embedded Report

8/3/2019 Complete Embedded Report

http://slidepdf.com/reader/full/complete-embedded-report 59/59

Summary An embedded system is a product that has one or more

computers embedded within it, which exercise primarily a

control function.

The embedded computer is usually a microcontroller: a

microprocessor adapted for embedded control applications.

Microcontrollers are designed according to accepted electronic

and computer principles, and are fundamentally made up of microprocessor core, memory and peripherals.

Microchip offers a wide range of microcontrollers, divided

into a number of different families. Each family has identical

central architecture and instruction set. However, common

features also appear across all their microcontrollers.

The Microchip 12F508 is a good microcontroller to introduce

a range of features of microcontrollers in general and of PIC

microcontrollers in particular .

h i h b d h