DEEPAK 2307388

download DEEPAK 2307388

of 47

Transcript of DEEPAK 2307388

  • 8/8/2019 DEEPAK 2307388

    1/47

    Training Report

    On

    Embedded Systems

    (July 1th to 11th August)

    At

    EmTech Foundation, New Delhi

    Submitted in Partial Fulfillment of Requirementfor the award of degree of B.Tech

    in

    ELECTRONICS AND COMMUNICATION ENGINEERING

    Submitted By:

    Deepak Kumar(2307388)

    Submitted to:

    Electronics and Communication Engineering DepartmentAmbala College of Engineering and Applied Research

    Devsthali, near Mithapur, Ambala Cantt.(Affiliated to Kurukshetra University, Kurukshetra)

    (2009-10)

    1

  • 8/8/2019 DEEPAK 2307388

    2/47

    ACKNOWLEDGEMENT

    Any work of this nature would not have possible without support and guidance of

    others. It is important to acknowledge all those peoples who had a major influence on

    the conception & fruition of this report.I am very thankful to all those who helped me during my Practical Training

    at EMTECH FOUNDATION. I am very thankful to Mr. Naveen kumar (C.E.O), who

    allowed me six weeks training inEMTECH, Delhi. I am also thankful to Mr. Neeraj

    Kumar & Mr. Shubham Goyal (EMTECH Team members) who share their

    knowledge with me.

    My special thanks to Mr. Naveen kumar for engagingin many fruitful

    work and I am very grateful for his cooperation and help at various stages of my

    training period .

    I also thanks to the staff of EMTECH for their co-operation & guidance.

    Lastly I am thankful to the management for allowing me to do summer training in

    their organization.

    2

  • 8/8/2019 DEEPAK 2307388

    3/47

    TABLE OF CONTENTS

    CONTENTS PAGE

    NO.COMPANY PROFILE 1

    CHAPTER1: EMBEDDED SYSTEMS 2-13

    1.1 INSIDE THE CPU 3

    1.2 EMBEDDED PRODUCTS & THEIR CHRACTERSTICS 4

    1.3 EXAMPLES OF EMBEDDED SYSTEMS 6

    1.4 OTHER APPLICATIONS 9

    1.5 EMBEDDED SYSTEMS vs. GENRAL COMPUTING

    SYSTEMS

    10

    1.6 EMBEDDED MARKET GLOBALLY 10

    CHAPTER2 :MICROCONTROLLER 14-27

    2.1 IMPORTANT FEATURES & APPLICATIONS 14

    2.2 MICROPROCESSOR vs. MICROCONTROLLER 16

    2.3 TYPES OF MICROCONTROLLERS 16

    2.4 HISTORY OF THE 8051 18

    2.5 STANDARD FEATURES OF 8051

    MICROCONTROLLER

    20

    2.6 8051 ARCHITECTURE 22

    2.7 8051 REGISTERS 25

    CHAPTER3 : PROGRAMMING OF 8051 28-33

    3.1 LANGUAGES 28

    3.2 ADRESSING MODES 29

    3.3 TYPES OF INSTRUCTIONS 303.4 PROGRAMMING TOOLS 32

    CHAPTER 4 : INTERFACING DEVICES 34-38

    4.1 GENRAL INTERFACING DEVICES 34

    CHAPTER 5 : PROGRAMMING OF 8051 39-42

    REFRENCES 43

    LIST OF FIGURES

    3

  • 8/8/2019 DEEPAK 2307388

    4/47

    Figure No. Title Page No.

    1.1 EMBEDDED PRODUCTS 4

    1.2 HARDWARE 5

    1.3 SOFTWARE 61.4 EXAMPLES OF EMBEDDED SYSTEMS 7

    1.5 EMBEDDED IN ROBOTICS 8

    1.6 GENRAL APPLICATIONS 10

    1.7 EMBEDDED MARKETPLACE 11

    1.8 GROWTH RATE 12

    2.1 PROCESSORS RELATED TO 8051 15

    2.2 BLOCK DIAGRAM OF 8051 22

    2.3 PIN DIAGRAM OF 8051 23

    2.4 CONNECTION DIAGRAM 25

    4.1 RELAY CIRCUIT 35

    4.2 RELAY WORKING 36

    4.3 OPTOCOUPLER 36

    4.4 CONSTRUCTION OF OPTOCOUPLER 37

    4.5 LCD Connections 38

    LIST OF TABLES

    Table No. Title Page No.

    2.1 4-bit Microcontrollers 17

    2.2 8-bit Microcontrollers 17

    2.3 16-bit Microcontrollers 18

    2.4 Comparison of 8051 Family members 21

    4

  • 8/8/2019 DEEPAK 2307388

    5/47

    EmTech Foundation

    Introduction

    Embedded Technology Foundation (EmTech) was established in 2000 as a public

    sector Enterprise provides various services like:

    EMBEDDED SYSTEMS DESIGINING COURSES

    TRAINING ON 8051/PIC/AVR/ARM MICROCONTROLLERS

    5

  • 8/8/2019 DEEPAK 2307388

    6/47

    CAREER & JOB PLACEMENT PROGRAM FOR ENGINEERS

    SUMMER / WINTER INDUSTRIAL EMBEDDED SYSTEMS TRAINING

    FOR ENGINEERING STUDENTS

    Today EmTech Foundation is spread over five locations in Gurgaon, Faridabad,

    Greater Noida, Jodhpur, New Delhi having ISO-9001 accreditation.

    Embedded Technology Foundation also organize Training programs in different

    institutions for PCB designing, Embedded System Designing etc.

    Embedded Technology Foundation is UKs Board Affiliated ISO 9001:2000 Certified

    company Leaders in Embedded Technology Training provides training on Embedded

    Systems for Engineering Students & organize various Training workshops on

    Robotics, PCB Designing for Engineering students.

    CHAPTER 1

    INTRODUCTION

    An embedded system is a combination of hardware and software design to meet a

    specific need with performance in a given time frame. It is a specialized computer

    6

  • 8/8/2019 DEEPAK 2307388

    7/47

    system that is a part of larger system on machine. Typically an embedded system is

    housed on a single microcontroller board with programs stored in ROM. Virtually all

    appliances which have a digital interfacewatches, microwaves, carsutilize

    embedded systems include an operating system, but many are so specialized that the

    entire logic can be implemented as a single program. An embedded controller is a

    controller (or computer) that is embedded into some device for some purpose other

    than to provide general purpose computing. It is a special purpose system in which

    the computer is completely encapsulated by the device it controls. Unlike a general-

    purpose computer, such as a personal computer, an embedded system performs pre-

    defined tasks, usually with very specific requirements. Since the system is dedicated

    to a specific task, design engineers can optimize it, reducing the size and cost of

    product. Embedded systems are often mass produced, so the cost savings may be

    multiplied by millions of items. Hand held computers or PDAs are generally

    considered embedded devices because of the nature of their hardware design, even

    though they are more expandable in software terms. This line of definition continues

    to blur as devices expand. Embedded systems are a combination of hardware as well

    as software. The software written for embedded systems is often called firmware, and

    is stored in ROM or FLASH memory chips rather than a disk drive. It often runs with

    limited hardware resources: small or no keyboard, screen, and little RAM memory.

    Embedded systems are designed to do some specific task, rather than be a general

    purpose computer for multitasks. Some also have real-time performance constraints

    that must be met, for reasons such as safety and usability: others may have low or no

    performance requirements, allowing the system hardware to be simplified to reduce

    costs.

    1.1 INSIDE THE CPU :

    REGISTERS: These are used to store information temporarily, which could

    be address or data.

    7

  • 8/8/2019 DEEPAK 2307388

    8/47

    ALU: Arithmetic logic Unit- performs arithmetic operations such as addition,

    subtraction, division, multiplication and logical operations AND, OR, XOR,

    NOT

    PROGRAM COUNTER: It points to the next instruction to be fetched.

    Increases automatically with execution of each instruction.

    INSTRUCTION DECODER: Interprets the instructions fetched into CPU.

    DATA BUS:

    Used to carry information in and out of CPU.

    Increase in number of data buses increases speed as well as cost.

    Address bus:

    Used to identify the devices and memory connected to the CPU.

    Determines the number of locations which it can communicate

    No. of locations=2^X where X= number of address lines. Ex: 16 address lines

    make 64k of addressable memory.

    RAM:

    Random Access Memory

    Also known as Data Memory. This is a volatile memory and is used to store

    the data temporarily during the execution of a program.

    ROM:

    Read Only Memory

    This is a permanent memory. In Embedded systems (micro controllers) the

    ROM is FLASH ROM also known as CODE MEMORY. The program is

    stored in this memory, which doesnt have to remain same.

    1.2 EMBEDDED PRODUCTS & THEIR CHRACTERSTICS:

    8

  • 8/8/2019 DEEPAK 2307388

    9/47

    Fig. 1.1 EMBEDDED PRODUCTS

    CHARACTERISTICS OF EMBEDDED PRODUCTS:

    Perform single set of functions.

    Works in time constrained environment

    Provides high-performance and reliability

    Mostly embedded systems have low cost because they are mass produced in

    millions.

    Some embedded systems have mechanical moving parts such as disk drives as

    they are less reliable as compared to solid state parts such as Flash memory.

    How quickly an embedded design responds to a particular function key being pushed

    on an information appliance or to an event triggered by the appliance doesn't just

    depend on how well the device was designed. Nowadays it depends on things that

    used to be far outside the problem domain of traditional unconnected, or locally

    connected, embedded systems. In connected embedded systems, response time to an

    event depends on how fast the routers and the servers on the intranet, the virtual

    private network, or the World-wide Web can respond. This is especially true as

    companies such as IBM, Microsoft, and Sun shift to services-based models as a way

    to counteract the shift away from platform loyalty and take advantage of the Internet.

    They want to shift to a model in which software is maintained on a server and sell

    services on a transaction-by-transaction basis. The designer of a net-centric embedded

    device now has to deal with a problem domain as large and as complex as the servers

    and routers that link the device to the controlling system. In any design that depends

    on access to resources located remotely, as is proposed by a number of services-

    9

    INPUTSYSTEMS

    CONTROLLOGICS

    FEEDBACK/ERROR CONNECTION OUTPUT

    SYSTEMS

  • 8/8/2019 DEEPAK 2307388

    10/47

    oriented models for future Web activity, it will be necessary determine not just the

    parameters of the problem. You'll also have to look for sources of delay that require

    modifications of the way the various elements interact, which ones are related to the

    nature of the Internet medium, and which depend on the architecture of the various

    nodes. The architecture of the various computing devices will affect the performance

    parameters important to an embedded designer; specifically in the microprocessors at

    the heart of every server. Embedded designers are going to have to look closely at the

    architecture of the processors in that server-mediated chain of causality imposed on

    all connected net-centric computer systems. The demands that are placed on Web

    servers are much different now from even a year ago, and they will differ even more

    in a few years. Processor architectures will have to reflect that change. The nature of

    the server loads in the context of both present and future diverse.

    HARDWARE

    Fig 1.2

    SOFTWARE

    10

    PassivecomponentsResistance,

    Capacitance,Transistors etc.

    PassivecomponentsResistance,

    Capacitance,Transistors etc.

    Printed

    CircuitBoards(PCBs)

    Printed

    CircuitBoards(PCBs)

    Electro-

    mechanicalMotors,

    Valves etc.

    Electro-

    mechanicalMotors,Valves etc.

    Analog CircuitsOPAMP, ADC,

    DACetc.

    Analog CircuitsOPAMP, ADC,

    DACetc.

    Digital Circuits

    Decoder, latchesetc.

    Digital CircuitsDecoder, latches

    etc.

    HardwareHardware

  • 8/8/2019 DEEPAK 2307388

    11/47

    Fig 1.3

    1.3 EXAMPLES OF EMBEDDED SYSTEMS:

    Automatic teller machines(ATM)

    Cellular telephones and telephone switches

    Engine controllers and antilock brake controllers for automobiles

    Home automation products, such as thermostats, air conditioners, sprinklers,

    and security monitoring systems, handheld calculators.

    Household appliances, including microwave ovens, washing machines,

    television sets, DVD players

    Handheld computers

    videogame consoles

    Even computer peripherals themselves such as routers and printers have

    embedded processors.

    11

    Java/J2EEJava/J2EE

    Embedded C,C++

    Embedded C,C++

    AssemblyLanguage

    AssemblyLanguage

    MachineLanguage

    MachineLanguage

    SoftwareSoftware

  • 8/8/2019 DEEPAK 2307388

    12/47

  • 8/8/2019 DEEPAK 2307388

    13/47

    ROBOTICS:

    Fig 1.5 EMBEDDED IN ROBOTICS

    This is a Part I of a series of articles which is an attempt to introduce the reader into

    the world of embedded systems and their applications in the industry. I have decided

    to divide the topic into several parts that will be presented gradually as I complete

    them. The objective of the series will be a general discussion of embedded systems

    and what they are. In the process I will also show how to assemble a basic robot using

    a robotics kit provided by Parallax which will be controlled thru the BASIC Stamp II

    microcontroller. Towards the end of the series, I will start using the Microsoft

    Robotics Studio to illustrate some of the f features available thru the new IDE

    provided by Microsoft if time permits.

    13

  • 8/8/2019 DEEPAK 2307388

    14/47

    So what is an embedded system? In general terms, an embedded system is any device

    that includes a programmable computer for a specific task. Sometimes it is also said

    that, a computer. Embedded systems are found everywhere these days! Your cell

    phone, digital camera, portable video games, calculators, digital watches, and etc

    the list can go on for a really Long time. This gives you an idea of the broad

    application base of embedded systems.

    1.4 OTHER APPLICATIONS:

    14

  • 8/8/2019 DEEPAK 2307388

    15/47

    Fig 1.6 GENRAL APPLICATIONS

    1.5 EMBEDDED SYSTEMS VS. GENERAL COMPUTING

    SYSTEMS:

    An embedded system will have very few resources compared to GENERAL

    purpose computing systems like desktop computer.

    The memory capacity and processing power in an embedded system is limited

    It is more challenging to develop an application in embedded system due to its

    constricted environment as compared to developing the same for a desktop system

    Embedded system are dedicated to specific task

    ES can be implemented using wide variety of processors, even generic or custom

    Es are cost sensitive(but so are PC)

    Es operate have real time constraints

    Es have environmental constraints (i.e. supposed to work in diverse environmental

    conditions)

    Es usually run out of ROM

    Es have resource constraints

    Es are infrequently reprogrammed

    Es often work in reactive mode

    Es have hard reliability and correctness constraints.

    1.6 EMBEDDED MARKET GLOBALLY:

    15

  • 8/8/2019 DEEPAK 2307388

    16/47

    The world market for embedded systems development is around $250

    billion and is expected to grow at a CAGR of 26%

    Cisco, Wind River Systems, Sun Microsystems, Integrated Systems,Microware Systems, and QNX Software Systems are among the prominent

    developers of embedded systems.

    According to a study, for future of Embedded Systems Technologies, the

    market for embedded systems is expected to grow at an average annual

    growth rate (AAGR) of 16% over the period.

    Fig 1.7 EMBEDDED MARKETPLACE

    16

  • 8/8/2019 DEEPAK 2307388

    17/47

    GROWTH RATE:

    Embedded Processor will grow at 11.2% on average per year

    Embedded Memory products will rise at an AAGR of 17.7%.

    Embedded Boards will see a respectable AAGR of 13.1%.

    Embedded Software will average annual growth rate (AAGR) of 16%.

    Fig 1.8 GROWTH RATE

    WHY THE MARKET OF EMBEDDED SYSTEMS IS BOOMING??

    Embedded products are no more limited just to the high-end technology

    related tools. They are very much an integral part of our life today.

    Everyday home appliances, phones, toys, entertainment systems and

    printers, though find extensive use of embedded systems, are first

    generation systems.

    The advent of the internet and the need for convergence has ushered a new

    era in the field of embedded systems.

    17

    0

    2

    4

    68

    10

    12

    14

    16

    18

    growth

    Rate

    1st

    Qtr

    2004

    Embedded

    ProcessorEmbeddedMemory

    EmbeddedBoards

  • 8/8/2019 DEEPAK 2307388

    18/47

    The embedded systems applications will branch out areas as diverse as

    wireless, internet and mobile communications, industrial control, test and

    measurement, networking, aerospace and automotive control, consumer

    electronics, digital imaging and defence

    Exciting Career opportunities:

    15% of HCL staff is working on embedded systems. It contributes more

    than 30% of HCL Technologies revenues.

    Wipro has around 4,000 people in embedded systems. If the telecom

    services are included then the number goes up to 9000.

    18

  • 8/8/2019 DEEPAK 2307388

    19/47

    CHAPTER 2

    MICRONTROLLER

    INTRODUCTION:

    Microcontrollers are single chip computers. The Intel 8051 is a single chip

    microcontroller (C) which was developed by Intel in 1980 for use in embedded

    systems. Intel's original versions were popular in the 1980s and early 1990s, but has

    today largely been superseded by a vast range of faster and/or functionally enhanced

    8051-compatible devices manufactured by more than 20 independent manufacturers

    including Atmel, Infineon Technologies (formerly Siemens AG), Maxim Integrated

    Products (via its Dallas Semiconductor subsidiary), NXP (formerly Philips

    Semiconductor), Winbond, ST Microelectronics, Silicon Laboratories (formerly

    Cygnal), Texas Instruments and Cypress Semiconductor. Intel's official designation

    for the 8051 family of Cs is MCS 51.Intel's original 8051 family was developed

    using NMOS technology, but later versions, identified by a letter "C" in their name,

    e.g. 80C51, used CMOS technology and were less power-hungry than their NMOS

    predecessors - this made them eminently more suitable for battery-powered devices.

    2.1 Important features and applications

    It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer,

    etc.) in a single package

    8-bit data bus - It can access 8 bits of data in one operation (hence it is an 8-bitmicrocontroller)

    16-bit address bus - It can access 216 memory locations - 64 kB each of RAM

    and ROM

    On-chip RAM - 128 bytes ("Data Memory")

    On-chip ROM - 4 kB ("Program Memory")

    Four byte bi-directional input/output port

    UART (serial port)

    Two 16-bit Counter/timers

    19

  • 8/8/2019 DEEPAK 2307388

    20/47

    Two-level interrupt priority

    RELATED PROCESSORS:

    The 8051's predecessor, the 8048, was used in the keyboard of the first IBM PC,

    where it converted keypresses into the serial data stream which is sent to the main unit

    of the computer. The 8048 and derivatives are still used today for basic model

    keyboards.The 8031 was a cut down version of the original Intel 8051 that did not

    contain any internal program memory (ROM). To use this chip external ROM is to be

    added that will contain the program that the 8031 will fetch and execute.The 8052

    was an enhanced version of the original Intel 8051 that featured 256 bytes of internal

    RAM instead of 128 bytes, 8 kB of ROM instead of 4 kB, and a third 16-bit timer.

    The 8032 had these same features except for the internal ROM program memory. The

    8052 and 8032 are largely considered to be obsolete because these features and more

    are included in nearly all modern 8051 based microcontrollers.

    20

  • 8/8/2019 DEEPAK 2307388

    21/47

    Fig. 2.1 PROCESSORS RELATED TO 8051

    2.2 Microprocessor vs. Microcontroller

    In short microcontroller can be defined as:

    True computer on a chip

    Specific-purpose digital computers

    Design incorporates all the features of a microprocessor like ALU, PC, SP and

    registers along with RAM ROM, parallel I/O, serial I/O,, timers, clock circuits

    ADC etc

    2.3 Types of microcontroller:

    4 BIT MICROCONTROLLERS:It is the most popular microcontroller made in

    terms of production. It is most economical and cheaper. It is mainly applicable to toys

    and small appliances

    21

    CPU RAM

    ROM

    I/O TIMERSERIAL

    COMPORT

    CPU

    General

    purposeuP

    RAM

    ROM

    I/O

    TIMER

    SERIAL

    COM

    PORT

    Address Bus

    Data Bus

    MICRPROCESSOR MICRCONTROLLER

    1. Contains no on chip RAM, ROM, I/O,

    TIMER, Serial port .

    1. Contains on chip RAM, ROM, I/O,

    TIMER, Serial port .

    2. Used in General Purpose applications 2. Used in Specific Purpose applications

    3. Dont provide data storage facility. 3. Provides data storage facility.

    4. The structure of uP is as given below 4. The structure of uC is as given below

  • 8/8/2019 DEEPAK 2307388

    22/47

    Table 2.1 4-bit Microcontrollers

    8 BIT MICROCONTROLLERS: It represents the transition zone between

    dedicated, high volume, 4 bit microcontrollers and the high performance 16 bitmicrocontrollers. 8-bit word size adequate for many computing tasks and control or

    monitoring applications it is applicable to simple appliances control, high speed

    machine control, data collection etc.

    Table 2.2 8-bit Microcontrollers

    16 BIT MICROCONTROLLERS: It provides faster and more sophisticated

    calculations. It is applicable to control of servomechanisms like robot arms.

    22

    Serial bit I/O2K128242:35Toshiba: TLCS47

    LED display1K6428:23TI: TMS 1000

    1K3216:11OKI: MSM6411

    Serial bit I/O1K64128:23National: COP42

    10 bit ROM5123228:10Hitachi: HMCS40

    Otherfeatures

    ROM

    (bytes)

    RAM

    (bytes)CountersPins: I/O

    Manufacturer:

    Model

    8-channel AD; very low cost4K256228:22Zilog : Z86C83

    Ext memory to 124K; serial port2K128240:32Zilog : Z8

    serial port; ADC; WDT8K256368:48Philips : 87C552

    2K64140:32Rockwell : 6500/1

    serial ports; ADC; WDT8K256252:40Motorola : 68HC11

    1K64128:20Motorola : 6805

    serial bit I/O1K64128:24National : COP820

    25/20 ma sink/source; WDT1K25018:12Microchip:PIC16C56

    Ext memory to 128K;serial port4K128240:32Intel : 8051

    Ext memory to 8K1K64140:27Intel : 8048

    Other featuresROM

    (bytes)

    RAM

    (bytes)CountersPins: I/O

    Manufacturer:

    Model

  • 8/8/2019 DEEPAK 2307388

    23/47

    Table 2.3 16-bit Microcontrollers

    32 BIT MICROCONTROLLERS: The design emphasis is more on high speed

    computation features and not on chip features like RAM, ROM, and Timers etc. it is

    applicable to robotics, highly intelligent instrumentation, avionics, image, processing,

    telecommunications, automobiles

    Example: Intel 80960, ARM

    2.4 History of the 8051

    Developed by Intel Corporation in the year 1981.

    First 8-bit microcontroller called as 8051

    It was called as a System on a chip

    Intel refers to it as MCS-51

    In 2005, the 8051 microcontroller celebrated it's 25th anniversary. Intel introduced a

    Single-chip processor, the 4004, in 1971. It was a 4-bit microprocessor, with

    whopping processing speed of 100 thousand operations per second, and was meant for

    23

    Ext memory to 64K; serial port; A/D;PWM

    16K512468:52National:HPC1616

    4

    Ext memory to 64K; serial port; A/D;PWM; WDT

    8K232268:40Intel:80C196

    Ext memory to 1M; serial port; A/D;PWM

    32K1K584:65Hitachi:H8/532

    Other features

    ROM

    (bytes)

    RAM

    (bytes)

    Counters

    Pins:I/O

    Manufacturer:

    Model

    132 Pin ceramic package efficient procedure calls20 MHz clock Fault handling capability

    32 Bit bus Trace events

    Floating point unit Global registers

    512 Byte instruction cache efficient interrupt vectors

    Interrupt control versatile addressing

    Hardware features Software features

  • 8/8/2019 DEEPAK 2307388

    24/47

    an electronic calculator. There is a lot of 4-bit processing in calculators, especially if

    the software is based on BCD arithmetics. Later Intel introduced the 8-bitter 8008

    and it's grown-up brother - the famous 8080 (which then was perfected by an ex-Intel

    employee as Ziploc Z80, one of the best 8-bit microprocessors of all times).

    In 1976, Intel introduced its first microcontroller, 8048. It integrated the processing

    core with code and data memory and certain peripherals. The code memory was a

    1kB mask ROM (defined by the last metallization mask during the chip processing) or

    EPROM (after all, Intel invented EPROM), the data memory was 64 bytes of RAM

    (including the 8-level stack and two pages of eight general purpose registers). Besides

    general-purpose I/O (see below), peripherals included a timer and an external

    interrupt (plus the necessary interrupt system).Although the 8048 is clearly an 8-bit

    architecture, it is said to be an ancestor of the 4-bit 4004 Rather than the 8080. Also it

    is said to bear remarkable similarities to Fairchild F8 microprocessor.

    8051: The Classics.

    In 1980, Intel introduced the successor to 8048, the 8051.Intel made sure that the

    transition from the already successful model will be as smooth as Possible.

    Architecturally, the 8051 is an extension to 8048. Almost every resource of

    8048 is present in 8051 in same or superior form. 4kB ROM and 128B RAM on chip.

    Pin Compatibility was not maintained, but it was not a real issue. Software

    compatibility is not binary wise but source-wise, but that is also acceptable. The

    preliminary datasheet read: "Enhanced MCS-48 Architecture".

    The extensions included code and data memory extended to 64kB with appropriate

    support in Instruction set and registers (DPTR), relative conditional and unconditional

    jumps (conditionals and DJNZ were constrained within a 256-byte page in 8048), four

    register banks instead of two, unlimited" stack (8048 had stack limited to 16 bytes),

    multiple and divide instructions. As for peripherals, second timer was added and both

    were extended to 16 bits with multiple modes

    (Including 8-bit auto reload mode), and an UART (which was a luxury that many

    lower-end microcontrollers didn't have even a couple of years ago). The raw clock

    frequency did not increase considerably, being 12MHz, but an instruction cycle is 12

    clocks now.

    24

  • 8/8/2019 DEEPAK 2307388

    25/47

    2.5 Standard Features of 8051 Microcontroller:

    8 Bit data path and ALU.

    On chip flash memory.

    4K X 8 ROM - Program memory.

    128 x 8 RAM - Data memory.

    Multiple 16-bit Timer/Counter.

    Full duplex UART (Serial port).

    On chip clock oscillator.

    32 I/O pins

    Six Interrupt sources

    Introduced by Intel Corporation in 1981 as MCS 51

    Main features of MCS 51:

    Intel allowed other manufacturers to make and market any version of 8051

    depending upon the speed and on chip ROM

    All versions code compatible

    Other members of the 8051 family: 8052, 8031

    25

    ROM 4K bytes

    RAM 128 bytes

    Timer 2

    I/O Pins 32

    Serial port 1

    Interrupt sources 6

    Feature Quantity

  • 8/8/2019 DEEPAK 2307388

    26/47

    COMPARISON OF 8051 FAMILY MEMBERS:

    Table 2.4 Comparison of 8051 family members

    128 bytes of RAM, a timer and extra 4K bytes of on chip ROM. 8051 is an upward

    compatible to 8052.

    MICROCONTROLLER (AT89S52)

    The AT89S52 is an upgraded version of the micro controller 8051. the main features

    of 8051 are given as under:8051 micro controller has 128 bytes of RAM, 4K bytes of

    on-chip ROM, two timers, one serial port, and four ports (each 8-bits wide) all on a

    single chip. The 8051 is an 8-bit processor i.e. the CPU can work on only 8 bits of

    data at a time. The fixed amount of on-chip ROM, RAM, and number of I/O ports in

    microcontroller makes them ideal for many applications in which cost and space are

    critical.

    FEATURES OF THE AT89S52:

    Feature Quantity

    ROM 4K bytes

    RAM 128 bytes

    26

    ROM 4K 0K 8K

    RAM (bytes) 128 128 256

    Timers 2 2 3

    I/O Pins 32 32 32

    Serial Port 1 1 1

    Interrupt Sources 6 6 8

    Feature 8051 8031 8052

  • 8/8/2019 DEEPAK 2307388

    27/47

    Timer 2

    I/O pins 32

    Serial port 1

    Interrupt sources 6

    The only differences in 89S52 and 8051 is that of on-chip ROM and RAM, timers and

    interrupts. Both the micro controllers are based on the high power CISC architecture

    of INTEL-MCS-51.

    2.68051 ARCHITECTURE:

    The 8051 family is one of the most common microcontroller architectures used

    worldwide. 8051 based microcontrollers are offered in hundreds of variants from

    many different silicon manufacturers. The 8051 is based on an 8-bit CISC core with

    Harvard architecture. The 8051 family is one of the most common microcontroller

    architectures used worldwide. 8051 based microcontrollers are offered in hundreds of

    variants from many different silicon manufacturers. The 8051 is based on an 8-bit

    CISC core with Harvard architecture

    BLOCK DIAGRAM OF UC 8051 :

    27

    CPU

    INTERRUPT

    CONTROL

    OSC

    ON CHIPRAM

    BUSCONTRO

    L

    SERIALPORT4 I/O PORTS

    ON-CHIP

    FLASH

    ETC.

    TIMER1

    TIMER0

    COUNTER

    INPUT

    EXTERNAL

    INTERRUPTS

    P0 P2 P1 P3TXD RXD

    ADDRESS/DA

    TA

  • 8/8/2019 DEEPAK 2307388

    28/47

    Fig 2.2BLOCK DIAGRAM OF 8051

    PIN DIAGRAM:

    Fig. 2.3 PIN DIAGRAM OF 8051

    PIN DESCRIPTION :

    Port 1- Pins (1-8) :

    Input/output pins

    Contains internal pull-ups.

    Port 3- Pins (10-17)

    Input/output pins.

    28

    1 40

    2 39

    3 38

    4 37

    5 36

    6 35

    7 34

    8 33

    9 32

    10 31

    11 30

    12 29

    13 28

    14 27

    15 26

    16 25

    17 24

    18 23

    19 22

    20 21

    P1.0

    P1.1

    P1.2

    P1.3

    P1.4

    P1.5

    P1.6

    P1.7

    RST

    (RXD) P3.0

    (TXD) P3.1

    (INT0) P3.2

    (INT1) P3.3

    (T0) P3.4

    (T1) P3.5

    (WR) P3.6

    (RD) P3.7

    XTAL2

    XTAL1

    GND

    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)

  • 8/8/2019 DEEPAK 2307388

    29/47

    Contains internal pull-ups.

    Alternate functions to provide signals such as interrupts.

    Port 2- pins (21-28) :

    Input/output port.

    Contains internal pull-ups.

    Used both as I/O port and higher address byte

    Port 0- Pins (32-39):

    Input/output pins.

    Required external Pull- up resisters of 10 k.

    Used both as I/O port and higher address byte

    PSEN- (pin 29): Program store enable

    Active low input

    Used while accessing external memory.

    Connected to OE pin of external ROM.

    ALE- (pin 30) : Address Latch Enable

    Active high.

    Used for de-multiplexing the address and data by connecting G pin of the

    74LS373.

    EA- (pin 31):

    Active low input.

    To access external ROM, it must be GND.

    XTAL1and XTAL2 - (pin 19 and pin 18):

    Provides clock to quartz crystal oscillator.

    29

  • 8/8/2019 DEEPAK 2307388

    30/47

    Fig. 2.4CONNECTIONS DIAGRAM

    RST- (pin 9) : Reset

    Active high input.

    Terminate all activities of uc.

    Sets PC to 0.

    Requires minimum 2 machine cycles.

    VCC - (pin 40): Power supply

    GND (pin 20): Ground

    2.7 8051 REGISTERS:

    GENERAL PURPOSE REGISTERS:

    REGISTERS (R0-R7): Set of 8 auxiliary registers, namely R0-R7

    There are 4 such banks in lower RAM.

    Data Pointer (DPTR): Made of two 8-bit registers, namely DPH and DPL.

    30

  • 8/8/2019 DEEPAK 2307388

    31/47

    Used to furnish memory address for internal and external code access and external

    data access.

    Program Counter (PC): 16-bit register holds the address of the next program

    instruction to be executed, automatically Incremented after each instruction fetch.

    Stack Pointer (SP): 8-bit register, used to hold an internal RAM Address called the

    top of the stack.

    Special Function Registers

    CPU REGISTER:ACC : Accumulator.

    - B : B registers.

    - PSW : Program Status Word.

    - SP : Stack Pointer.

    - DPTR : Data Pointer (DPH, DPL).

    INTERRUPT CONTROL:

    -IE : Interrupt Enable.

    -IP : Interrupt Priority.

    I/O PORT:

    - P0 : Port 0.

    - P1 : Port 1.

    - P2 : Port 2.

    - P3 : Port 3.

    TIMERS:

    - TMOD: Timer mode.

    - TCON : Timer control.

    - TH0 : Timer 0 high byte.

    - TL0 : Timer 0 low byte.

    - TH1 : Timer 1 high byte.

    31

  • 8/8/2019 DEEPAK 2307388

    32/47

    - TL1 : Timer 1 low byte.

    SERIAL I/O:

    - SCON : Serial port control.- SBUF : Serial data registers.

    OTHER:

    - PCON : Power control & misc.

    32

  • 8/8/2019 DEEPAK 2307388

    33/47

  • 8/8/2019 DEEPAK 2307388

    34/47

    COMMENT:

    Begin with semicolon comment indication.

    Comments should be small and meaningful.

    Assembler ignores comments, but they are indispensable to programmer.

    HIGH LEVEL LANGUAGES

    The language whose instruction set is more compatible with human languages

    and human thought processes

    HLL offers three significant advantages over machine/assembly language.

    SIMPLICITY.UNIFORMITY.PROBABILITY

    HLL the programmer need not to be concern with internal detail ofmicroprocessor and microcontroller

    3.2 ADDRESSING MODES

    IMMEDIATE ADDRESSING MODE: The operand comes immediately after the opcode.

    Immediate data must be preceded by the pound sign (#).

    Can be used to load information into any of the registers and

    memory locations.

    MOV 30H, #23H

    MOV A, #25H

    MOV R0, #65H

    REGISTERS ADDRESSING MODES:

    Involves the use of registers to hold the data to be

    manipulated.

    MOV A, R0

    MOV R1, A

    MOV A, R6

    34

  • 8/8/2019 DEEPAK 2307388

    35/47

    DIRECT ADDRESSING MODE:

    The data in the RAM memory location and whose address is

    known.

    The address is given as apart of instruction

    MOV 30H, A : Save content of A in RAM

    MOV R0, 24H

    MOV A, 28H

    REGISTER INDIRECT ADDRESSING MODES:

    A register is used as a pointer to the data.

    As the register hold the address of RAM location they must be proceeded by

    @ sign.

    Only register R0, R1 are used for this purpose.

    MOV A, R0; Move the content of Ram location whose address is

    Held by R0 into A.

    MOV @R1, B; Move contents of B into RAM location whose

    Address is held by R1.

    INDEXED ADDRESSING MODE:

    Used in accessing data elements of look-up table located in ROM space.

    The 16-bit register DPTR and ACC are used to form the address of data

    element stored on a chip ROM.

    The instruction used foe this purpose is

    MOV A, @A+DPTR

    3.3 TYPES OF INSTRUCTIONS:

    Arithmetic instructions:

    Mnemonic Operands Bytes/cycle

    35

  • 8/8/2019 DEEPAK 2307388

    36/47

    ADD A, Rn 1/1

    ADDC A, direct 2/1

    SUBB A, @ RI 1/1

    A, #Data 2/1

    INC A 1/1

    DEC Rn 1/1

    Direct 2/1

    @ RI 2/1

    INC DPTR 1/2

    MUL AB 1/4

    DIV AB 1/4

    DA A 1/1

    LOGIC INSTRUCTIONS

    Mnemonic Operands Bytes/Cycle

    ANL A, R 1/1

    ORL A, direct 2/1

    XRL A,@Ri 1/1

    A, #data 2/1

    Direct, A 2/1

    Direct, #data 3/2

    C, bit 2/2

    C, /bit 2/2

    CLR A 1/1

    CPL C 1/1

    Bit 2/1

    36

  • 8/8/2019 DEEPAK 2307388

    37/47

    RL A 1/1

    RLC A 1/1

    RRC A 1/1

    SWAP A 1/1

    SETB C 1/1

    DATA TRANSFER INSTRUCTION

    Mnemonic operands Bytes/Cycles

    MOV A, Rn 1/1

    A, direct 2/1

    A, @ RI 1/1

    A, #data 2/1

    Rn, A 1/1

    Rn, direct 2/2

    Rn, #data 2/1

    Direct, A 2/1

    Direct, Rn 2/2

    Direct, direct 3/2

    Direct, @ RI 2/2

    Direct, #data 3/2

    MOVC A, @ A+DPTR 1/2

    A, @ A+PC 1/2

    PUSH Direct 2/2

    POP direct 2/2

    XCH A, Rn 1/1

    XCHD A,@ Ri 1/1

    3.4 PROGRAMMING TOOLS

    EDITOR: It provides the facility to write the programs and then immediate

    assemble or compile the program. It gives us the facility to create new text,

    open existing text and save the written text.

    37

  • 8/8/2019 DEEPAK 2307388

    38/47

    ASSEMBLER: Assembler is software which convert assembly language

    program into machine language program called object code. After assembling

    it generates a number of files

    Asm file---lst file---Obj file---Link file---Hex file ASSEMBLING A PROGRAM:

    The program developed by the programmer is stored as asm file

    The assembler converts the source file into machine code and produce an

    object file and list file

    The linker links all the object files and produces link files

    The link file is fed into an OH (object to hex converter) which creates a

    hex file.

    The hex file is programmed into the ROM

    COMPILER:

    A compiler is a program that translates a high level language program to

    machine level language instructions

    A compiler may use an assembly language as an intermediate step in the

    translation or may translate the program directly to machine code

    After assembling the code it generates a number of files like c file, asm

    file, lst file, obj file, rel file, link file, hex file etc depending on the

    compiler.

    The most popular microcontroller compilers are SDCC, READS, (PIC),

    PL/M, from Intel and many more,

    PROGRAMMER:

    Programmer is a device used to program the hex file generated by

    assembler/compiler into ROM of microcontroller

    SIMULATOR:It is a program which provides the facility to step through

    the code to see exactly what is happening as the program runs. The

    contents of register or variable can altered to change the way the program

    runs. A simulator cant support real interrupts or devices.

    DEBUGGER:It is a tool that is used to help identify and fix problems in

    a program. It supports step by step execution of the code and viewing the

    38

  • 8/8/2019 DEEPAK 2307388

    39/47

    contents of code variables. It allows monitoring of registers memory and

    program statements

    CHAPTER 4

    INTERFACING DEVICES

    Many times we need to interface some devices at I/O ports of 8051 microcontroller.Some common interfacing devices are:

    4.1 GENRAL INTERFACING DEVICES:

    LIGHT EMITTING DIODES (LED)

    Light emitting diodes, commonly called LEDs do dozens of different jobs and are

    found in all kinds of devices. Among other things, they form the numbers on digital

    clocks, transmit information from remote controls, light up watches and tell you when

    your appliances are turned on. Collected together, they can form images on a jumbo

    television screen or illuminate a traffic light.

    Basically, LEDs are just tiny light bulbs that fit easily into an electrical circuit. But

    unlike ordinary incandescent bulbs, they don't have a filament that will burn out, and

    they don't get especially hot. They are illuminated solely by the movement ofelectrons in a semiconductor material, and they last just as long as a standard

    transistor.

    PHOTO DIODE

    Photodiode are efficient light detectors that can be made small sizes, good linearity,

    and high response speed. Photodiode converts light into an electrical signal.

    Photodiode are faster than photoconductor because they have a pn junction to collect

    the carriers.

    Photo dictions mechanism in photodiodes is similar to that in photoconductor in

    that an electron-hole pair is created by a

    Photon for which hv>=Eg but it differs in that only the photo carrier

    That diffuse to the depletion layer are counted and only the minority carriers are

    collected.

    RELAYS

    39

  • 8/8/2019 DEEPAK 2307388

    40/47

    In industrial application we need to isolate one circuit electrically from another, while

    still allowing the first circuit to control the second. The way of providing electrical

    isolation between two circuits is to place a relay between them.

    A relay consists of a coil, which may be energized by the low-voltage circuit, and one

    or more sets of switch contacts, which may be connected to the high-voltage circuit.

    Fig. 4.1 RELAY CIRCUIT

    RELAYS WORKING:

    When a relay is off, the metal arm is at its rest position and so there is contact

    between the Normally Closed (N.C.) switch contact and the 'common' switch contact.

    If a current is passed through the coil, the resulting magnetic field attracts the metal

    arm and there is now contact between the Normally Open (N.O.) switch contact and

    the common switch contact.

    Fig. 4.2 RELAY WORKING

    40

    Low-voltage circuit High-voltage circuit

    A relay providing isolation between two circuits

    Relay off Relay on

    Metal arm

    Energized coilCoil

    Coil contactsN.C.

    contact

    Common

    contact

    N.O. contact

    There is contact between thecommon and N.C. contacts

    There is now contact between thecommon and N.O. contacts

    The mechanical operation of a relay

  • 8/8/2019 DEEPAK 2307388

    41/47

    OPTOCOUPLERS

    The MCT2XXX series opt isolators consist of a gallium arsenide

    infrared emitting diode driving a silicon phototransistor in a 6-pin dual in-line

    package.

    Fig 4.3 OPTOCOUPLER

    There are many situations where signals and data need to be

    transferred from one subsystem to another within a piece of electronics equipment, or

    from one piece of equipment to another, without making a direct electrical

    connection. Often this is because the source and destination are (or may be at times) at

    very different voltage levels.

    Relays provide this kind of isolation, but even small relays tend to be fairly bulky

    compared with ICs and many of todays other miniature circuit components. Because

    theyre electro-mechanical, relays are also not as reliable and only capable of

    relatively low speed operation. Where small size, higher speed and greater reliability

    are important, a much better alternative is to use an optocoupler. These use a beam of

    light to transmit the signals or data across an electrical barrier, and achieve excellent

    isolation.

    Optocouplers typically come in a small 6-pin or 8-pin IC package, but

    are essentially a combination of two distinct devices: an optical transmitter, typically

    a gallium arsenide LED (light-emitting diode) and an optical receiver such as a

    phototransistor or light-triggered diac. The two are separated by a transparent barrier

    which blocks any electrical current flow between the two, but does allow the passage

    41

  • 8/8/2019 DEEPAK 2307388

    42/47

    of light. The basic idea is shown in Fig.1, along with the usual circuit symbol for an

    optocoupler.

    Fig 4.4 CONSTRUCTION OF A OPTOCOUPLER

    Usually the electrical connections to the LED section are brought out

    to the pins on one side of the package and those for the phototransistor or diac to the

    other side, to physically separate them as much as possible. This usually allows

    optocouplers to withstand voltages of anywhere between 500V and 7500V between

    input and output.

    Optocouplers are essentially digital or switching devices, so theyre

    best for transferring either on-off control signals or digital data. Analog signals can be

    transferred by means of frequency or pulse-width modulation.

    LCD

    A Liquid Crystal Display is a thin, flat display device made up of any number of color

    or monochrome pixels arrayed in front of light source or reflector.

    42

  • 8/8/2019 DEEPAK 2307388

    43/47

    Fig 4.5 LCD Connections

    It is often utilize in battery powered electronic devices because it uses very small

    amount of electric power.

    LCDs can be broadly broken in to two categories:

    Graphics LCD

    Character LCD

    CHAPTER 5

    Programming of 8051

    LEDs interfacing program:

    LEDPORT EQU P0

    MAIN:

    LEDPORT,#00H

    ACALL DELAY

    43

  • 8/8/2019 DEEPAK 2307388

    44/47

    LEDPORT,#00H

    ACALL DELAY

    SJMP MAIN

    DELAY1:

    MOV 33H,#100D

    D3: MOV 34H,#100D

    D2: MOV 35H,#50D

    D1: DJNZ 35H,D1

    DJNZ 34H,D2

    DJNZ 33H,D3

    RET

    LCD interfacing Program:

    LCDPORT EQU P2

    RS EQU P1.1

    EN EQU P1.0

    ORG 0000H

    MOV P2,#38H

    ACALL COMMAND

    MOV P2,#0CH

    ACALL COMMAND

    MOV P2,#01H

    ACALL COMMAND

    MOV P2,#80H

    ACALL COMMAND

    MOV R2,#00H

    MOV R3,#16D

    H2:

    MOV A,R2

    MOV DPTR,#0100H

    MOVC A,@A+DPTR

    MOV P2,A

    44

  • 8/8/2019 DEEPAK 2307388

    45/47

    ACALL DATA

    INC R2

    DJNZ R3,H2

    MOV P2,#0C0H

    ACALL COMMAND

    MOV R4,#00H

    MOV R5,#16D

    H3:

    MOV A,R4

    MOV DPTR,#0110H

    MOVC A,@A+DPTR

    MOV P2,A

    ACALL DATA

    INC R4

    DJNZ R5,H3

    HERE3:SJMP HERE3

    COMMAND:

    CLR P1.0

    SETB P1.1

    NOP

    NOP

    CLR P1.1

    ACALL DELAY

    RET

    DATA:

    SETB P1.0

    SETB P1.1

    NOP

    NOP

    CLR P1.1

    ACALL DELAY

    45

  • 8/8/2019 DEEPAK 2307388

    46/47

    RET

    delay:

    MOV R0,#0FFH

    HERE1:MOV R1,#0FFH

    HERE:DJNZ R1,HERE

    DJNZ R0,HERE1

    RET

    ORG 0100H

    DB 'DEEPAK GUPTA'

    ORG 0110H

    DB 'DATE 30/JUL/2009'

    7 Segment Interfacing Program:

    SEG EQU P3

    LOOP2:

    MOV R3,#00H

    MOV R4,#10D

    LOOP1:

    MOV A,R3

    MOV DPTR,#0070H

    MOVC A,@A+DPTR

    ORL A,00H

    MOV P3,A

    ACALL DELAY

    INC R3

    DJNZ R4,LOOP1

    SJMP LOOP2

    STOP: SJMP STOP

    delay:

    MOV R0,#0FFH

    HERE1:MOV R1,#0FFH

    46

  • 8/8/2019 DEEPAK 2307388

    47/47

    HERE:DJNZ R1,HERE

    DJNZ R0,HERE1

    RET

    org 0070h

    DB 00H

    DB 10H

    DB 20H

    DB 30H

    DB 40H

    DB 50H

    DB 60H

    DB 70H

    DB 80H

    DB 90H

    REFRENCES

    www.emtech.in

    www.wikipidia.com

    www.siliconindia.com

    www.google.com

    http://www.emtech.in/http://www.wikipidia.com/http://www.siliconindia.com/http://www.google.com/http://www.emtech.in/http://www.wikipidia.com/http://www.siliconindia.com/http://www.google.com/