Sei sulla pagina 1di 46

ACKNOWLEDGE

The training at APPIN TECHNOLOGY LAB LAXMI NAGAR ,DELHI is one of the most productive & knowledge experience of my engineering career .It provides a golden opportunity for me to both upgrade my skills & practical aspects of various technologies .

It gives me immense pleasure to thank all those people who have contributed directly or indirectly during this training period .

I would like to express my gratitude to Mr. Tanmoy Dutta (Director),APPIN TECHNOLOGY LAB,LAXMI NAGAR,DELHI for giving the outline of the project and also to Mr. Ahinay Sharma (Training Incharge) for his all time co-operation in guiding this final shape. So, at last I wish to thanks my college principal & all staff members of APPIN TECHNOLOGY LAB,DELHI. Above all I wish to thank almighty who provided me this golden opportunity.

TABLE OF CONTENT

1) Company Profile 2) Introduction 3) Embedded system 4) Varieties of embedded systems 5) Microcontrollers vs. Microprocessors 6) Types of Microcontrollers 7) Block of Microcontrollers 8) 8051 Architecture 9) Project Description 10) Procedure 11) General Information 12) Circuit Diagram 13) Coding 14) Snapshots 15) Reference and Biblography

COMPANYS PROFILE
Appin Security Group is a global Information Security company focused on training, consulting and solutions. The company was formed as a merger of two entities, XIRS Ventures Inc based in Austin Texas incorporated in 2003 and XIRS Appin incubated inside IIT, Delhi India formed in 2004. Later the name XIRS was dropped from the company and the merged entity is known as Appin Technologies. From USA & India, the company has now expanded its operations to Europe, Africa and South East Asia as well. The company has gone through several mergers and acquisitions and has operated businesses under the trademarks 'Appin Knowledge Solutions', 'XIRS Appin Appin Technologies', 'Appin Overseas', 'Appin Software Security' all of whom form a part of the current Appin Security Group.

'PROFESSIONAL TURNS TO TRAINING'


APPIN TECHNOLOGY LAB is the pioneer co. in the Embedded Technology. His main emphasis is on practical project work. He increased the breadth & depth of our technical skill sets of domain.

VISION & MISSION


Our Vision is to fill the gap, which the present professional education system is lacking by providing each engineering student by providing practical expertise & train the manpower in the emerging field of Wireless, Telecom & Robotics.

The Mission of APPIN Institute is to produce a confident workforce & enable them to enter today's competitive business environment armed with zeal and enthusiasm required to become a successful, productive member of society.

INTRODUCTION
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 va r i o u s Embedded Products such as keyboard, printer, modem, Disc controller, Soundc a r d , 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 reasoning recent years many manufactures of general purpose microprocessors such as INTEL, Motorola, 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 SYSTEMS
An embedded system is a computer system designed to perform one or a f e w d e d i c a t e d functions, often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. In contrast, a general-purpose computer, such as a personal computer, is designed to be flexible and to meet a wide range of an end-user's needs. Embedded systems control many of the common devices in use today. Embedded systems are controlled by a main processing core that is t y p i c a l l y e i t h e r a microcontroller or a digital signal processor (DSP).Since the embedded system is dedicated to specific tasks, design engineers can optimize it reducing the size and cost of the product and increasing the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale. 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. 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. 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 general purpose computer, which can run any software application, the user chooses, the software on an embedded system is semipermanent, so it is often called firmware. In general, "embedded system" is not an exactly defined term, as many systems have some element of programmability. For example, handheld computers share

some elements with embedded systems such as the operating systems and microprocessors which power them, but are not truly embedded systems, because they allow different applications to be loaded and peripherals to be connected.

VARIETIES 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 routers and network bridges to route data. Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones, p r i n t e r s e t c . M a n y household appliances, such as microwave ovens, washing machines and dishwashers, are including embedded systems to provide flexibility, efficiency and features. Advanced HVACs stems 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 m o t o r c o n t r o l l e r s . 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.

MICROCONTROLLERS vs. MICROPROCESSORS


General-purpose microprocessors Contains No RAM No ROM No I/O ports Microcontroller contains CPU (microprocessor) RAM ROM I/O ports Timer ADC and other peripherals

