You are on page 1of 33

INTRODUCTION TO EMBEDDED SYSTEMS:Microcontrollers are widely used in Embedded System products.

An Embedded product uses the microprocessor (or microcontroller) to do one task & one task only . A printer is an example of embedded system since the processor inside it performs one task only namely getting the data and printing it. Contrast this with Pentium based PC. A PC can be used for any no. of applications such as word processor, print server, bank teller terminal, video game player, network server or internet terminal. Software for variety of applications can be loaded and run. Of course the reason a PC can perform multiple tasks is that it has RAM memory and an operating system that loads the application software into RAM & lets the CPU run it. In and Embedded system there is only one application software that is typically burn into ROM. An x86PC Contain or its connected to various Embedded Products such as keyboard, printer, modem, Disc controller, Soundcard, CD-ROM Driver, Mouse & so on. Each one of these peripherals as a microcontroller inside it that performs only one task. For example inside every mouse there is microcontroller to perform the task of finding the mouse position and sending it to PC. Although microcontrollers are preferred choice for many embedded systems, there are times that a microcontroller is inadequate for the task. For this reason in recent years many manufactures of general purpose microprocessors such as INTEL, Motorola, and AMD & Cyrix have targeted their microprocessors for the high end of embedded market. While INTEL, AMD, Cyrix push their x86 processors for both the embedded and desktop pc market, Motorola is determined to keep the 68000 families alive by targeting it mainly for high end of embedded system .One of the most critical needs of the embedded system is to decrease power consumptions and space. This can be achieved by integrating more functions into the CPU chips. All the embedded processors based on the x86 and 680x0have low power consumptions in additions to some forms of I/O, Com port & ROM all on a single chip. In higher performance Embedded system the trend is to integrate more & more function on the CPU chip & let the designer decide which feature he/she wants to us. EMBEDDED SYSTEM: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. Embedded systems are often mass produced, so the cost savings may be multiplied by million of items. The core of any embedded system is formed by one or several microprocessor or micro controller programmed to perform a small number of tasks. In contrast to a general purpose computer, which can run any software application, the user chooses, the software on an embedded system is semi-permanent, so it is often called firmware. Variety Of Embedded systems: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 router sand network bridges to route data. Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones, videogame consoles, digital cameras, DVD players, GPS receivers, and printers. Man y 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 wirelessnetworking 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 equipment is continuing to advance with more embedded systems for vital signs monitoring, electronic stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT, and MRI) for non-invasive internal inspections. 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 Characteristic:1. 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 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 or Flash memory chips. They run with limited computer hardware resources: little memory, small or non-existent keyboard and/or screen 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 telephones and telephonic switches. Computer network equipment, including routers timeservers and firewalls Computer printers, Copiers. Disk drives (floppy disk drive and hard disk drive 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. Measurement equipment such as digital storage oscilloscopes, logic analyzers and spectrum analyzers. Multimedia appliances: internet radio receivers, TV set top boxes. Personal digital assistants (PDAs), i.e., small hand held computer withP1M5 and other applications.

Programmable logic controllers (PLCs) for industrial automation and monitoring. Stationary video game controllers. Wearable computers.

MICROCONTROLLER v/s MICROPROCESSOR :Microprocessor and microcontroller are two popular terms in world of computer. However, microprocessor and microcontroller has different functions and features. Microprocessors generally require external components or circuits to implement program memory, RAM memory and Input/Output. Intel's 8085, 80386 and Pentium are examples of microprocessors. Microcontrollers incorporate program memory, RAM memory an d input/output port into one chip. Microchip's PIC series and Atmel's AVR series are examples of microcontrollers. One of the main differences is that microcontrollers are usually designed to perform a small set of specific functions, for example as in the case of a Automatic Braking System which performs a small set of input processing functions, whereas microprocessors te nd to be designed to perform a wider set of general purpose functions. For example, microcontrollers are widely used in modern cars where they will each perform a dedicated task, i.e. mic rocontroller to regulate the brakes on all four wheels, or a microcontroller to regulate the car air conditioning, or a microcontroller for automatic gate systems. These microcontrollers will perform few other tasks (if any) other than those specified . Compare to a microprocessor in a PC which performs a wide range of tasks related to the general requirements of a PC such as performing the necessary calculations for a very wide set of software applications, performing Input/Output for the main subsystems, peripheral control and etc. VARIOUS MICROCONTROLLERS:First Microcontroller is 8031: FEATURES

1. It is Intels product. Neither a microprocessor nor a microcontroller

2. It is a 8-bit controller. 3. Internally no ROM is provided i.e. code is outside the chip. Second Microcontroller is 8051
FEATURES

1. It is a first complete 8-bit microcontroller. 2. It is a name of a family. In which the instruction set, pin configuration , architecture are same, only memory storage capacity is different 3. Internally PROM (programmable read only memory) is provided so it called one time programmable (OTP). Third Microcontroller is AT89C51
FEATURES

1. It is a similar to 8051 microcontroller i.e. having same instruction set, pin configuration, architecture. 2. It is a also 8-bit microcontroller. Its cost is only Rs10 more than 8051. 3. It uses EPROM (erasable programmable read only memory) or FLASH memory. 4. It is Multiple time programmable (MTP) i.e. 1000 times. So it is better than 8051.

THE 8051 MICROCONTROLLER :The 8051 provides the following standard features: 4Kbytes of ROM, 128 bytes of RAM , 32 I/O lines , two1 6-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator and clock circuitry .In addition ,the8051 is designed with static logic for operation down to zero frequency and supports Two software selectable power saving modes. The Idle Modes tops the CPU while allowing the RAM, timer /counters, serial port and interrupt system to continue functioning. The Power down Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset

What is 8051 Standard? Microcontrollers producers have been struggling for a long time for attracting more and more choosy customers. Every couple of days a new chip with a higher operating frequency, more memory and more high-quality A/D converters comes on the market. Nevertheless, by analyzing their structure it is concluded that most of them have the same (or at least very similar) architecture known in the product catalogs as 8051compatib le. What is all this about? The whole story began in the far 80s when Intel launched its series of the microcontrollers labeled with MCS 051. Although, several circuits belonging to this series had quite modest features in comparison to the new ones, they took over the world very fast and became a standard for what nowadays is meant by a word microcontroller. The reason for success and such a big popularity is a skillfully chosen configuration which satisfies needs of a great number of the users allowing at the same time stable expanding (refers to the new types of the microcontrollers ). Besides, since a great deal of software has been developed in the meantime, it simply was not profitable to change anything in the microcontrollers basic core. That is the reason for having a great number of various microcontrollers which actually are solely upgraded versions of the 8051family. What is it what makes this microcontroller so special and universal so that almost all the world producers manufacture it today under different name?

As shown on the previous picture, the 8051 microcontroller has nothing impressive at First sight: 4 Kb program memories is not much at all. 128Kb RAM (including SFRs as well) satisfies basic needs, but it is not imposing amount. 4 ports having in total of 32 input/output lines are mostly enough to make connection to peripheral environment and are not luxury at all. As it is shown on the previous picture, the 8051 microcontroller have nothing impressive at first sight: The whole configuration is obviously envisaged as such to satisfy the needs of most programmers who work on development of automation devices. One of advantages of this microcontroller is that nothing is missing and nothing is too much. In other words, it is created exactly in accordance to the average users taste and needs. The other advantage is the way RAM is organized, the way Central Processor Unit (CPU) operates and ports which maximally use all recourses and enable further upgrading. 8051 Microcontroller's pins:Pins 1-8: Port 1 each of these pins can be configured as input or output. Pin 9: RS Logical one on this pin stops microcontrollers operating and erases the contents of most registers. By applying logical zero to this pin, the program starts execution from the beginning. In other words, a positive voltage pulse on this pin resets the microcontroller. Pins10-17: Port 3 Similar to port 1, each of these pins can serve as universal input or output. Besides, all of them have alternative functions: Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication output.

Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication clock output. Pin 12:INT0 Interrupt 0 inputs Pin 13:INT1 Interrupt 1 input Pin 14:T0 Counter 0 clock input Pin 15:T1 Counter 1 clock input Pin 16: WR Signal for writing to external (additional) RAM Pin 17: RD Signal for reading from external RAM Pin 18, 19: X2 X1 Internal oscillator input and output. A quartz crystal which determines operating frequency is usually connected to these pins. Instead of quartz crystal, the miniature ceramics resonators can be also used for frequency stabilization. Later versions of the microcontrollers operate at a frequency of 0 Hz up to over 50 Hz.

Pin 20: GND Ground Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as universal inputs/outputs. In case external memory is used then the higher address byte, i.e. addresses A8-A15 will appear on this port. It is important to know that even memory with capacity of 64Kb is not used ( i.e. note all bits on port are used for memory addressing) the rest of bits are not available as inputs or outputs. Pin 29: PSEN if external ROM is used for storing program then it has a logic-0 value every time the microcontroller reads a byte from memory. Pin 30: ALE Prior to each reading from external memory, the microcontroller will set the lower address byte (A0-A7) on P0 and immediately after that activates the output ALE. Upon receiving signal from the ALE pin, the external register (74HCT373 or 74HCT375circuit is usually embedded) memorizes the state of P0 and uses it as an address for memory chip. In the second part of the microcontrollers machine cycle, a signal on this pin stops being emitted and P0 is used now for data transmission (Data Bus). In this way, By means of only one additional (and cheap) integrated circuit, data multiplexing from the port is performed. This port at the same time used for data and address transmission. Pin 31:EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. That means that even there is a program written to the microcontroller, it will not be executed, the program written to external ROM will be used instead. Otherwise, by applying logic one to the EA pin, the microcontroller will use both memories, first internal and afterwards external (if it exists), up to end of address space. Pin 32-39: Port 0 Similar to port 2, if external memory is not used, these pins can be used as universal inputs or outputs. Otherwise, P0 is configured as address output (A0-A7)when the ALE pin is at high level (1) and as data output (Data Bus), when logic zero (0)is applied to the ALE pin. Pin 40: VCC Power supply +5V

8051 Microcontroller Memory Organization:-

The microcontroller memory is divided into Program Memory and Data Memory. Program Memory (ROM) is used for permanent saving program being executed, while Data Memory (RAM) is used for temporarily storing and keeping intermediate results and variables. Depending on the model in use ( still referring to the whole 8051microcontroller family) at most a few Kb of ROM and 128 or 256 bytes of RAM can be used .All 8051 microcontrollers have 16-bit addressing bus and can address 64 kb memory. It is neither a mistake nor a big ambition of engineers who were working on basic core development. It is a matter of very clever memory organization which makes these controllers a real programmers tidbit Program Memory:The oldest models of the 8051 microcontroller family did not have internal program memory. It was added from outside as a separate chip. These models are recognizable by their label beginning with 803 ( for ex. 8031 or 8032). All later models have a few Kbytes ROM embedded, Even though it is enough for writing most of the programs, there are situations when additional memory is necessary. A typical example of it is the use of so called lookup tables. They are used in cases when something is too complicated or when there is no time for solving equations describing some process. The example of it can be totally exotic (an estimate of self-guided rockets meeting point) or totally common (measuring of temperature using non-linear thermo element or a synchronous motor speed control). In those cases all needed estimates and approximates are executed in advance and the final results are put in the tables (similar to logarithmic tables). EA=0 in this case, internal program memory is completely ignored, only a program stored in external memory is to be executed. EA=1 in this case, a program from built in ROM is to be executed first (to the last location). Afterwards, the execution is continued by reading additional memory. in both cases, P0 and P2 are not available to the user because they are used for data address transmission..

Besides, the pins ALE and PSEN are used too. Data Memory:As already mentioned, Data Memory is used for temporarily storing and keeping data and intermediate results created and used during microcontrollers operating. Besides, this microcontroller family includes many other registers such as: hardware counters and timers, input/output ports, serial data buffers etc. The previous versions have the total memory size of 256 locations, while for later models this number is incremented by additional 128 available registers. In both cases, these first 256 memory locations (addresses 0-FFh) are the base of the memory. Common to all types of the 8051microcontrollers. Locations available to the user occupy memory space with addresses from 0 to 7Fh. First 128 registers and this part of RAM is divided in several blocks. The first block consists of 4 banks each including 8 registers designated as R0 to R7.Prior to access them, a bank containing that register must be selected. Next memory block (in the range of 20h to 2Fh) is bit- addressable, which means that each

bit being there has its own address from 0 to 7Fh. Since there are 16 such registers, this block contains in total of 128 bits with separate addresses (The 0th bit of the 20h byte has the bit address 0 and the 7th bit of the 2Fh byte has the bit address 7Fh). The third groups of registers occupy addresses 2Fh-7Fh (in total of 80 locations) and does not have any special purpose or feature. Additional Memory Block of Data Memory:In order to satisfy the programmers permanent hunger for Data Memory, producers have embedded an additional memory block of 128 locations into the latest versions of the8051 microcontrollers. Naturally, its not so simpleThe problem is that electronics performing addressing has 1 byte (8 bits) on disposal and due to that it can reach only the first 256 locations. In order to keep already existing 8-bit architecture

and compatibility with other existing models a little trick has been used. Using trick in this case means that additional memory block shares the same addresses with existing locations intended for the SFRs (80h- FFh). In order to differentiate between these two physically separated memory spaces, different ways of addressing are used. A direct addressing is used for all locations in the SFRs, while the locations from additional RAM are accessible using indirect addressing. How to extend memory? In case on-chip memory is not enough, it is possible to add two external memory chips with capacity of 64Kb each. I/O ports P2 and P3 are used for their addressing and data transmission.

From the users perspective, everything functions quite simple if properly connected because the most operations are performed by the microcontroller itself. The 8051microcontroller has two separate reading signals RD#(P3.7) and PSEN#. The first one is activated byte from external data memory (RAM) should be read, while another one is activated to read byte from external program memory (ROM). These both signals are active at logical zero (0) level. A typical example of such memory extension using special chips for RAM and ROM, is shown on the previous picture. It is called Hardward architecture. Even though the additional memory is rarely used with the latest versions of the microcontrollers, it will be described here in short what happens when memory chips are connected according to the previous schematic. It is important to know that the whole process is performed automatically, i.e. with no intervention in the program. When the program during execution encounters the instruction which resides in external memory (ROM), the microcontroller will activate its control output ALEand set the first 8 bits of address (A0-A7) on P0. In this way, IC circuit74HCT573 which "lets in" the first 8 bits to memory address pins is activated. A signal on the pin ALE closes the IC circuit 74HCT573 and immediately afterwards 8 higher bits of address (A8-A15) appear on the port. In this way, a desired location in additional program memory is completely addressed. The only thing left over is to read its content. Pins on P0 are configured as inputs, the pin PSEN is activated and the microcontroller reads content from memory chip. The same connections are used both for data and lower address byte. Similar occurs when it is a needed to read some location from external Data Memory. Now, addressing is performed in the same way, while reading or writing is performed via signals which appear on the control outputs RD or WR. SPECIAL FUNCTION REGISTERS:-

The 8051 operations that do not use the internal 128-byte Ram addresses from 00h to 7Fhare done by a group of specific internal register, each called a special function register (SFR).SFRs are a kind of control table used for running and monitoring microcontrollers operating. Each of these registers, even each bit they include, has its name, address in the scope of RAM and clearly defined purpose ( for example: timer control, interrupt, serial connection etc.). Even though there are 128 free memory locations intended for their storage, the basic core, shared by all types of 8051 controllers, has only 21 such registers. Rests of locations are intentionally left free in order to enable the producers to further improved models keeping at the same time

compatibility with the previous versions. It also enables the use of programs written a long time ago for the microcontrollers which are out of production now

1). 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 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.

