You are on page 1of 71

TRAINING REPORT

ON

EMBEDDED SYSTEMS
AT

DUCAT GURGAON
Period of Training (From July 17, 2011 to August 25, 2011)

Submitted by:MOHIT RATHI 4109242 th 5 semester

Electronics and Communication Engineering

Yamuna Institute Of Engineering and Technology


Vill-Gadholi, Distt.-YamunaNagar Kurukshetra University, kurukshetra

ACKNOWLEDGEMENT
Many lives and destinies are destroyed due to lack of proper guidance, direction and opportunity. It is in this respect that we are in a much better position today due to continuous process of motivation and focus provided by our parents and teachers in general. The process of completion of this project was a tedious job and required careful guidance at all stages. I would like to highlight the role-played by many individuals towards this. First I am eternally grateful to Honorable Principal Prof. Rajeev Khanduja for providing me the opportunity and the infrastructure to complete the project in the college laboratories. I am also highly obliged towards Head of Department Prof. Manpreet Singh for this constant motivation, support and guidance. His experience went a long way in assisting me. I feel privileged to offer my sincere thanks and deep sense of gratitude to Er. Sunil panjeta ,the Project-in-Charge, for expressing their confidence in me by letting me work on a project of this magnitude and using the latest technologies and providing their support, help & encouragement in implementing this Project.

DATE:MOHIT RATHI 4109242

ii

PREFACE

Practical training is an important part of theoretical studies. It covers all that which remains uncovered in classroom. It offers the student to explore an invaluable treasure of experience. It offers an exposure to real practical of institute in the industries. As we know well that practical training pay an important role in future building of an individual one can easily over come the fear form that life in which he has to join as a member after some time. Just theoretical knowledge is not sufficient for the success of an individual so one should have practical knowledge about each theory of general life. I have been given opportunity to have my practical training in embedded. I availed of this opportunity in an excellent manner and I have tried to cover whatever I come to know in this report. In collecting all the needed information and data for prepare the report equal importance was eagerness of all the workers and concerned supervisions to all them for their big help.

iii

List Of Figures

S. No.
1. 2. 3. 4. 5. 6. 7. 8. 9.

Figure
Fig: 2.1.1 Fig: 2.3.1 Fig: 2.3.2 Fig: 2.3.3 Fig: 2.3.4 Fig: 2.3.5 Fig: 2.4.1 Fig: 2.4.2 Fig: 2.4.3

Name
Embedded Sytem user Interface Intel P8051 microcontroller Pin Diagram of the 8051 Internal Schemits Block Diagram of 8051 Micrcontroller Intel 8031 Microprocessor Block Diagram of Cell Phone operated Circuit Diagram of Relay Section Circuit Diagram of Cell Phone Operate Device Switching

Device Switching

iv

Contents
1: INTRODUCTION 1.1 1.2 1.3 Training Module Skilled and Knowledgeable recruiter of Executive talent Mission And Vision

2: PROJECT WORK 2.1. Embedded System 2.1.1. Introduction 2.1.2. History 2.1.3. Variety of embedded systems 2.1.4. Characteristics 2.1.4.1. User interface 2.1.4.2. Processors in embedded systems 2.1.4.2.1 Ready made computer boards 2.1.4.2.2 ASIC and FPGA solutions 2.1.4.3. Peripherals 2.1.4.4. Tools 2.1. 5. Embedded software architecture 2.1.6. Examples of embedded system

2.2. Microcontroller
2.2.1. Introduction 2.2.2. History 2.2.3. Embedded Design 2.2.4. Architecture 2.2.5. Interrupts 2.2.6. Programs 2.2.7. Other microcontroller Features 2.2.8. Higher Integration 2.2.9. Volumes 2.2.10. Programming Environments 2.2.11. Types of Microcontroller 2.2.12. Interrupt Latency 2.2.13. Microcontroller Embedded Technology 2.2.13.1. Data 2.2.13.2. Firmware 2.3. 8051 Microcontroller 2.3.1. Introduction 2.3.2. About 8051 2.3.3. Pin Diagram of 8051 2.3.3.1. Basic Pins 2.3.3.2. Ports 2.3.3.3 Oscillatory circuits 2.3.3.4. Architecture 2.3.4.1. Internal Architecture 2.3.4.2. Memory Architecture 2.3.5. Program start Address 2.3.5.1. Direct Memory

vi

2.3.5.2. Special Function Registers 2.3.5.3. General Purpose Registers 2.3.5.4. As and Bs Registers 2.3.6. Important Function and Applications 2.3.7. Programming 2.3.8. Instruction Set 2.3.9. Related Processors

3. Results and Discussions 4. Conclusions 5. Bibliography

vii

1.ABOUT DUCAT

viii

Introduction to Institute
Backed by a team of professionals who have successfully trained and placed students. DUCAT offers a wide spectrum of technical courses and application courses designed to suit every skill level, as well as the ability to consult directly with organizations to tailor made learning plans for any number of employees. Our products and services have a wide appeal and are applicable those in varied positions including network administrators, systems analysts, systems architects, and business professionals. test engineers, software developers, help desk staff, IT managers, senior executives, administrative assistants

1.1.

Training Modules

Our courses feature hands-on tasks and real-world scenariosin just a matter of days, you'll be more productive and embracing new technology standards. The goal of our training program is to provide the world with skilled human resources who are competent to practice and provide solutions in an ever-changing technology world. To attain this goal, DUCAT uses a robust and well-researched proven training model. Trainees are exposed to a wide range of professional role models, mentors, and trainers while in the process they develop a professional identity that is uniquely their own. Since we always believe that each trainee bring with them their own unique skills and abilities, training staff recognizes and encourage them to develop and enhance these while sharing with other trainees. During the training period, our mentors provide an

ix

appropriate, graded sequence of experiential learning activities. Trainees are expected to attain increasing levels of autonomy and complexity in their progression from the role of student to the role of entry level professional by the end of the training where as our corporate training programs make the experienced profession filled with new passion to face the next project challenge with full confidence. We believe that self-awareness and the ability to continually reflect on one's own personal dynamics are critical to the development of effective professional skills. Towards this aim, trainees may be asked to engage in a process of personal exploration with their supervisors and trainers. In this process, mentors will encourage trainees to discuss and reflect upon how their experiences, personal qualities, and interpersonal dynamics related to their professional functioning. Mentors take care to create a training relationship characterized by trust, safety, and respect. They also take care to differentiate between training and supervision. As such, the focus of the discussion is always directly related to the trainees professional functioning and development. Our Training Methodology includes Class room Lectures Group Discussions Case studies Paper Presentation. Field Visits Interaction with various organization and experts from the fields Preserving latest knowledge by maintaining up -to-date library Learning by actual doing the work Observing live Models of various projects

1.2. Skilled and Knowledgeable recruiter of Executive talent


At DUCAT, you get the best HR solutions for different domains in IT. Since our inception, we have made a mark as one of the most prominent recruitment consultants in India. With the ongoing change in the various industries in India, which was initiated in the last decade, because of the globalization and open market strategies, companies are facing stiffer competitions from its MNC counterparts. Therefore, they have focused on the intensive business strategies, and a perfect HR strategy which is one of the most important aspects of a well managed company. This is why the importance of the recruitment agencies in India is felt in a greater extent these days. We believe in acquiring in-depth knowledge of the domains of our client, because we understand that without understanding the business of our clients, we cannot help them in their HR policies. Therefore, unlike other HR companies in India, we at DUCAT have decided to narrow the horizon of our service, so that we can enhance the depth of the service. That is why our recruitment services are restricted to the IT and ITES sector only. Our extensive network enables us to source for the right candidates with the right experience and qualifications for our Clients. We aim to be your partner and are able to identify and select candidates to fill your requirements in the technical, managerial and functional roles. With our extensive experience in HR, and expertise in placing candidates with top MNCs, we will provide customized solutions to your HR requirements.

xi

1.3. Vision and Mission


To become first choice of companies, looking for recruitment solutions, and job seekers, looking for best career options, in IT domain. To be a highly valued partner fostering innovation and exclusive Staffing solutions in areas of IT & ITES which enable our customers to meet their critical assurance. business

2.1.1. INTRODUCTION

An embedded system is a computer system designed to perform one or a few dedicated functions often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems are controlled by one or more main processing cores that are typically either microcontrollers or digital signal processors (DSP). The key characteristic, however, is being dedicated to handle a particular task, which may require very powerful processors. For example, air traffic control systems may usefully be viewed as embedded, even though they involve mainframe computers and dedicated regional and national networks between airports and radar sites (each radar probably includes one or more embedded systems of its own). Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale.