General-purpose microprocessors
1) Must add RAM, ROM, I/O ports, and timers externally to make them functional

2) Make the system bulkier and much more Expensive 3) Have the advantage of versatility on the amount of RAM, ROM, and I/O ports.

Microcontroller 1) The fixed amount of on-chip ROM, RAM, and number of I/O ports makes them ideal and number of I/O ports makes them ideal for many applications in which cost and space 2) In many applications, the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power.

An embedded product uses a microprocessor (or microcontroller) to do one task and one task Only. There is only one application software that is typically burned into ROM. A PC, in contrast with the embedded system, can be used for any number of applications. It has RAM memory and an operating system that loads a variety of applications into RAM and lets the CPU run them.

TYPES OF MICROCONTROLLERS
The predominant family of microcontrollers is 8-bit types since this word size has proved p o p u l a r f o r t h e v a s t m a j o r i t y o f t a s k s t h e d e v i c e s h a v e b e e n r e q u i r e d t o p e r f o r m . T h e microcontroller family would have a common instruction subset but family members differ in the amount, and type, of memory, timer facility, port options, etc. possessed, thus producing cost-effective devices suitable for particular manufacturing requirements. There are 4 major 8 bit micro controllers. They are Free scales 6811, Intel's 8051, Zilog's Z8 and PIC 16x from Microchip Technology. Each of these Microcontrollers have a unique set of instruction set and register set; therefore they are not compatible with each other.

8051 MICROCONTROLLER

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 microcontrollers is referred to as the MCS-51 architecture, or Sometimes simply as MCS-51. The microcontrollers have an 8-bit data bus. They are capable of addressing 64K of program memory and a separate 64K of data memory. The 8051 has 4K of code memory implemented as on-chip Read Only Memory (ROM). The 8051 has 128 bytes of internal Random Access Memory (RAM). It has two timer/counters, a serial port, 4 general purpose parallel input/output ports, and interrupt control logic with five sources of interrupts. Besides internal RAM, the 8051 has various Special Function Registers (SFR), which are the control and data registers for on-chip facilities

COMPARISON OF 8051 FAMILY MEMBERS

Feature ROM (program space in bytes) RAM (bytes) Timers I/O pins Serial port Interrupt sources

8051 8052 8031 4K 8K 0K 128 256 128 2 3 2 32 32 32 1 1 1 6 8 6

BLOCK DIAGRAM OF MICROCONTROLLER

8051 ARCHITECTURE

Consist of specific features:

8-bit CPU with register A ( the accumulators) and B. 16 -bit Program counter (PC) and data pointer. 8 -bit program status word( PSW ) 8-bit stack pointer(SP) 16 bit timers (usually 2, but may have more, or less) Bit as well as byte addressable RAM area of 16 bytes Four 8-bit ports, (short models have two 8-bit ports). Low power idle and power down Modes Interrupt recovery from power down mode 256*8 bit internal RAM

What is 8051 Standard?


Microcontroller manufacturers have been competing for a long time for attracting choosy customers and every couple of days a new chip with a higher operating frequency, more memory and upgraded A/D converters appeared on the market. However, most of them had the same or at least very similar architecture known in the world of microcontrollers as 8051 compatible. What is all this about? The whole story has its beginnings in the far 80s when Intel launched the first series of microcontrollers called the MCS 051. Even though these microcontrollers had quite modest features in comparison to the new ones, they conquered the world very soon and became a standard for what nowadays is called the microcontroller. The main reason for their great success and popularity is a skillfully chosen configuration which satisfies different needs of a large number of users allowing at the same time constant expansions (refers to the new types of microcontrollers).

Besides, the software has been developed in great extend in the meantime, and it simply was not profitable to change anything in the microcontrollers basic core. This is the reason for having a great number of various microcontrollers which basically are solely upgraded versions of the 8051 family. What makes this microcontroller so special and universal so that almost all manufacturers all over the world manufacture it today under different name?

As seen in figure above, the 8051 microcontroller has nothing impressive in appearance:

4 Kb of ROM is not much at all. 128b of RAM (including SFRs) satisfies the user's basic needs. 4 ports having in total of 32 input/output lines are in most cases sufficient to make all necessary connections to peripheral environment.