2). 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).

3). 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.

4). 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. 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 selects 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.

RS1 0 0 1 1

RS2 0 1 0 1

SPACE IN RAM Bank0 00h-07h Bank1 08h-0Fh Bank2 10h-17h Bank3 18h-1Fh

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). For this reason it may be treated as a 16-bit register or as two independent 8-bit registers. Their 16 bits are primarily used for external memory addressing. Besides, the DPTR Register is usually used for storing data and intermediate results.

Stack Pointer (SP) Register:-

A value stored in the Stack Pointer points to the first free stack address and permits stack availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack Pointer, which means that the space of RAM reserved for the stack starts at this location. If another value is written to this register, the entire Stack is moved to the new memory location.

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 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. ADDRESSING MODES:An "addressing mode" refers to how you are addressing a given memory location. In summary ,the addressing modes are as follows, with an example of each: Immediate addressing:Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. That is to say, the instruction itself dictates what value will be stored in memory. For example, the instruction: MOV A,#20h This instruction uses Immediate Addressing because the Accumulator will be loaded with the value that immediately follows; in this case 20 (hexadecimal).Immediate addressing is very fast since the value to be loaded is included in the instruction. However, since the value to be loaded is fixed at compile-time it is not very flexible. Direct Addressing:Direct addressing is so-named because the value to be stored in memory is obtained by directly retrieving it from another memory location. For example: MOV A,30h This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the Accumulator. Direct addressing is generally fast since, although the value to be loaded isnt included in the instruction, it is quickly accessible since it is