xii

Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure. In general, "embedded system" is not a strictly definable term, as most systems have some element of extensibility or programmability. For example, handheld computers share some elements with embedded systems such as the operating systems and microprocessors which power them, but they allow different applications to be loaded and peripherals to be connected. Moreover, even systems which don't expose programmability as a primary feature generally need to support software updates. On a continuum from "general purpose" to "embedded", large application systems will have subcomponents at most points even if the system as a whole is "designed to perform one or a few dedicated functions", and is thus appropriate to call "embedded". An Embedded System employs a combination of hardware & software (a computational engine) to perform a specific function; is part of a larger system that may not be a computer works in a reactive and time-constrained environment. Software is used for providing features and flexibility Hardware = {Processors, ASICs, Memory...} is used for performance (& sometimes security

An embedded system 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 PC, an embedded system performs predefined tasks usually with very specific tasks design engineers can optimize it reducing the size and cost of the product. Embedded systems are often mass produced, so the cost savings may be multiplied by million of items.

xiii

2.1.2. History
In the earliest years of computers in the 194050s, computers were sometimes dedicated to a single task, but were far too large and expensive for most kinds of tasks performed by embedded computers of today. Over time however, the concept of programmable controllers evolved from traditional electromechanical sequencers, via solid state devices, to the use of computer technology. One of the first recognizably modern embedded systems was the Apollo Guidance Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. At the project's inception, the Apollo guidance computer was considered the riskiest item in the Apollo project as it employed the then newly developed monolithic integrated circuits to reduce the size and weight. An early mass-produced embedded system was the Automatics D-17 guidance computer for the Minuteman missile, released in 1961. It was built from transistor logic and had a hard disk for main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a new computer that was the first high-volume use of integrated circuits. This program alone reduced prices on quad nand gate ICs from $1000/each to $3/each, permitting their use in commercial products. Since these early applications in the 1960s, embedded systems have come down in price and there has been a dramatic rise in processing power and functionality. The first microprocessor for example, the Intel 4004, was designed for calculators and other small systems but still required many external memory and support chips. In 1978 National Engineering Manufacturers Association released a "standard" for programmable microcontrollers, including almost any computer-based controllers, such as single board computers, numerical, and event-based controllers. As the cost of microprocessors and microcontrollers fell it became feasible to replace expensive knob-based analog components such as potentiometers and variable capacitors with up/down buttons or knobs read out by a microprocessor even in some consumer products. By the mid-1980s, most of the common previously external system

xiv

components had been integrated into the same chip as the processor and this modern form of the microcontroller allowed an even more widespread use, which by the end of the decade were the norm rather than the exception for almost all electronics devices. The integration of microcontrollers has further increased the applications for which embedded systems are used into areas where traditionally a computer would not have been considered. A general purpose and comparatively low-cost microcontroller may often be programmed to fulfill the same role as a large number of separate components. Although in this context an embedded system is usually more complex than a traditional solution, most of the complexity is contained within the microcontroller itself.

2.1.3. Variety of Embedded systems


PC Engines' ALIX.1C Mini-ITX embedded board with an x86 AMD Geode LX 800 together with Compact Flash miniPCI and PCI slots, 44-pin IDE interface, audio, USB and 256MB RAM
An embedded Router Board 112 with U.FL-RSMA pigtail and R52 mini PCI Wi-Fi card widely used by wireless Internet service providers (WRISPs) in the Czech Republic. Embedded systems span all aspects of modern life and there are many examples of their use. Telecommunications systems employ numerous embedded systems from telephone switches for the network to mobile phones at the end-user. Computer networking uses dedicated routers and network bridges to route data.

xv

Consumer electronics include personal Digital assistants (PDAs), mp3 players, mobile phones, videogame Consoles, digital cameras, DVD players, GPS receivers, and printers. Many household appliances, such as microwave ovens, washing machines and dishwashers, are including embedded systems to provide flexibility, efficiency and features. Advanced HVAC systems use networked Thermostats to more accurately and efficiently control temperature that can change by time of day and season. Home automation uses wired- and wireless-networking that can be used to control lights, climate, security, audio/visual, surveillance, etc., all of which use embedded devices for sensing and controlling. Transportation systems from flight to automobiles increasingly use embedded systems. New airplanes contain advanced avionics such as inertial guidance systems and GPS receivers that also have considerable safety requirements. Various electric motors brushless DC motors, induction motors and DC motors are using electric/electronic motor controllers. Automobiles, electric vehicles, and hybrid vehicles are increasingly using embedded systems to maximize efficiency and reduce pollution. Other automotive safety systems include anti-lock braking system (ABS), Electronic Stability Control (ESC/ESP), traction control (TCS) and automatic four-wheel drive. Medical is continuing to advance with more embedded systems for vital signs monitoring, electronic stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT, MRI) for non-invasive internal inspections.In addition to commonly described embedded systems based on small computers, a new class of miniature wireless devices called motes are quickly gaining popularity as the field of wireless sensor networking rises. Wireless sensor networking, WSN, makes use of miniaturization made possible by advanced IC design to couple full wireless subsystems to sophisticated sensors, enabling people and companies to measure a myriad of things in the physical world and act on this information through IT monitoring and control systems.

xvi

2.1.4. Characteristics
1. Embedded systems are designed to do some specific task, rather than be a general-purpose computer for multiple tasks. 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. 2. Embedded systems are not always standalone devices. Many embedded systems consist of small, computerized parts within a larger device that serves a more general purpose. For example, the Gibson Robot Guitar features an embedded system for tuning the strings, but the overall purpose of the Robot Guitar is, of course, to play music. Similarly, an embedded system in an automobile provides a specific function as a subsystem of the car itself. 2. The program instructions written for embedded systems are referred to as firmware, and are stored in read-only memory.

xvii

2.1.4.1. User interface

FIG: 2.1.1. Embedded system text user interface

Embedded systems range from no user interface at all dedicated only to one task to complex graphical user interfaces that resemble modern computer desktop operating systems. Simple embedded devices use buttons, LEDs, graphic or character LCDs (for example popular HD44780 LCD) with a simple menu system. A more sophisticated devices use graphical screen with touch sensing or screen-edge buttons provide flexibility while minimizing space used: the meaning of the buttons can change with the screen, and selection involves the natural behavior of pointing at what's desired. Handheld systems often have a screen with a "joystick button" for a pointing device. Some systems provide user interface remotely with the help of a serial (e.g. RS-232, USB, IC, etc.) or network (e.g. Ethernet) connection. In spite of the potentially necessary proprietary client software and/or specialist cables that are needed, this approach usually gives a lot of advantages: extends the capabilities of embedded system, avoids the cost of a display, simplifies BSP, allows to build rich user interface on the PC. xviii

2.1.4.2. Processors in embedded systems


Embedded processors can be broken into two broad categories: ordinary microprocessors (P) and microcontrollers (C), which have many more peripherals on chip, reducing cost and size. Contrasting to the personal computer and server markets, a fairly large number of basic CPU architectures are used; there are Von Neumann as well as various degrees of Harvard architectures, RISC as well as non-RISC and VLIW; word lengths vary from 4-bit to 64-bits and beyond (mainly in DrSP processors) although the most typical remain 8/16-bit. Most architectures come in a large number of different variants and shapes, many of which are also manufactured by several different companies. A long but still not exhaustive list of common architectures are: 65816, 65C02, 68HC08, 68HC11, 68k, 8051, ARM, AVR, AVR32, Black fin, C167, Cold fire, COP8, Cortus APS3, eZ8, eZ80, FR-V, H8, HT48, M16C, M32C, MIPS, MSP430, PIC, PowerPC, R8C, SHARC, SPARC, ST6, SuperH, TLCS-47, TLCS-870, TLCS-900, Tricore, V850, x86, XE8000, Z80, AsAP etc.

2.1.4.2.1. Ready made computer boards


PC/104 and PC/104+ are examples of standards for ready made computer boards intended for small, low-volume embedded and ruggedized systems, mostly x86-based. These often use DOS, Linux, NetBSD, or an embedded real-time operating system such as MicroC/OS-II, QNX or VxWorks. Sometimes these boards use non-x86 processors. In certain applications, where small size or power efficiency are not primary concerns, the components used may be compatible with those used in general purpose x86 personal computers. Boards such as the VIA EPIA range help to bridge the gap by being PC-compatible but highly integrated, physically smaller or have other attributes making them attractive to embedded engineers. The advantage of this approach is that low-cost commodity components may be used along with the same software development tools used for general software development. Systems built in this way are

xix

still regarded as embedded since they are integrated into larger devices and fulfill a single role. Examples of devices that may adopt this approach are ATMs and arcade machines, which contain code specific to the application. However, most ready-made embedded systems boards are not PC-centered and do not use the ISA or PCI busses. When a System-on-a-chip processor is involved, there may be little benefit to having a standarized bus connecting discrete compontents, and the environment for both hardware and software tools may be very different. One common design style uses a small system module, perhaps the size of a business card, holding high density BGA chips such as an ARM-based System-on-a-chip processor and peripherals, external flash memory for storage, and DRAM for runtime memory. The module vendor will usually provide boot software and make sure there is a selection of operating systems, usually including Linux and some real time choices. These modules can be manufactured in high volume, by organizations familiar with their specialized testing issues, and combined with much lower volume custom mainboards with application-specific external peripherals. Gumstix product lines are a Linux-centric example of this mode