The whole configuration is obviously thought of as to satisfy the needs of most programmers working on development of automation devices. One of its advantages 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. Another advantage are RAM organization, the operation of Central Processor Unit (CPU) and ports which completely use all recourses and enable further upgrade.

PIN CONFIGURATION

PIN DESCRIPTION
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most registers. In other words, the positive voltage on this pin resets the microcontroller. By applying logic zero to this pin, the program starts execution from the beginning. Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general 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 input. Pin 13: INT1 Interrupt 1 input. Pin 14: T0 Counter 0 clock input. Pin 15: T1 Counter 1 clock input. Pin 16: WR Write to external (additional) RAM. Pin 17: RD Read from external RAM. Pin 18, 19: X2 X1 Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be used for frequency stability. Later versions of 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 general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs.

Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every time the microcontroller reads a byte from memory. Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both 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. It means that even there is a program written to the microcontroller, it will not be executed. Instead, the program written to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal then external (if exists). Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0). Pin 40: VCC +5V power supply.

Input/output Ports (I/O Ports)


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

Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the case with any TTL input). This may seem confusing but don't loose your patience. It all becomes clear after studying simple electronic circuits connected to an I/O pin.

Memory Organization
The 8051 has two types of memory and these are Program Memory and Data Memory. Program Memory (ROM) is used to permanently save the program being executed, while Data Memory (RAM) is used for temporarily storing data and intermediate results created and used during the operation of the microcontroller. Depending on the model in use (we are still talking about the 8051 microcontroller family in general) at most a few Kb of ROM and 128 or 256 bytes of RAM is used. However All 8051 microcontrollers have a 16-bit addressing bus and are capable of addressing 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 smart memory organization which makes these microcontrollers a real programmers goody.

Program Memory
The first models of the 8051 microcontroller family did not have internal program memory. It was added as an external separate chip. These models are recognizable by their label beginning with 803 (for example 8031 or 8032). All later models have a few Kbyte ROM embedded. Even though such an amount of memory is sufficient for writing most of the programs, there are situations when it is necessary to use additional memory as well. Typical examples are so called lookup tables. They are used in cases when equations describing some processes are too complicated or when there is no time for solving them. In such cases all necessary estimates and approximates are executed in advance and the final results are put in the tables (similar to logarithmic tables).

How does the microcontroller handle external memory depends on the EA pin logic state:

EA=0 In this case, the microcontroller completely ignores internal program memory and executes only the program stored in external memory. EA=1 In this case, the microcontroller executes first the program from built-in ROM, then the program stored in external memory. In both cases, P0 and P2 are not available for use since being used for data and address transmission. Besides, the ALE and PSEN pins are also used.

Data Memory
As already mentioned, Data Memory is used for temporarily storing data and intermediate results created and used during the operation of the microcontroller. Besides, RAM memory built in the 8051 family includes many registers such as hardware counters and timers, input/output ports, serial data buffers etc. The previous models had 256 RAM locations, while for the later models this number was incremented by additional 128 registers. However, the first 256 memory locations (addresses 0-FFh) are the heart of memory common to all the models belonging to the 8051 family. Locations available to the user occupy memory space with addresses 0-7Fh, i.e. first 128 registers. This part of RAM is divided in several blocks. The first block consists of 4 banks each including 8 registers denoted by R0-R7. Prior to accessing any of these registers, it is necessary to select the bank containing it. The next memory block (address 20h-2Fh) is bit- addressable, which means that each bit has its own address (07Fh). Since there are 16 such registers, this block contains in total of 128 bits with separate addresses (address of bit 0 of the 20h byte is 0, while address of bit 7 of the 2Fh byte is 7Fh). The third group of registers occupy addresses 2Fh-7Fh, i.e. 80 locations, and does not have any special functions or features.

Additional RAM
In order to satisfy the programmers constant hunger for Data Memory, the manufacturers decided to embed an additional memory block of 128 locations into the latest versions of the 8051 microcontrollers. However, its not as simple as it seems to be The problem is that electronics performing addressing has 1 byte (8 bits) on disposal and is capable of reaching only the first 256 locations, therefore. In order to keep already existing 8-bit architecture and compatibility with other existing models a small trick was done. What does it mean? It means that additional memory block shares the same addresses with locations intended for the SFRs (80h- FFh). In order to differentiate between these two physically separated memory spaces, different ways of addressing are used. The SFRs memory locations are accessed by direct addressing, while additional RAM memory locations are accessed by indirect addressing.