stored in the 8051s Internal RAM. It is also much more flexible than Immediate Addressing since the value to be loaded is whatever is found at the given address-which may be variable. Also, it is important to note that when using direct addressing any instruction which refers to an address between 00h and 7Fh is referring to Internal Memory. Any instruction which refers to an address between 80h and FFh is referring to the SFR control registers that control the 8051microcontroller itself. Register addressing:The register banks, containing registers R0 through R7, can be accessed by certain instructions which carry a 3-bit register specification within the opcode of the instruction. Instructions that access the registers this way are code efficient, since this mode eliminates an address byte. When the instruction is executed, one of the eight registers in the selected bank is accessed. One of four banks is selected at execution time by the two bank select bits in the PSW. Register indirect addressing:Indirect addressing is a very powerful addressing mode which in many cases provides an exceptional level of flexibility. Indirect addressing is also the only way to access the extra 128 bytes of Internal RAM found on an 8052.Indirect addressing appears as follows: MOV A,@R0 This instruction causes the 8051 to analyze the value of the R0 register. The 8051 will then load the accumulator with the value from Internal RAM which is found at the address indicated by R0. Indexed addressing:Used in accessing data elements of look up table entries located in the program ROM space of 8051eg. MOVC A@A+DPTR

Counters and Timers:As you already know, the microcontroller oscillator uses quartz crystal for its operation. As the frequency of this oscillator is precisely defined and very stable,