2.1.4.2.2. ASIC and FPGA solutions


A common configuration for very-high-volume embedded systems is the system on a chip (SoC) which contains a complete system consisting of multiple processors, multipliers, caches and interfaces on a single chip. SoCs can be implemented as an application-specific integrated circuit (ASIC) or using a field-programmable gate array Peripherals Embedded Systems talk with the outside world via peripherals, such as:

Serial Communication Interfaces (SCI): RS-232, RS-422, RS-

485 etc.

Synchronous Serial Communication Interface: I2C, SPI, SSC and ESSI

xx

Universal Serial Bus (USB) Multi Media Cards (SD Cards, Compact Flash etc.) Networks: Ethernet, controller Area Network, Lon Works, etc. Timers: PLL(s), Capture/Compare and Time Processing Units Discrete IO: aka General Purpose Input/Output (GPIO) Analog to Digital/Digital to Analog (ADC/DAC) Debugging: JTAG, ISP, ICSP, BDM Port, BITP, and DP9 ports.

2.1.4.3. Tools
As for other software, embedded system designers use compilers, assemblers, and debuggers to develop embedded system software. However, they may also use some more specific tools:

In circuit debuggers or emulators (see next section). Utilities to add a checksum or CRC to a program, so the embedded system can check if the program is valid.

For systems using digital signal processing, developers may use a math workbench such as Scilab / Scicos, MATLAB / Simulink, EICASLAB, MathCAD, Mathematica, or Flowstone DSP to simulate the mathematics. They might also use libraries for both the host and target which eliminates developing DSP routines as done in DSPnano RTOS and Unison Operating System.

An embedded system may have its own special language or design tool, or add enhancements to an existing language such as Forth or Basic. Another alternative is to add a real-time operating system or embedded operating system, which may have DSP capabilities like DSPnano RTOS.

xxi

Software tools can come from several sources:


Software companies that specialize in the embedded market Ported from the GNU software development tools Sometimes, development tools for a personal computer can be

used if the embedded processor is a close relative to a common PC processor As the complexity of embedded systems grows, higher level tools and operating systems are migrating into machinery where it makes sense. For example, cell phones, personal digital assistants and other consumer computers often need significant software that is purchased or provided by a person other than the manufacturer of the electronics. In these systems, an open programming environment such as Linux, NetBSD, OSGi or Embedded Java is required so that the third-party software provider can sell to a large market.

2.1.6. EXAMPLES OF EMBEDDED SYSTEM


Automated tiller machines (ATMS). Avionic, such as inertial guidance systems, flight control hardware / Software and letter integrated system in aircraft and missile. Cellular Computer Disk drives (floppy telephones and printers, disk drive and hard disk telephonic switches. Copiers. drive)

Computer network equipment, including routers timeservers

Engine controllers and antilock brake controllers for automobiles. Home automation products like thermostat, air conditioners sprinkles and security monitoring system. House hold appliances including microwave ovens, washing machines, TV sets DVD players/recorders. Medical equipment.

xxii

2.2. MICROCONTROLLER

xxiii

