Embedded Systems Ducat Gurgaon: Training Report
Embedded Systems Ducat Gurgaon: Training Report
Embedded Systems Ducat Gurgaon: Training Report
ON
EMBEDDED SYSTEMS
AT
DUCAT GURGAON
Period of Training (From July 17, 2011 to August 25, 2011)
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.
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
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
xi
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.
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
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
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
485 etc.
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 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.
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.
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.
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).
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
volatile memory (RAM) for data storage ROM, EPROM, EEPROM or Flash memory for program and
clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit
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
xxxiii
xxxiv
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
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.
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
xli
xlii
2.3.3.2 .Ports
There are 4 8-bit ports: P0, P1, P2 and P3.
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).
xlv
xlvi
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)
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:
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:
is the (ninth) auxiliary bit used for all arithmetical operations and shift instructions.
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.
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.
liv
lv
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.
lvii
lviii
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
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.
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
address. The instruction used may vary to access internal RAM, external RAM, or program memory.
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.
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.
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
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
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
lxix
REFERENCES
lxx
CONCLUSION
lxxi