pulses it generates are always of the same width, which makes them ideal for time measurement. Such crystals are also used in quartz watches. In order to measure time between two events it is sufficient to count up pulses coming from this oscillator. That is exactly what the timer does. If the timer is properly programmed, the value stored in its register will be incremented (or decremented) with each coming pulse, i.e. once per each machine cycle. A single machine-cycle instruction lasts for 12 quartz oscillator periods, which means that by embedding quartz with oscillator frequency of 12MHz, a number stored in the timer register will be changed million times per second, i.e. each microsecond. The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their main purpose is to measure time and count external events. Besides, they can be used for generating clock pulses to be used in serial communication, so called Baud Rate. TMOD Register (Timer Mode):The TMOD register selects the operational mode of the timers T0 and T1. As seen in figure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 - bit7) refer to the timer 1. There are 4 operational modes and each of them is described herein.

Bits of this register have the following function: GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3): 1 - Timer 1 operates only if the INT1 bit is set. 0 - Timer 1 operates regardless of the logic state of the INT1 bit. C/T1 selects pulses to be counted up by the timer/counter 1: 1 - Timer counts pulses brought to the T1 pin (P3.5). 0 - Timer counts pulses from internal oscillator. T1M1,T1M0 These two bits select the operational mode of the Timer 1.