2.2.1. INTRODUCTION
A microcontroller (sometimes abbreviated C, C or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, and toys. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems. Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as 4 kHz, for low power consumption (milliwatts or microwatts). They will generally have the ability to retain functionality while waiting for an event such as a button press or other interrupt; power consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts, making many of them well suited for long lasting battery applications.

2.2.2 History
The first single-chip microprocessor was the 4-bit Intel 4004 released in 1971. With the Intel 8008 and more capable microprocessors available over the next several years. These however all required external chip(s) to implement a working system, raising total system cost, and making it impossible to economically computerize appliances.

xxiv

The first computer system on a chip optimized for control applications was the Intel 8048 released in 1975 with both RAM and ROM on the same chip. This chip would find its way into over one billion PC keyboards, and other numerous applications. At this time Intels President, Luke J. Valenter, stated that the (Microcontroller) was one of the most successful in the companies history, and expanded the division's budget over 25%.Most microcontrollers at this time had two variants. One had an erasable EPROM program memory, which was significantly more expensive than the PROM variant which was only programmable once. In 1993, the introduction of EEPROM memory allowed microcontrollers (beginning with the Microchip PIC16x84 to be electrically erased quickly without an expensive package as required for EPROM, allowing both rapid prototyping, and In System Programming. The same year, Atmel introduced the first microcontroller using Flash memory Other companies rapidly followed suit, with both memory types. Cost has plummeted over time, with the cheapest 8-bit microcontrollers being available for under $0.25 in quantity (thousands) in 2009,] and some 32-bit microcontrollers around $1 for similar quantities.

2.2.3. Embedded design


A microcontroller can be considered a self-contained system with a processor, memory and peripherals and can be used as an embedded system The majority of microcontrollers in use today are embedded in other machinery, such as automobiles, telephones, appliances, and peripherals for computer systems. These are called embedded systems. While some embedded systems are very sophisticated, many have minimal requirements for memory and program length, with no operating system, and low software complexity. Typical input and output devices include switches, relays, solenoids, LEDs, small or custom LCD displays, radio frequency devices, and sensors for data such as temperature, humidity, light level etc. Embedded systems usually have no keyboard, screen, disks, printers, or other recognizable I/O devices of a personal computer, and may lack human interaction devices of any kind.

xxv

2.2.4. ARCHITECTURE
Microprocessors and Microcontrollers
A digital computer typically consists of three major components: the Central Processing Unit (CPU), program and data memory, and an Input/Output (I/O) system. The CPU controls the flow of information among the components of the computer. It also processes the data by performing digital operations. Most of the processing is done in the Arithmetic-Logic Unit (ALU) within the CPU. When the CPU of a computer is built on a single printed circuit board, the computer is called a minicomputer. A microprocessor is a CPU that is compacted into a single-chip semiconductor device. Microprocessors are general-purpose devices, suitable for many applications. A computer built around a microprocessor is called a microcomputer. The choice of I/O and memory devices of a microcomputer depends on the specific application. For example, most personal computers contain a keyboard and monitor as standard input and output devices. A microcontroller is an entire computer manufactured on a single chip. Microcontrollers are usually dedicated devices embedded within an application. For example, microcontrollers are used as engine controllers in automobiles and as exposure and focus controllers in cameras. In order to serve these applications, they have a high concentration of on-chip facilities such as serial ports, parallel input output ports, timers, counters, interrupt control, analog-to-digital converters, random access memory, read only memory, etc. The I/O, memory, and on-chip peripherals of a microcontroller are selected depending on the specifics of the target application. Since microcontrollers are powerful digital processors, the degree of control and programmability they provide significantly enhances the effectiveness of the application. Embedded control applications also distinguish the microcontroller from its relative, the general-purpose microprocessor. Embedded systems often require realtime operation and multitasking capabilities. Real-time operation refers to the fact that the embedded controller must be able to receive and process the signals from its

xxvi

environment as they are received. That is, the environment must not wait for the controller to become available. Similarly, the controller must perform fast enough to output control signals to its environment when they are needed. Again, the environment must not wait for the controller. In other words, the embedded controller should not be a bottleneck in the operation of the system. Multitasking is the capability to perform many functions in a simultaneous or quasi-simultaneous manner. The embedded controller is often responsible of monitoring several aspects of a system and responding accordingly when the need arises. The 8051 is the first microcontroller of the MCS-51 family introduced by Intel Corporation at the end of the 1970s. The 8051 family with its many enhanced members enjoys the largest market share, estimated to be about 40%, among the various microcontroller architectures. The architecture of the 8051 family of the microcontrollers is presented in this chapter. First, the original 8051 microcontroller is discussed, followed by the enhanced features of the 8032, and the 80C515.

2.2.5. Interrupts
Microcontrollers must provide real time (predictable, though not necessarily fast) response to events in the embedded system they are controlling. When certain events occur, an interrupt system can signal the processor to suspend processing the current instruction sequence and to begin an interrupt service routine (ISR, or "interrupt handler"). The ISR will perform any processing required based on the source of the interrupt before returning to the original instruction sequence. Possible interrupt sources are device dependent, and often include events such as an internal timer overflow, completing an analog to digital conversion, a logic level change on an input such as from a button being pressed, and data received on a communication link. Where power consumption is important as in battery operated devices, interrupts may also wake a microcontroller from a low power sleep state where the processor is halted until required to do something by a peripheral event.

xxvii

2.2.6. Programs
Microcontroller programs must fit in the available on-chip program memory, since it would be costly to provide a system with external, expandable, memory. Compilers and assemblers are used to convert high-level language and assembler language codes into a compact machine code for storage in the microcontroller's memory. Depending on the device, the program memory may be permanent, read-only memory that can only be programmed at the factory, or program memory may be field-alterable flash or erasable read-only memory.

2.2.7. Other microcontroller features


Microcontrollers usually contain from several to dozens of general purpose input/output pins (GPIO). GPIO pins are software configurable to either an input or an output state. When GPIO pins are configured to an input state, they are often used to read sensors or external signals. Configured to the output state, GPIO pins can drive external devices such as LEDs or motors. Many embedded systems need to read sensors that produce analog signals. This is the purpose of the analog-to-digital converter (ADC). Since processors are built to interpret and process digital data, i.e. 1s and 0s, they are not able to do anything with the analog signals that may be sent to it by a device. So the analog to digital converter is used to convert the incoming data into a form that the processor can recognize. A less common feature on some microcontrollers is a digital-to-analog converter (DAC) that allows the processor to output analog signals or voltage levels. In addition to the converters, many embedded microprocessors include a variety of timers as well. One of the most common types of timers is the Programmable Interval Timer (PIT). A PIT just counts down from some value to zero. Once it reaches zero, it sends an interrupt to the processor indicating that it has finished counting. This is useful

xxviii

for devices such as thermostats, which periodically test the temperature around them to see if they need to turn the air conditioner on, the heater on, etc. Time Processing Unit (TPU) is a sophisticated timer. In addition to counting down, the TPU can detect input events, generate output events, and perform other useful operations. A dedicated Pulse Width Modulation (PWM) block makes it possible for the CPU to control power converters, resistive loads, motors, etc., without using lots of CPU resources in tight timer loops. Universal Asynchronous Receiver/Transmitter (UART) block makes it possible to receive and transmit data over a serial line with very little load on the CPU. Dedicated on-chip hardware also often includes capabilities to communicate with other devices (chips) in digital formats such as I2C and Serial Peripheral Interface (SPI).

2.2.8. Higher integration


In contrast to general-purpose CPUs, micro-controllers may not implement an external address or data bus as they integrate RAM and non-volatile memory on the same chip as the CPU. Using fewer pins, the chip can be placed in a much smaller, cheaper package. Integrating the memory and other peripherals on a single chip and testing them as a unit increases the cost of that chip, but often results in decreased net cost of the embedded system as a whole. Even if the cost of a CPU that has integrated peripherals is slightly more than the cost of a CPU and external peripherals, having fewer chips typically allows a smaller and cheaper circuit board, and reduces the labor required to assemble and test the circuit board. A micro-controller is a single integrated circuit, commonly with the following features:

xxix

central processing unit - ranging from small and simple 4-bit processors to complex 32- or 64-bit processors

discrete input and output bits, allowing control or detection of the logic state of an individual package pin serial input/output such as serial ports (UARTs) other serial communications interfaces like IC, Serial Peripheral

Interface and Controller Area Network for system interconnect

peripherals such as timers, event counters, PWM generators, and watchdog

volatile memory (RAM) for data storage ROM, EPROM, EEPROM or Flash memory for program and

operating parameter storage

clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit

many include analog-to-digital converters in-circuit programming and debugging support

This integration drastically reduces the number of chips and the amount of wiring and circuit board space that would be needed to produce equivalent systems using separate chips. Furthermore, and on low pin count devices in particular, each pin may interface to several internal peripherals, with the pin function selected by software. This allows a part to be used in a wider variety of applications than if pins had dedicated functions. Micro-controllers have proved to be highly popular in embedded systems since their introduction in the 1970s. Some microcontrollers use a Harvard architecture: separate memory buses for instructions and data, allowing accesses to take place concurrently. Where a Harvard architecture is used, instruction words for the processor may be a different bit size than

xxx

the length of internal memory and registers; for example: 12-bit instructions used with 8-bit data registers. The decision of which peripheral to integrate is often difficult. The microcontroller vendors often trade operating frequencies and system design flexibility against time-tomarket requirements from their customers and overall lower system cost. Manufacturers have to balance the need to minimize the chip size against additional functionality. Microcontroller architectures vary widely. Some designs include general-purpose microprocessor cores, with one or more ROM, RAM, or I/O functions integrated onto the package. Other designs are purpose built for control applications. A microcontroller instruction set usually has many instructions intended for bit-wise operations to make control programs more compact.[] For example, a general purpose processor might require several instructions to test a bit in a register and branch if the bit is set, where a micro-controller could have a single instruction to provide that commonlyrequired function. Microcontrollers typically do not have a math coprocessor, so floating point arithmetic is performed by software.

2.2.9. Volumes
About 55% of all CPUs sold in the world are 8-bit microcontrollers and microprocessors. According to Semi co, over four billion 8-bit microcontrollers were sold in 2006. A typical home in a developed country is likely to have only four general-purpose microprocessors but around three dozen microcontrollers. A typical mid-range

xxxi

automobile has as many as 30 or more microcontrollers. They can also be found in many electrical device such as washing machines, microwave ovens, and telephones. Manufacturers have often produced special versions of their microcontrollers in order to help the hardware and software development a "window" on the top of the device through which program memory can be erased by ultraviolet light, ready for reprogramming after a programming ("burn") and test cycle. Since 1998, EPROM versions are rare and have been replaced by EEPROM and flash, which are easier to use (can be erased electronically) and cheaper to manufacture. Other versions may be available where the ROM is accessed as an external device rather than as internal memory, however these are becoming increasingly rare due to the widespread availability of cheap microcontroller programmers. The use of field-programmable devices on a microcontroller may allow field update of the firmware or permit late factory revisions to products that have been assembled but not yet shipped. Programmable memory also reduces the lead time required for deployment of a new product. Where hundreds of thousands of identical devices are required, using parts programmed at the time of manufacture can be an economical option. These "mask programmed" parts have the program laid down in the same way as the logic of the chip, at the same time.

xxxii

2.2.10. Programming environments


Microcontrollers were originally programmed only in assembly language, but various high-level programming languages are now also in common use to target microcontrollers. These languages are either designed specially for the purpose, or versions of general purpose languages such as the C programming language. Compilers for general purpose languages will typically have some restrictions as well as enhancements to better support the unique characteristics of microcontrollers. Some microcontrollers have environments to aid developing certain types of applications. Microcontroller vendors often make tools freely available to make it easier to adopt their hardware. Many microcontrollers are so quirky that they effectively require their own nonstandard dialects of C, such as SDCC for the 8051, which prevent using standard tools (such as code libraries or static analysis tools) even for code unrelated to hardware features. Interpreters are often used to hide such low level quirks. Interpreter firmware is also available for some microcontrollers. For example, BASIC on the early microcontrollers Intel 8052; BASIC and FORTH on the Zilog Z8 as well as some modern devices. Typically these interpreters support interactive programming. Simulators are available for some microcontrollers, such as in Microchip's MPLAB environment. These allow a developer to analyze what the behavior of the microcontroller and their program should be if they were using the actual part. A simulator will show the internal processor state and also that of the outputs, as well as allowing input signals to be generated. While on the one hand most simulators will be limited from being unable to simulate much other hardware in a system

xxxiii

2.2.11. Types of microcontrollers


As of 2008 there are several dozen microcontroller architectures and vendors including: Free scale 68HC11 (8-bit) Intel 8051 ARM processors (from many vendors) using ARM7 or CortexSTMicroelectronics STM8S (8-bit), ST10 (16-bit) and STM32 Atmel AVR (8-bit), AVR32 (32-bit), and AT91SAM (32-bit) Freescale Cold Fire (32-bit) and S08 (8-bit) Hitachi H8, Hitachi SuperH (32-bit) Hyper stone E1/E2 (32-bit, First full integration of RISC and MIPS (32-bit PIC32) NEC V850 (32-bit) PIC (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24) PowerPC ISE PSoC (Programmable System-on-Chip) Rabbit 2000 (8-bit) Texas Instruments Microcontrollers MSP430 (16-bit), C2000 Toshiba TLCS-870 (8-bit/16-bit) Zilog eZ8 (16-bit), eZ80 (8-bit) and many others, some of which are used in very narrow range of applications or are more like applications

M3 cores are generally microcontrollers (32-bit)

DSP on one processor core [1996])

(32-bit), and Stellar is (32-bit)

xxxiv

2.2.12. Interrupt latency


In contrast to general-purpose computers, microcontrollers used in embedded systems often seek to optimize interrupt latency over instruction throughput. Issues include both reducing the latency, and making it be more predictable (to support real-time control). When an electronic device causes an interrupt, the intermediate results (registers) have to be saved before the software responsible for handling the interrupt can run. They must also be restored after that software is finished. If there are more registers, this saving and restoring process takes more time, increasing the latency. Ways to reduce such context/restore latency include having relatively few registers in their central processing units (undesirable because it slows down most non-interrupt processing substantially), or at least having the hardware not save them all (this fails if the software then needs to compensate by saving the rest "manually"). Another technique involves spending silicon gates on "shadow registers": one or more duplicate registers used only by the interrupt software, perhaps supporting a dedicated stack. Other factors affecting interrupt latency include: Cycles needed to complete current CPU activities. To minimize those costs, microcontrollers tend to have short pipelines (often three instructions or less), small write buffers, and ensure that longer instructions are continuable or restart able. RISC design principles ensure that most instructions take the same number of cycles, helping avoid the need for most such continuation/restart logic. The length of any critical section that needs to be interrupted. Entry to a critical section restricts concurrent data structure access. When a data structure must be accessed by an interrupt handler, the critical section xxxv

must block that interrupt. Accordingly, interrupt latency is increased by however long that interrupt is blocked. When there are hard external constraints on system latency, developers often need tools to measure interrupt latencies and track down which critical sections cause slowdowns. One common technique just blocks all interrupts for the duration of the critical section. This is easy to implement, but sometimes critical sections get uncomfortably long. A more complex technique just blocks the interrupts that may trigger access to that data structure. This often based on interrupt priorities, which tend to not correspond well to the relevant system data structures. Accordingly, this technique is used mostly in very constrained environments. Processors may have hardware support for some critical sections. Examples include supporting atomic access to bits or bytes within a word, or other atomic access primitives like the LDREX/STREX exclusive access primitives introduced in the ARMv6 architecture. Interrupt nesting. Some microcontrollers allow higher priority interrupts to interrupt lower priority ones. This allows software to manage latency by giving time-critical interrupts higher priority (and thus lower and more predictable latency) than less-critical ones. Trigger rate. When interrupts occur back-to-back, microcontrollers may avoid an extra context save/restore cycle by a form of tail call optimization.

2.2.13.

Microcontroller

embedded

memory

technology

xxxvi

Since the emergence of microcontrollers, many different memory technologies have been used. Almost all microcontrollers have at least two different kinds of memory, a non-volatile memory for storing firmware and a read-write memory for temporary data.

2.2.13.1. Data
From the earliest microcontrollers to today, six-transistor SRAM is almost always used as the read/write working memory, with a few more transistors per bit used in the register file. MRAM could potentially replace it as it is 4-10 times denser which would make it more cost effective. In addition to the SRAM, some microcontrollers also have internal EEPROM for data storage; and even ones that do not have any (or not enough) are often connected to external serial EEPROM chip (such as the BASIC Stamp) or external serial flash memory chip. A few recent microcontrollers beginning in 2003 have "self-programmable" flash memory].