Addressing
While operating, the processor processes data as per program instructions. Each instruction consists of two parts. One part describes WHAT should be done, while the other explains HOW to do it. The latter part can be a data (binary number) or the address at which the data is stored. Two ways of addressing are used for all 8051 microcontrollers depending on which part of memory should be accessed:

Direct Addressing
On direct addressing, the address of memory location containing data to be read is specified in instruction. The address may contain a number being changed during operation (variable). For example:

Since the address is only one byte in size (the largest number is 255), only the first 255 locations of RAM can be accessed this way. The first half of RAM is available for use, while another half is reserved for SFRs. MOV A, 33h; Means: move a number from address 33 hex. to accumulator

Indirect Addressing
On indirect addressing, a register containing the address of another register is specified in instruction. Data to be used in the program is stored in the letter register. For example: Indirect addressing is only used for accessing RAM locations available for use (never for accessing SFRs). This is the only way of accessing all the latest versions of the microcontrollers with additional memory block (128 locations of RAM). Simply put, when the program encounters instruction including @ sign and if the specified address is higher than 128 ( 7F hex.), the processor knows that indirect addressing is used and skips memory space reserved for SFRs. MOV A, @R0; Means: Store the value from the register whose address is in the R0 register into accumulator.

Special Function Registers (SFRs)


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

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.

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. 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 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. 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 primarly 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.

Counters and Timers


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. Timer T0 As seen in figure below, the timer T0 consists of two registers TH0 and TL0 representing a low and a high byte of one 16-digit binary number.

Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists of will contain 0. If the timer contains for example number 1000 (decimal), then the TH0 register (high byte) will contain the number 3, while the TL0 register (low byte) will contain decimal number 232.

Formula used to calculate values in these two registers is very simple: TH0 256 + TL0 = T Matching the previous example it would be as follows: 3 256 + 232 = 1000

Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case of exceeding this value, the timer will be automatically cleared and counting starts from 0. This condition is called an overflow. Two registers TMOD and TCON are closely connected to this timer and control its operation.

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): o 1 - Timer 1 operates only if the INT1 bit is set. o 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: o 1 - Timer counts pulses brought to the T1 pin (P3.5).

T1M1 0 0 1 1

T1M0 0 1 0 1

MODE 0 1 2 3

DESCRIPTION 13-bit timer 16-bit timer 8-bit auto-reload Split mode

0 - Timer counts pulses from internal oscillator.

T1M1,T1M0 These two bits select the operational mode of the Timer 1. GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2): o 1 - Timer 0 operates only if the INT0 bit is set. o 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: o 1 - Timer counts pulses brought to the T0 pin (P3.4). o 0 - Timer counts pulses from internal oscillator. T0M1,T0M0 These two bits select the oprtaional 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

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: o 0 - disables all interrupt requests. o 1 - enables all individual interrupt requests. ES - enables or disables serial interrupt: o 0 - UART system cannot generate an interrupt. o 1 - UART system enables an interrupt. ET1 - bit enables or disables Timer 1 interrupt: o 0 - Timer 1 cannot generate an interrupt. o 1 - Timer 1 enables an interrupt. EX1 - bit enables or disables external 1 interrupt: o 0 - change of the pin INT0 logic state cannot generate an interrupt. o 1 - enables an external interrupt on the pin INT0 state change. ET0 - bit enables or disables timer 0 interrupt: o 0 - Timer 0 cannot generate an interrupt. o 1 - enables timer 0 interrupt. EX0 - bit enables or disables external 0 interrupt: o 0 - change of the INT1 pin logic state cannot generate an interrupt. o 1 - enables an external interrupt on the pin INT1 state change.

Interrupt Priorities It is not possible to forseen 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 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: 1. External interrupt INT0 2. Timer 0 interrupt 3. External Interrupt INT1 4. Timer 1 interrupt 5. 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 o Priority 0 o Priority 1 PT1 - Timer 1 interrupt priority o Priority 0 o Priority 1 PX1 - External Interrupt INT1 priority o Priority 0 o Priority 1 PT0 - Timer 0 Interrupt Priority o Priority 0 o Priority 1 PX0 - External Interrupt INT0 Priority o Priority 0 o Priority 1