T1M1 0 0

T1M0 0 1

MODE 0 1

DESCRIPTION 13-bit timer 16-bit timer

1 1

0 1

2 3

8-bit auto-reload Split mode

GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2): 1 - Timer 0 operates only if the INT0 bit is set. 0 - Timer 0 operates regardless of the logic state of the INT0 bit. C/T0 selects pulses to be counted up by the timer/counter 0: 1 - Timer counts pulses brought to the T0 pin (P3.4). 0 - Timer counts pulses from internal oscillator. T0M1, T0M0 These two bits select the operational mode of the Timer 0.
T0M1 0 0 1 1 T0M0 0 1 0 1 MODE 0 1 2 3 DESCRIPTION 13-bit timer 16-bit timer 8-bit auto-reload Split mode

Timer Control (TCON) Register:TCON register is also one of the registers whose bits are directly in control of timer operation. Only 4 bits of this register are used for this purpose, while rest of them is used for interrupt control to be discussed later.

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

UART (Universal Asynchronous Receiver and Transmitter):One of the microcontroller features making it so powerful is an integrated UART, better known as a serial port. It is a full-duplex port, thus being able to transmit and receive data simultaneously and at different baud rates. Without it, serial data send and receive would be an enormously complicated part of the program in which the pin state is constantly changed and checked at regular intervals. When using UART, all the programmer has to do is to simply select serial port mode and baud rate. When it's done, serial data transmit is nothing but writing to the SBUF register, while data receive represents reading the same register. The microcontroller takes care of not making any error during data transmission.