2.2.13.2. Firmware
The earliest microcontrollers used hard-wired or mask ROM to store firmware. Later microcontrollers (such as the early versions of the Freescale 68HC11 and early PIC microcontrollers) had quartz windows that allowed ultraviolet light in to erase the E

xxxvii

2.3.8051 MICROCONTROLLER

xxxviii

2.3.1. INTRODUCTION

Fig: 2.3.1 Intel P8051 microcontroller.

The Intel MCS-51 is a Harvard architecture, single chip microcontroller (C) series 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), rNXP (formerly Philips Semiconductor), Nuvoton (formerly Winbond), ST Microelectronics, Silicon Laboratories (formerly Cygnal), Texas Instruments and Cypress Semiconductor. xxxix

Intel's original MCS-51 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 more suitable for battery-powered devices. The Intel 8051 microcontroller is one of the most popular general purpose microcontrollers in use today. The success of the Intel 8051 spawned a number of clones which are collectively refered to as the MCS-51 family of microcontrollers, which includes chips from vendors such as Atmel, Philips, Infineon, and Texas Instruments.

2.3.2. About the 8051


The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and Extended. The Short and Standard chips are often available in DIP form, but the Extended 8051 models often have a different form factor, and are not "drop-in compatible". All these things are called 8051 because they can all be programmed using 8051 assembly language, and they all share certain features (although the different models all have their own special features).Some of the features that have made the 8051 popular are:

8-bit data bus 16-bit address bus 32 general purpose registers each of 8 bits 16 bit timers (usually 2, but may have more, or less). 3 internal and 2 external interrupts. Bit as well as byte addressable RAM area of 16 bytes. Four 8-bit ports, (short models have two 8-bit ports). 16-bit program counter and data pointer

xl

2.3.3. Pin Diagram of 8051

Fig: 2.3.2. Pin diagram of the 8051

xli

2.3.3.1. Basic Pins


PIN 9: PIN 9 is the reset pin which is used reset the microcontrollers internal registers and ports upon starting up. (Pin should be held high for 2 machine cycles.) PINS 18 & 19: The 8051 has a built-in oscillator amplifier hence we need to only connect a crystal at these pins to provide clock pulses to the circuit. PIN 40 and 20: Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V 500mA to function properly, although there are lower powered versions like the Atmel 2051 which is a scaled down version of the 8051 which runs on +3V. PINS 29, 30 & 31: As described in the features of the 8051, this chip contains a built-in flash memory. In order to program this we need to supply a voltage of +12V at pin 31. If external memory is connected then PIN 31, also called EA/VPP, should be connected to ground to indicate the presence of external memory. PIN 30 is called ALE (address latch enable), which is used when multiple memory chips are connected to the controller and only one of them needs to be selected. We will deal with this in depth in the later chapters. PIN 29 is called PSEN. This is "program select enable". In order to use the external memory it is required to provide the low voltage (0) on both PSEN and EA pins.

xlii

2.3.3.2 .Ports
There are 4 8-bit ports: P0, P1, P2 and P3.

Input/Output Ports (I/O Ports):


All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to be connected to peripheral devices are available for use. Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends on its logic state, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the case with any TTL input.

Port 0
Port 0 is an 8-bit open drain bidirectional port. As an open drain output port, it can sink eight LS TTL loads. Port 0 pins that have 1s written to them float, and in that state will function as high impedance inputs. Port 0 is also the multiplexed low-order address and data bus during accesses to external memory. In this application it uses strong internal pull-ups when emitting 1s. Port 0 emits code bytes during program verification. In this application, external pull-ups are required.

xliii

If any pin of this port is configured as an input then it acts as if it floats. Such an input has unlimited input resistance and in determined potential.

When the pin is configured as an output, it acts as an open drain. By applying logic 0 to a port bit, the appropriate pin will be connected to ground (0V). By applying logic 1, the external output will keep on floating. In order to apply logic 1 (5V) on this output pin, it is necessary to built in an external pull-up resistor.

Port 1
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 1 pins that have 1s written to them are pulled high by the internal pull-ups, and in that state can be used as inputs. As inputs, port 1 pins that are externally being pulled low will source current because of the internal pull-ups.

Port 2
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Port 2 emits the highorder address byte during accesses to external memory that use 16-bit addresses. In this application, it uses the strong internal pull-ups when emitting 1s.

xliv

Port 3
Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. It also serves the functions of various special features of the 80C51 Family as follows: Port Pin Alternate Function P3.0 RxD (serial input port) P3.1 TxD (serial output port) P3.2 INT0 (external interrupt 0) P3.3 INT1 (external interrupt 1) P3.4 T0 (timer 0 external input) P3.5 T1 (timer 1 external input) P3.6 WR (external data memory write strobe) P3.7 RD (external data memory read strobe).

Port Structures and Operation


All four ports in the 80C51 are bidirectional. Each consists of a latch (Special Function Registers P0 through P3), an output driver, and an input buffer. The output drivers of Ports 0 and 2, and the input buffers of Port 0, are used in accesses to external memory. In this application, Port 0 outputs the low byte of the external memory address, timemultiplexed with the byte being written or read. Port 2 outputs the high byte of the external memory address when the address is 16 bits wide. Otherwise, the Port 2 pins continue to emit the P2 SFR content. All the Port 3 pins are multifunctional. They are not only port pins, but also serve the functions of various special features as listed below:

xlv

2.6.6 Special Function Registers (SFRs):


Special Function Registers (SFRs) are a sort of control table used for running and monitoring the operation of the microcontroller. Each of these registers as well as each bit they include, has its name, address in the scope of RAM and precisely defined purpose such as timer control, interrupt control, serial communication control etc. Even though there are 128 memory locations intended to be occupied by them, the basic core, shared by all types of 8051 microcontrollers, has only 21 such registers. Rest of locations are intentionally left unoccupied in order to enable the manufacturers to further develop microcontrollers keeping them compatible with the previous versions. It also enables programs written a long time ago for microcontrollers which are out of production now to be used today.

xlvi

BIT SYMBOL FUNCTION