SERIAL PORT COMMUNICATION

One of the 8051s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051 has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial line would be a rather tedious process requiring turning on and off one of the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits. However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate. Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a value from the serial port. The 8051 will automatically let us know when it has finished sending the character we wrote and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about transmission at the bit level--which saves us quite a bit of coding and processing time The first thing we must do when using the 8051s integrated serial port is, obviously, configure it. This lets us tell the 8051 how many data bits we want, the baud rate we will be using, and how the baud rate will be determined. First, lets present the "Serial Control" (SCON) SFR and define what each b i t o f t h e S F R represents:

PROJECT DESCRIPTION

I have attempted to make a DTMF BASED ROBOT It is a basically a robot which will be run with the help of signals given through a cell phone. A cell phone will be attached to the robot (car) with its earphones plugged into the dtmf circuit. When a person will call on that cell phone, he can operate the car by pressing keys on his own cell phone. Each key will execute different commands such as forward, backward, right,left.

PROJECT METHODOLOGY COMPONENTs USED


1) Microcontroller section :-AT89s52 with base

Crystal oscillator (12 MHz) Capacitor 22pF (2) Resistor 470 ohm (5)
2) DTMF section :- 8870with base

Crystal oscillator (3.579 Hz) Resistor 100 k, 200 k, 300k Capacitor 0.1 uF(2) 3) H bridge IC (L293D) 4) V o l t a g e r e g u l a t o r s ( L M 7 8 0 5 ) 5) Car (driven by 2 DC motors) 6) V o l t a g e s u p p l y ( D C b a t t e r y o f 9 v ) SOFTWARE USED keil EQUIPMENT USED Soldering iron, flux, wire

Procedure of building the Wireless Robot


STEP 1: Circuit Diagram of the project is designed and finalized (given above)

STEP 2 : All the components and software platform (also mentioned above) are selected. STEP 3 : All the hardware components are soldered on the general circuit board. STEP 4: The program/code of the project is written in assembly language and compiled using IDE STEP 5: The hex code is burnt in microcontrollers.

GENERAL INFORMATION
DTMF DECODER
Dual-tone multi-frequency (DTMF) signaling is used for telecommunication signaling over analog telephone lines in the voice-frequency band between telephone handsets and other communications devices and the switching center. DTMF, also known as touch-tone, are the audible sounds you hear when you press keys on your phone. It was designed for optimal performance with each tone being very distinct. This makes decoding the tone very easy even in surrounding noise. It is this performance that makes DTMF ideal for clear transmission and reception in remote control (wireless or through phone lines) applications.

H-BRIDGE
i s a n electronic circuit which enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards. H-bridges are available as integrated, or can be built

from discrete components. The H-Bridge arrangement is generally used to reverse the polarity of the motor, but can also be used to 'brake' the motor, where the motor comes to a sudden stop, as the motor's terminals are shorted, or to let the motor 'free run' to a stop, as the motor is effectively disconnected from the circuit. The following table summarizes operation. The L293D is a quadruple half H-bridge bidirectional motor driver IC that can drive current of up to 600mA with voltage range of 4.5 to 36 volts. It is suitable to drive small DC-Geared motors, bipolar stepper motor etc.

CIRCUIT DIAGRAM

CODING

ORG 00H MOV P1,#0FFH MOV P2,#00 LOOP:MOV A,P1 ANL A,#0FH CJNE A,#02H,L1 MOV P2,#OAH LJMP LOOP LI:CJNE A,#04H,L2 MOV P2,#06H LJMP LOOP L2:CJNE A,#06H,L3 MOV P2,#09H LJMP LOOP L3:CJNE A,#08H,L4 MOV P2,#05H LJMP LOOP L4:CJNE A,#05H,LOOP MOV P2,#00 LJMP LOOP END

SNAPSHOTS

REFERENCES AND BIBLIOGRAPHY


1. THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEM by Muhammad Ali Mazidi, Janice Ali Mazidi, Rolin D. McKinley 2. THE 8051 MICROCONTROLLER by K.J AYALA 3. www.wikipedia.org

Potrebbero piacerti anche