Serial port must be configured prior to being used. In other words, it is necessary to determine how many bits is contained in one serial word, baud rate and synchronization clock source. The whole process is in control of the bits of the SCON register (Serial Control). Serial Port Control (SCON) Register:-

SM0 - Serial port mode bit 0 is used for serial port mode selection. SM1 - Serial port mode bit 1. SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit. When set, it enables multiprocessor communication in mode 2 and 3, and eventually mode 1. It should be cleared in mode 0. REN - Reception Enable bit enables serial reception when set. When cleared, serial reception is disabled.

TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of transmitting the 9th bit in modes 2 and 3. It is set to transmit logic 1 in the 9th bit. RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th bit received is a logic 0. Set by hardware if 9th bit received is logic 1. TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent. It's a signal to the processor that the line is available for a new byte transmitted. It must be cleared from within the software. RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte is received and should be read quickly prior to being replaced by a new data. This bit is also cleared from within the software. As seen, serial port mode is selected by combining the SM0 and SM2 bits:

SM0 0 0 1 1

SM1 0 1 0 1

MODE 0 1 2 3

DESCRIPTION 8-bit Shift Register 8-bit UART 9-bit UART 9-bit UART

BAUD RATE 1/12 the quartz frequency Determined by the timer 1

1/32 the quartz frequency (1/64 the quartz frequenc Determined by the timer 1

8051 Microcontroller Interrupts:There are five interrupt sources for the 8051, which means that they can recognize 5 different events that can interrupt regular program execution. Each interrupt can be enabled or disabled by setting bits of the IE register. Likewise, the whole interrupt system can be disabled by clearing the EA bit of the same register. Refer to figure below. Now, it is necessary to explain a few details referring to external interrupts- INT0 and INT1. If the IT0 and IT1 bits of the TCON register are set, an interrupt will be generated on high to low transition, i.e. on the falling pulse edge (only in that moment). If these bits are cleared, an interrupt will be continuously executed as far as the pins are held low.

IE Register (Interrupt Enable):-

EA - global interrupt enable/disable: 0 - Disables all interrupt requests. 1 - Enables all individual interrupt requests. ES - enables or disables serial interrupt: 0 - UART system cannot generate an interrupt. 1 - UART system enables an interrupt. ET1 - bit enables or disables Timer 1 interrupt: 0 - Timer 1 cannot generate an interrupt. 1 - Timer 1 enables an interrupt. EX1 - bit enables or disables external 1 interrupt:

0 - change of the pin INT0 logic state cannot generate an interrupt. 1 - Enables an external interrupt on the pin INT0 state change. ET0 - bit enables or disables timer 0 interrupt: 0 - Timer 0 cannot generate an interrupt. 1 - Enables timer 0 interrupt. EX0 - bit enables or disables external 0 interrupt: 0 - change of the INT1 pin logic state cannot generate an interrupt. 1 Enables an external interrupt on the pin INT1 state change. Interrupt Priorities:It is not possible to for seen when an interrupt request will arrive. If several interrupts are enabled, it may happen that while one of them is in progress, another one is requested. In order that the microcontroller knows whether to continue operation or meet a new interrupt request, there is a priority list instructing it what to do. The priority list offers 3 levels of interrupt priority: Reset! The absolute master. When a reset request arrives, everything is stopped and the microcontroller restarts. Interrupt priority 1 can be disabled by Reset only.

Interrupt priority 0 can be disabled by both Reset and interrupt priority 1. The IP Register (Interrupt Priority Register) specifies which one of existing interrupt sources have higher and which one has lower priority. Interrupt priority is usually specified at the beginning of the program. According to that, there are several possibilities: If an interrupt of higher priority arrives while an interrupt is in progress, it will be immediately stopped and the higher priority interrupt will be executed first. If two interrupt requests, at different priority levels, arrive at the same time then the higher priority interrupt is serviced first. If the both interrupt requests, at the same priority level, occur one after another, the one which came later has to wait until routine being in progress ends. If two interrupt requests of equal priority arrive at the same time then the interrupt to be serviced is selected according to the following priority list: External interrupt INT0 Timer 0 interrupt External Interrupt INT1 Timer 1 interrupt Serial Communication Interrupt IP Register (Interrupt Priority):The IP register bits specify the priority level of each interrupt (high or low priority).

PS - Serial Port Interrupt priority bit Priority 0 Priority 1 PT1 - Timer 1 interrupt priority Priority 0 Priority 1 PX1 - External Interrupt INT1 priority Priority 0

Priority 1 PT0 - Timer 0 Interrupt Priority Priority 0 Priority 1 PX0 - External Interrupt INT0 Priority Priority 0 Priority 1 Reset:Reset occurs when the RS pin is supplied with a positive pulse in duration of at least 2 machine cycles (24 clock cycles of crystal oscillator). After that, the microcontroller generates an internal reset signal which clears all SFRs, except SBUF registers, Stack Pointer and ports (the state of the first two ports is not defined, while FF value is written to the ports configuring all their pins as inputs). Depending on surrounding and purpose of device, the RS pin is usually connected to a power-on reset push button or circuit or to both of them. Figure below illustrates one of the simplest circuit providing safe power-on reset.

Basically, everything is very simple: after turning the power on, electrical capacitor is being charged for several milliseconds through a resistor connected to the ground. The pin is driven high during this process. When the capacitor is charged, power supply voltage is already stable and the pin remains connected to the ground, thus providing normal operation of the microcontroller. Pressing the reset button causes

the capacitor to be temporarily discharged and the microcontroller is reset. When released, the whole process is repeated

8051 Microcontroller Power Consumption Control:Generally speaking, the microcontroller is inactive for the most part and just waits for some external signal in order to takes its role in a show. This can cause some problems in case batteries are used for power supply. In extreme cases, the only solution is to set the whole electronics in sleep mode in order to minimize consumption. A typical example is a TV remote controller: it can be out of use for months but when used again it takes less than a second to send a command to TV receiver. The AT89S53 uses approximately 25mA for regular operation, which doesn't make it a power-saving microcontroller. Anyway, it doesnt have to be always like that, it can easily switch the operating mode in order to reduce its total consumption to approximately 40uA. Actually, there are two power-saving modes of operation: Idle and Power Down. Idle mode:Upon the IDL bit of the PCON register is set, the microcontroller turns off the greatest power consumer- CPU unit while peripheral units such as serial port, timers and interrupt system continue operating normally consuming 6.5mA. In Idle mode, the state of all registers and I/O ports remains unchanged. In order to exit the Idle mode and make the microcontroller operate normally, it is necessary to enable and execute any interrupt or reset. It will cause the IDL bit to be automatically cleared and the program resumes operation from instruction having set the IDL bit. It is recommended that first three instructions to execute now are NOP instructions. They don't perform any operation but provide some time for the microcontroller to stabilize and prevents undesired changes on the I/O ports. Power Down Mode:By setting the PD bit of the PCON register from within the program, the microcontroller is set to Power down mode, thus turning off its internal oscillator and reduces power consumption enormously. The microcontroller can operate using only 2V power supply in power- down mode, while a total power consumption is less than 40uA. The only way to get the microcontroller back to normal mode is by reset.

While the microcontroller is in Power Down mode, the state of all SFR registers and I/O ports remains unchanged. By setting it back into the normal mode, the contents of the SFR register is lost, but the content of internal RAM is saved. Reset signal must be long enough, approximately 10mS, to enable stable operation of the quartz oscillator. PCON register:-

The purpose of the Register PCON bits is: SMOD Baud rate is twice as much higher by setting this bit. GF1 General-purpose bit (available for use). GF1 General-purpose bit (available for use). GF0 General-purpose bit (available for use). PD By setting this bit the microcontroller enters the Power Down mode. IDL By setting this bit the microcontroller enters the Idle mode.

TABLE OF CONTENTS
Introduction..........................................................................................

Microprocessor v/s Microcontroller.....................................................

Embedded Systems...............................................................................

8051 Pins..

Types of Microcontrollers.....................................................................

8051 Family............................................................................................

8051 Microcontroller Memory Organization

Special Function Registers.

8051 Addressing Modes..

8051 Microcontroller Interrupts

ACKNOWLEDGEMENT
Success is a sweet fruit, which everyone strives to taste. To achieve this goal, one has to put in a lot of physical and mental efforts. Each time we write this report, gain stronger appreciation for the following fact: we couldnt do it without the help of many talented and dedicated people. So we wish to express our appreciation to those whose help has been most valuable. Firstly, we would like to express our gratitude and appreciation to (Head of company). who explained us everything about the training process at the company and made us familiar with the company staff. We are equally grateful to . (Instructor who sorted out many of our problems regarding the training and gave us proper material to work with. We are also grateful to..who is always there to help us out in our problematic time. We are also grateful to..(Training and Placement Officer ,HEC)for arranging the six months training for us and providing us with all the necessary information about the same. Finally, we would like to say thanks to all the people of the company for their kind co-operation.

INDUSTRIAL TRAINING REPORT ON EMBEDDED SYSTEM AND MICROCONTROLLER

&
SUBMITTED TO:Er. RUPINDER KAUR

SUBMITTED BY:NAME-CHARANPREET GROVER

CLASS-ECE-III ROLL NO.- 009576127744

You might also like