PSW.7 CY Carry flag. PSW.6 AC Auxiliary Carry flag. (For BCD operations.) PSW.5 F0 Flag 0. (Available to the user for general purposes.) PSW.4 RS1 Register bank select control bit 1. Set/cleared by software to determine working register bank. PSW.3 RS0 Register bank select control bit 0. Set/cleared by software to determine working register bank. PSW.2 OV Overflow flag. PSW.1 User-definable flag. PSW.0 P Parity flag. Set/cleared by hardware each instruction cycle to indicate an odd/even Number of one bits in the Accumulator, i.e., even parity. NOTE: The contents of (RS1, RS0) enable the working register banks as follows: (0, 0) Bank 0 (00H07H) (0, 1) Bank 1 (08H0fH) (1, 0) Bank 2 (10H17H) (1, 1) Bank 3 (18H17H)

A Register (Accumulator)

A register is a general-purpose register used for storing intermediate results obtained during operation. Prior to executing an instruction upon any number or operand it is necessary to store it in the accumulator first. All results obtained from arithmetical operations performed by the ALU are stored in the accumulator. Data to be moved from

xlvii

one register to another must go through the accumulator. In other words, the A register is the most commonly used register and it is impossible to imagine a microcontroller without it. More than half instructions used by the 8051 microcontroller use somehow the accumulator.
B Register

Multiplication and division can be performed only upon numbers stored in the A and B registers. All other instructions in the program can use this register as a spare accumulator (A).

R Registers (R0-R7)

This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7). Even though they are not true SFRs, they deserve to be discussed here because of their purpose. They occupy 4 banks within RAM. Similar to the accumulator, they are used for temporary storing variables and intermediate results during operation. Which one of these banks is to be active depends on two bits of the PSW Register. Active bank is a bank the registers of which are currently used.

xlviii

The following example best illustrates the purpose of these registers. Suppose it is necessary to perform some arithmetical operations upon numbers previously stored in the R registers: (R1+R2) - (R3+R4). Obviously, a register for temporary storing results of addition is needed. This is how it looks in the program: MOV A,R3; Means: move number from R3 into accumulator ADD A,R4; Means: add number from R4 to accumulator (result remains in accumulator) MOV R5,A; Means: temporarily move the result from accumulator into R5 MOV A,R1; Means: move number from R1 to accumulator ADD A,R2; Means: add number from R2 to accumulator SUBB A,R5; Means: subtract number from R5 (there are R3+R4)

Program Status Word (PSW) Register

PSW register is one of the most important SFRs. It contains several status bits that reflect the current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two register bank select bits, Overflow flag, parity bit and user-definable status flag.

P - Parity bit:

If a number stored in the accumulator is even then this bit will be automatically set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via serial communication.
Bit 1:

This bit is intended to be used in the future versions of microcontrollers.

xlix

OV Overflow:

occurs when the result of an arithmetical operation is larger than 255 and cannot be stored in one register. Overflow condition causes the OV bit to be set (1). Otherwise, it will be cleared (0).
RS0, RS1 - Register bank select bits:

These two bits are used to select one of four register banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four banks of RAM.
F0 - Flag 0:

This is a general-purpose bit available for use.


AC - Auxiliary Carry Flag:

is used for BCD operations only.


CY - Carry Flag:

is the (ninth) auxiliary bit used for all arithmetical operations and shift instructions.

Data Pointer Register (DPTR)


DPTR register is not a true one because it doesn't physically exist. It consists of two separate registers: DPH (Data Pointer High) and (Data Pointer Low). The Data Pointer (DPTR) consists of a high byte (DPH) and a low byte (DPL). Its intended function is to hold a 16-bit address. It may be manipulated as a 16-bit register or as two independent 8-bit registers.

Stack Pointer (SP) Register

The Stack Pointer register is 8 bits wide. It is incremented before data is stored during PUSH and CALL executions. While the stack may reside anywhere in on-chip RAM, the Stack Pointer is initialized to 07H after a reset. This causes the stack to begin at locations 08H.
P0, P1, P2, P3 - Input/Output Registers

If neither external memory nor serial communication system are used then 4 ports with in total of 32 input/output pins are available for connection to peripheral environment. Each bit within these ports affects the state and performance of appropriate pin of the

li

microcontroller. Thus, bit logic state is reflected on appropriate pin as a voltage (0 or 5 V) and vice versa, voltage on a pin reflects the state of appropriate port bit. As mentioned, port bit state affects performance of port pins, i.e. whether they will be configured as inputs or outputs. If a bit is cleared (0), the appropriate pin will be configured as an output, while if it is set (1), the appropriate pin will be configured as an input. Upon reset and power-on, all port bits are set (1), which means that all appropriate pins will be configured as inputs.

Serial Data Buffer


The Serial Buffer is actually two separate registers, a transmit buffer and a receive buffer. When data is moved to SBUF, it goes to the transmit buffer and is held for serial transmission. (Moving a byte to SBUF is what initiates the transmission.) When data is moved from SBUF, it comes from the receive buffer.

2.3.3.3. Oscillator Circuits


The 8051 requires the existence of an external oscillator circuit. The oscillator circuit usually runs around 12MHz, although the 8051 (depending on which specific model) is capable of running at a maximum of 40MHz. Each machine cycle in the 8051 is 12 clock cycles, giving an effective cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the maximum 40MHz clock).

lii

2.3.4 Architecture

8051c is a 8bit microcontroller introduced by Intel Corporation in 1981 which comes in 40 pin dual inline package (DIP). It has 4KB of inbuilt ROM i.e onchip program space. It has 128bytes of inbuilt RAM space and if required external memory of 64KB can be interfaced to the microcontroller. There are 4 parallel 8bit ports namely port 0, port 1, port 2 and port 3 which are addressable as well as programmable. It has an onchip crystal oscillator with crystal frequency 11.0592MHz (~12MHz). It has full duplex serial I/O port having two pins namely TxD, RxD. It has two 16bit timers namely Timer 0 and Timer 1 which can be used either as timer for internal operation or as counter for external operation.

liii

It has five interrupt sources. All of them are maskable as well as vector interrupts. They are External Interrupt 0, Timer Interrupt 0, External Interrupt 1, Timer Interrupt 1, Serial Port Interrupt. The programming mode of this microcontroller consists of general purpose registers (GPRs), Special Purpose Registers (SPRs) and Special Function Registers (SFRs). The instruction set of 8051 c consists of more number of bit manipulations or boolean variable manipulation group of instructions. The instructions are very much useful to manipulate SFR bits and also port pins.

2.3.4.1. Internal Architecture


The 8051 Microprocessor can be programmed in PL/M, 8051 Assembly, C and a number of other high-level languages. Many compilers even have support for compiling C++ for an 8051. Program memory in the 8051 is read-only, while the data memory is considered to be read/write accessible. When stored on EEPROM or Flash, the program memory can be rewritten when the microcontroller is in the special programmer circuit.

liv

Fig: 2.3.3. Internal schemits of 8051

lv

Fig: 2.3.4. Block Diagram of 8051 Microcontroller

2.3.4.2. Memory Architecture


The MCS-51 has four distinct types of memory internal RAM, special function registers, program memory, and external data memory. Internal RAM (IRAM) is located from address 0 to address 0xFF. IRAM from 0x00 to 0x7F can be accessed directly, and the bytes from 0x20 to 0x2F are also bitaddressable. IRAM from 0x80 to 0xFF must be accessed indirectly, using the @R0 or @R1 syntax, with the address to access loaded in R0 or R1.

lvi

Special function registers (SFR) are located from address 0x80 to 0xFF, and are accessed directly using the same instructions as for the lower half of IRAM. Some of the SFR's are also bit-addressable. Program memory (PMEM, though less common in usage than IRAM and XRAM) is located starting at address 0. It may be on- or off-chip, depending on the particular model of chip being used. Program memory is read-only, though some variants of the 8051 use on-chip flash memory and provide a method of re-programming the memory in-system or in-application. Aside from storing code, program memory can also store tables of constants that can be accessed by MOVC A, @DPTR, using the 16-bit special function register DPTR. External data memory (XRAM) also starts at address 0. It can also be on- or off-chip; what makes it "external" is that it must be accessed using the MOVX (Move external) instruction. Many variants of the 8051 include the standard 256 bytes of IRAM plus a few KB of XRAM on the chip. If more XRAM is required by an application, the internal XRAM can be disabled, and all MOVX instructions will fetch from the external bus.

2.3.5. Program Start Address


The 8051 starts executing program instructions from address 0x00 in the program memory.

2.3.5.1. Direct Memory


The 8051 has 256 bytes of internal addressable RAM, although only the first 128 bytes are available for general use by the programmer. The first 128 bytes of RAM (from 0x00 to 0x7F) are called the Direct Memory, and can be used to store data.

lvii

2.3.5.2. Special Function Register


The Special Function Register (SFR) is the upper area of addressable memory, from address 0x80 to 0xFF. This area of memory cannot be used for data or program storage, but is instead a series of memory-mapped ports and registers. All port input and output can therefore be performed by memory mov operations on specified addresses in the SFR. Also, different status registers are mapped into the SFR, for use in checking the status of the 8051, and changing some operational parameters of the 8051.

2.3.5.3. General Purpose Registers


The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means that there are essentially 32 available general purpose registers, although only 8 (one bank) can be directly accessed at a time. To access the other banks, we need to change the current bank number in the flag status register.

2.3.5.4. A and B Registers


The A register is located in the SFR memory location 0xE0. The A register works in a similar fashion to the AX register of x86 processors. The A register is called the accumulator, and by default it receives the result of all arithmetic operations. The B register is used in a similar manner, except that it can receive the extended answers from the multiply and divide operations. When not being used for multiplication and Division, the B register is available as an extra general-purpose register.

lviii

2.3.6. Important features and applica


It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a single package

8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8-bit microcontroller

8-bit data bus It can access 8 bits of data in one operation 16-bit address bus It can access 216 memory locations 64 KB

(65536 locations) each of RAM and ROM


On-chip RAM 128 bytes (data memory) On-chip ROM 4 Kbytes (program memory) Four byte bi-directional input/output port UART (serial port) Two 16-bit Counter/timers Two-level interrupt priority Power saving mode (on some derivatives)

A particularly useful feature of the 8051 core is the inclusion of a boolean processing engine which allows bit-level boolean logic operations to be carried out directly and efficiently on internal registers and RAM. This feature helped cement the 8051's popularity in industrial control applications. Another valued feature is that it has four separate register sets, which can be used to greatly reduce interrupt latency compared to the more common method of storing interrupt context on a stack.

lix

The MCS-51 UARTs make it simple to use the chip as a serial communications interface. External pins can be configured to connect to internal shift registers in a variety of ways, and the internal timers can also be used, allowing serial communications in a number of modes, both synchronous and asynchronous. Some modes allow communications with no external components. A mode compatible with an RS-485 multi-point communications environment is achievable, but the 8051's real strength is fitting in with existing ad-hoc protocols (e.g., when controlling serialcontrolled devices). Once a UART, and a timer if necessary, have been configured, the programmer needs only to write a simple interrupt routine to refill the send shift register whenever the last bit is shifted out by the UART and/or empty the full receive shift register (copy the data somewhere else). The main program then performs serial reads and writes simply by reading and writing 8-bit data to stacks. MCS-51 based microcontrollers typically include one or two UARTs, two or three timers, 128 or 256 bytes of internal data RAM (16 bytes of which are bit-addressable), up to 128 bytes of I/O, 512 bytes to 64 kB of internal program memory, and sometimes a quantity of extended data RAM (ERAM) located in the external data space. The original 8051 core ran at 12 clock cycles per machine cycle, with most instructions executing in one or two machine cycles. With a 12 MHz clock frequency, the 8051 could thus execute 1 million one-cycle instructions per second or 500,000 two-cycle instructions per second. Enhanced 8051 cores are now commonly used which run at six, four, two, or even one clock per machine cycle, and have clock frequencies of up to 100 MHz, and are thus capable of an even greater number of instructions per second. All SILabs, some Dallas and a few Atmel devices have single cycle cores. Common features included in modern 8051 based microcontrollers include built-in reset timers with brown-out detection, on-chip oscillators, self-programmable Flash ROM program memory, bootloader code in ROM, EEPROM non-volatile data storage, IC, SPI, and USB host interfaces, CAN or LIN bus, PWM generators, analog

lx

comparators, A/D and D/A converters, RTCs, extra counters and timers, in-circuit debugging facilities, more interrupt sources, and extra power saving modes.

2.3.7. Programming
There are various high-level programming language compilers for the 8051. Several C compilers are available for the 8051, most of which feature extensions that allow the programmer to specify where each variable should be stored in its six types of memory, and provide access to 8051 specific hardware features such as the multiple register banks and bit manipulation instructions. There are many commercial C compilers. SDCC is a popular open source C compiler. Other high level languages such as Forth, BASIC, Pascal/Object Pascal, PL/M and Modula-2 are available for the 8051, but they are less widely used than C and assembly. Because IRAM, XRAM, and PMEM all have an address 0, C compilers for the 8051 architecture provide compiler-specific pragmas or other extensions to indicate where a particular piece of data should be stored (i.e. constants in PMEM or variables needing fast access in IRAM). Since data could be in one of three memory spaces, a mechanism is usually provided to allow determining to which memory a pointer refers, either by constraining the pointer type to include the memory space, or by storing metadata with the pointer.

2.3.8. Instruction set


The MCS-51 instruction set offers several addressing modes, including :

lxi

direct register, using ACC (the accumulator) and R0-R7 direct memory, which access the internal RAM or the SFR's, indirect memory, using R0, R1, or DPTR to hold the memory

depending on the address

address. The instruction used may vary to access internal RAM, external RAM, or program memory.

individual bits of a range of IRAM and some of the SFR's

Many of the operations allow any addressing mode for the source or the destination, for example, MOV 020h, 03fh will copy the value in memory location 0x3f in the internal RAM to the memory location 0x20, also in internal RAM. Because the 8051 is an accumulator-based architecture, all arithmetic operations must use the accumulator, e.g. ADD A, 020h will add the value in memory location 0x20 in the internal RAM to the accumulator. One does not need to master these instructions to program the 8051. With the availability of good quality C compilers, including open source SDCC, virtually all programs can be written with high-level language. 2.6.9 Introduction to assembly programming:
The process of writing program for the microcontroller mainly consists of giving instructions (commands) in the specific order in which they should be executed in order to carry out a specific task. As electronics cannot understand what for example an instruction if the push button is pressed- turn the light on means, then a certain number of simpler and precisely defined orders that decoder can recognise must be used. All commands are known as INSTRUCTION SET. All microcontrollers compatibile with the 8051 have in total of 255 instructions, i.e. 255 different words available for program writing. At first sight, it is imposing number of odd signs that must be known by heart. However, It is not so complicated as it looks like. Many instructions are considered to be different, even though they perform the same operation, so there are only 111 truly different commands. For example: ADD A,R0, ADD A,R1, ... ADD A,R7 are instructions that perform the same operation (additon of the accumulator and register). Since there are 8 such registers, each instruction is counted

lxii

separately. Taking into account that all instructions perform only 53 operations (addition, subtraction, copy etc.) and most of them are rarely used in practice, there are actually 20-30 abbreviations to be learned, which is acceptable.

3.1 Types of instructions


Depending on operation they perform, all instructions are divided in several groups:

Arithmetic Instructions Branch Instructions Data Transfer Instructions Logic Instructions Bit-oriented Instructions

The first part of each instruction, called MNEMONIC refers to the operation an instruction performs (copy, addition, logic operation etc.). Mnemonics are abbreviations of the name of operation being executed. For example:

INC R1 - Means: Increment register R1 (increment register R1); LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as LAB5); JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is not 0, jump to the address marked as LOOP);

The other part of instruction, called OPERAND is separated from mnemonic by at least one whitespace and defines data being processed by instructions. Some of the instructions have no operand, while some of them have one, two or three. If there is more than one operand in an instruction, they are separated by a comma. For example:

RET - return from a subroutine; JZ TEMP - if the number in the accumulator is not 0, jump to the address marked as TEMP; ADD A,R3 - add R3 and accumulator; CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump to the address marked as LOOP;

lxiii

Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction, division, multiplication etc. After execution, the result is stored in the first operand. For example: ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.

ARITHMETIC INSTRUCTIONS Mnemonic ADD A,Rn ADD A,direct ADD A,@Ri ADD A,#data ADDC A,Rn ADDC A,direct ADDC A,@Ri ADDC A,#data SUBB A,Rn SUBB A,direct SUBB A,@Ri SUBB A,#data INC A INC Rn INC Rx INC @Ri DEC A DEC Rn DEC Rx DEC @Ri INC DPTR MUL AB DIV AB DA A Description Adds the register to the accumulator Adds the direct byte to the accumulator Adds the indirect RAM to the accumulator Adds the immediate data to the accumulator Adds the register to the accumulator with a carry flag Adds the direct byte to the accumulator with a carry flag Adds the indirect RAM to the accumulator with a carry flag Adds the immediate data to the accumulator with a carry flag Subtracts the register from the accumulator with a borrow Subtracts the direct byte from the accumulator with a borrow Subtracts the indirect RAM from the accumulator with a borrow Subtracts the immediate data from the accumulator with a borrow Increments the accumulator by 1 Increments the register by 1 Increments the direct byte by 1 Increments the indirect RAM by 1 Decrements the accumulator by 1 Decrements the register by 1 Decrements the direct byte by 1 Decrements the indirect RAM by 1 Increments the Data Pointer by 1 Multiplies A and B Divides A by B Decimal adjustment of the accumulator according to BCD code Byte 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 Cycle 1 2 2 2 1 2 2 2 1 2 2 2 1 2 3 3 1 1 2 3 3 5 5 1

Branch Instructions
There are two kinds of branch instructions:

lxiv

Unconditional jump instructions: upon their execution a jump to a new location from where the program continues execution is executed. Conditional jump instructions: a jump to a new program location is executed only if a specified
BRANCH INSTRUCTIONS Mnemonic ACALL addr11 LCALL addr16 RET RETI AJMP addr11 LJMP addr16 SJMP rel JC rel JNC rel JB bit,rel JBC bit,rel JMP @A+DPTR JZ rel JNZ rel CJNE A,direct,rel CJNE A,#data,rel CJNE Rn,#data,rel CJNE @Ri,#data,rel DJNZ Rn,rel DJNZ Rx,rel NOP Description Absolute subroutine call Long subroutine call Returns from subroutine Returns from interrupt subroutine Absolute jump Long jump Short jump (from 128 to +127 locations relative to the following instruction) Jump if carry flag is set. Short jump. Jump if carry flag is not set. Short jump. Jump if direct bit is set. Short jump. Jump if direct bit is set and clears bit. Short jump. Jump indirect relative to the DPTR Jump if the accumulator is zero. Short jump. Jump if the accumulator is not zero. Short jump. Compares direct byte to the accumulator and jumps if not equal. Short jump. Compares immediate data to the accumulator and jumps if not equal. Short jump. Compares immediate data to the register and jumps if not equal. Short jump. Compares immediate data to indirect register and jumps if not equal. Short jump. Decrements register and jumps if not 0. Short jump. Decrements direct byte and jump if not 0. Short jump. No operation Byte 2 3 1 1 2 3 2 2 2 3 3 1 2 2 3 3 3 3 2 3 1 Cycle 6 6 4 4 3 4 3 3 3 4 4 2 3 3 4 4 4 4 3 4 1

condition is met. Otherwise, the program normally proceeds with the next instruction.

Data Transfer Instructions


Data transfer instructions move the content of one register to another. The register the content of which is moved remains unchanged. If they have the suffix X (MOVX), the data is exchanged with external memory.

lxv

DATA TRANSFER INSTRUCTIONS Mnemonic MOV A,Rn MOV A,direct MOV A,@Ri MOV A,#data MOV Rn,A MOV Rn,direct MOV Rn,#data MOV direct,A MOV direct,Rn MOV direct,direct MOV direct,@Ri MOV direct,#data MOV @Ri,A MOV @Ri,direct MOV @Ri,#data MOV DPTR,#data MOVC A,@A+DPTR MOVC A,@A+PC MOVX A,@Ri MOVX A,@DPTR MOVX @Ri,A MOVX @DPTR,A PUSH direct POP direct XCH A,Rn XCH A,direct XCH A,@Ri XCHD A,@Ri Description Moves the register to the accumulator Moves the direct byte to the accumulator Moves the indirect RAM to the accumulator Moves the immediate data to the accumulator Moves the accumulator to the register Moves the direct byte to the register Moves the immediate data to the register Moves the accumulator to the direct byte Moves the register to the direct byte Moves the direct byte to the direct byte Moves the indirect RAM to the direct byte Moves the immediate data to the direct byte Moves the accumulator to the indirect RAM Moves the direct byte to the indirect RAM Moves the immediate data to the indirect RAM Moves a 16-bit data to the data pointer Moves the code byte relative to the DPTR to the accumulator (address=A+DPTR) Moves the code byte relative to the PC to the accumulator (address=A+PC) Moves the external RAM (8-bit address) to the accumulator Moves the external RAM (16-bit address) to the accumulator Moves the accumulator to the external RAM (8-bit address) Moves the accumulator to the external RAM (16-bit address) Pushes the direct byte onto the stack Pops the direct byte from the stack/td> Exchanges the register with the accumulator Exchanges the direct byte with the accumulator Exchanges the indirect RAM with the accumulator Exchanges the low-order nibble indirect RAM with the accumulator Byte 1 2 1 2 1 2 2 2 2 3 2 3 1 2 2 3 1 1 1 1 1 1 2 2 1 2 1 1 Cycle 1 2 2 2 2 4 2 3 3 4 4 3 3 5 3 3 3 3 3-10 3-10 4-11 4-11 4 3 2 3 3 3

Logic Instructions
Logic instructions perform logic operations upon corresponding bits of two registers. After execution, the result is stored in the first operand.
LOGIC INSTRUCTIONS Mnemonic Description Byte Cycle

lxvi

ANL A,Rn ANL A,direct ANL A,@Ri ANL A,#data ANL direct,A ANL direct,#data ORL A,Rn ORL A,direct ORL A,@Ri ORL direct,A ORL direct,#data XRL A,Rn XRL A,direct XRL A,@Ri XRL A,#data XRL direct,A XORL direct,#data CLR A CPL A SWAP A RL A RLC A RR A RRC A

AND register to accumulator AND direct byte to accumulator AND indirect RAM to accumulator AND immediate data to accumulator AND accumulator to direct byte AND immediae data to direct register OR register to accumulator OR direct byte to accumulator OR indirect RAM to accumulator OR accumulator to direct byte OR immediate data to direct byte Exclusive OR register to accumulator Exclusive OR direct byte to accumulator Exclusive OR indirect RAM to accumulator Exclusive OR immediate data to accumulator Exclusive OR accumulator to direct byte Exclusive OR immediate data to direct byte Clears the accumulator Complements the accumulator (1=0, 0=1) Swaps nibbles within the accumulator Rotates bits in the accumulator left Rotates bits in the accumulator left through carry Rotates bits in the accumulator right Rotates bits in the accumulator right through carry

1 2 1 2 2 3 1 2 1 2 3 1 2 1 2 2 3 1 1 1 1 1 1 1

1 2 2 2 3 4 1 2 2 3 4 1 2 2 2 3 4 1 1 1 1 1 1 1

Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that these are performed upon single bits.
BIT-ORIENTED INSTRUCTIONS Mnemonic CLR C CLR bit SETB C SETB bit Description Clears the carry flag Clears the direct bit Sets the carry flag Sets the direct bit Byte 1 2 1 2 Cycle 1 3 1 3

lxvii

CPL C CPL bit ANL C,bit ANL C,/bit ORL C,bit ORL C,/bit MOV C,bit MOV bit,C

Complements the carry flag Complements the direct bit AND direct bit to the carry flag AND complements of direct bit to the carry flag OR direct bit to the carry flag OR complements of direct bit to the carry flag Moves the direct bit to the carry flag Moves the carry flag to the direct bit

1 2 2 2 2 2 2 2

1 3 2 2 2 2 2 3

3.2 Description of all 8051 instructions


Here is a list of the operands and their meanings:

A - accumulator; Rn - is one of working registers (R0-R7) in the currently active RAM memory bank;

Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a SFR (I/O port, control register etc.); @Ri - is indirect internal or external RAM location addressed by register R0 or R1; #data - is an 8-bit constant included in instruction (0-255); #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (065535); addr16 - is a 16-bit address. May be anywhere within 64KB of program memory; addr11 - is an 11-bit address. May be within the same 2KB page of program memory as the first byte of the following instruction; rel - is the address of a close memory location (from -128 to +127 relative to the first byte of the following instruction). On the basis of it, assembler computes the value to add or subtract from the number currently stored in the program counter;

bit - is any bit-addressable I/O pin, control or status bit; and C - is carry flag of the status register (register PSW).

lxviii

S.NO. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.

Name of Hardware.
40 pin IC base 8051 p89B51RD2FN MCU XTAL(11.0592Mhz) Capacitor 30pF 10k POT LCD 7085 regulator Pull-up resistor G.P. PCB Berg strip LED

Quantity
1 1 1 2 1 1 1 1 1

Wires Resistance Multimeter 12v DC supply source Soldering wires, soldering iron ,Flux

As required. 8 As required As required 1

lxix

LCD Commands Codes


Code(HEX) 1 2 4 6 5 7 8 A C E F 10 14 18 1C 80 C0 38

Command to LCD Instruction Register


Clear Display Screen. Return Home. Decrement cursor( shift cursor to left) Increment cursor( shift cursor to lift) Shift display right Shift display left Display off, cursor off Display off, cursor on Dicplay on, cursor off Display on, cursor blinking Display on, cursor blinking Shift cursorposition to left Shift cursor position to right Shift the entire display to the left Shift to the entire display to the right Force cursor to beginning of first line Force cursor to beginning of second line 2 lines and 5*7 matrix

REFERENCES
lxx

1) www.8051projects.com 2) Google.com 3) http://www.seminarprojects.com 4) http://www.esnips.com

CONCLUSION

lxxi

You might also like