You are on page 1of 63

CHAPTER 1 INTRODUCTION

In this project, a system is designed and created which uses Dual Tone Multi Frequency (DTMF) technology of our mobile phone. Every mobile phone will have this facility. Long distance computer communication has become a challenge of the present day technology. Recently these computer communication networks are also termed as information networks. Presently there are many information services for information exchange like Telex, Electronics mail, Video teleconferencing, Facsimile transmission (FAX), which are quit efficient but expensive too. But there could be a situation where the terminal down load or upload few lines or files or say information, may be OFF from the mains. Thus all the technologies are failed. And this is where the project Mobile Controlled Devices comes into picture. To establish an interactive link with such a terminal, the mains must be ON. To materialize such a system, it requires some circuitry which would receive commands on telephone line and can switch mains load ON or OFF. The two major parts of the system are the hardware configuration and device control logic. This project is to eliminate the problem by using such a circuitry, which can switch the remote terminal ON/OFF without anybody being present at the remote location. This aim is achieved by using Mobile Control Devices.

1.1 Overview of the project


Conventionally, wireless controlled devices use RF circuits, which have the drawbacks of limited working range, limited frequency range, limited features and limited control options. To overcome all these limitations, this device is designed to operate through a mobile phone, there by it can be controlled any where from the world. It provides the advantages of device control, un-limited working range depending up on the coverage area of tele-communications network, no interference with other signals, and more control options. Generally from any mobile or any land line phone 12 different DTMF codes can be produced by activating the different keys of mobile keypad, so 12 different control options can be adopted in the device.

Generally for this purpose cordless phones (mobile phone) are best suited, it is the primary function of the device to carry the mobile over its chassis, there by the device can receive the command signals through this mobile. According to the control signals received from another mobile at remote end, the switching of devices can be controlled by decoding the DTMF signals received by the cordless phone. The operator controls it using the handset of the cordless phone. The DTMF decoder circuit is designed with 8870 chips, this is a complete DTMF receiver integrating both the band split filter and digital decoder functions. The filter section uses switched capacitor techniques for high and low group filters; the decoder uses digital counting techniques to detect and decode all 16 DTMF tone-pairs into a 4-bit code. External component count is minimized by on chip provision of a differential input amplifier, clock oscillator and latched three-state bus interface. The main controlling technique using this integrated DTMF IC is that it is having all DTMF Receiver Features like it has low power consumption, adjustable guard time, inhibit mode. It is widely used in Telephone answering machine; the MT8870D is a complete DTMF receiver integrating both the band split filter and digital decoder functions. The filter section uses switched capacitor techniques for high and low group filters; the decoder uses digital counting techniques to detect and decode all 16 DTMF tone pairs into a 4-bit code. External component count is minimized by on chip provision of a differential input amplifier, clock oscillator and latched three-state bus interface. The prime use of microcontroller is to acquire data from DTMF decoder, and according to that it is the main function of the controller to control devices. Initially the process begins from mobile phone, depending up on the control signals in the form of DTMF code transmitted by the mobile or land line, the receiving mobile produces corresponding DTMF code. The output of the mobile is amplified to increase the signal strength and it is fed to DTMF signal decoder chip, which generates corresponding binary code at four outputs. This binary code differs depending up on the low frequencies produced by the exchange, whenever any key of calling mobile is operated, two low frequencies are produced and corresponding to this a particular binary code is produced by the DTMF chip. The output of the DTMF chip is fed to microcontroller. Here the microcontroller is playing major roll, hence it can be called as heart of the project work. There by the following is the brief introduction about the 89C52 microcontroller. 2

1.2 Requirements of Project


MICRO CONTROLLER (89S52) DTMF 8870 RELAY DRIVER RELAYS BULBS MOBILE

1.3 Criteria for Choosing 89S52 Microcontroller


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 real-time 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 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 8052 is the first microcontroller of the MCS-52 family introduced by Intel Corporation at the end of the 1970s. The 8052 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 8052 family of the microcontrollers is presented in this chapter. First, the original 8052 microcontroller is discussed, followed by the enhanced features of the 8032, and the 80C515. In this chapter, the overview of the project, requirements of the project and need of 89S52 microcontroller are explained. In the next chapter, block diagram and schematic diagrams of the project will be explained.

CHAPTER 2 BLOCK AND SCHEMATIC DIAGRAMS


In this chapter, block diagram and schematic diagram of the project will be explained.

2.1 Block diagram

Fig. 2.1 Block Diagram of MCD This system is divided into two sections: 1.Remote Section: It is nothing but remote telephone set which is present in remote place. It may be your workspace mobile phone in PCO. Signal are sent through this phone. 2.Local Control Section: This is a control system through which you can control your appliances. This contains one telephone line and a control unit. The appliances to be controlled must be connected to telephone line through control unit. Control unit is kept with a sufficient backup.

Remote section consists of a simple DTMF encoder integrated circuit and matrix keypad. By pressing any key in the keyboard corresponding DTMF signal is available at the output. The respective tone represents the number and the signal is sent to local control system through telephone line via exchange. The local control unit contains one telephone line. The appliances to be controlled must be connected to a telephone line through control unit. Local control section consists of a DTMF decoder, 4-16 decoder or de-multiplexer, D-flip flops and relay driver circuits by which we control (ON/OFF) devices. In this project work, devices (mobile controlled devices) are controlled by a mobile phone that makes a call to the other mobile phone attached to the device. In the course of a call, if any button of calling mobile keypad is pressed, a tone corresponding to the button pressed is heard at the other end of the call (through the called mobile), where the mobile is installed over the device. This tone is called duel tone multiple frequency (DTMF), the robot recognizes this signal after converting it in to suitable digital signal through 8870 chip. The received tone signal is converted in to its equivalent binary digit and this binary number through four outputs of DTMF decoder is fed to microcontroller. The microcontroller is pre-programmed, which takes suitable decisions according to the binary code accepted as an input signal. Depending up on this code, the controller drives the motors in forward and backward directions. The controller is programmed to switch the devices. For example; if we want to turn ON the device, specific code has to be generated, based on this signal the controller ON the device automatically. Like wise to ON and OFF the devices, four different codes must be produced for microcontroller. So this simple project does not require the construction of receiver and transmitter units. The mobile that makes a call to the data receiving mobile by dialing the service number makes a communication link between these two mobiles. After establishing a call and by activating the calling mobile key pad DTMF signals are produced and transmitted to the called mobile through call switching centre. The version of DTMF used for telephone tone dialing is known as touch-tone. DTMF assigns a specific frequency to each key, so that it can easily be identified by the microcontroller unit. Each key

generates two separate tone frequencies, for example when number one key is pressed two different low frequencies of 697 Hz and 1209 Hz are generated. In general a mobile communication device receives an incoming call signal, and activates a call alert function to alert a user of the mobile communication device of the incoming call. The mobile communication device also presents the user with the alternative options of auto-answering the incoming call, or answering the call normally. If the auto-answer option is chosen, the mobile communication device answers the call and transmits a pre-recorded greeting message to the calling party, then puts the call on hold until the user is ready to speak with the calling party. This avoids the disruption of having to answer the call immediately. But here the application is quite different; the called mobile need not replay, the aim is putting the receiving mobile in to auto answering mode is to establish a communication link between the two mobiles automatically. Typically, whenever any mobile receives any call from any phone, answering key has to be activated manually, here human involvement is avoided, there by the receiving mobile is always put in to auto answering mode to accept the command signals from caller phone. The main purpose of this project work is to control the device through our mobile phone. In this regard, through another mobile installed in the device, as per the instructions passed through any mobile or land line. The control circuit is designed with DTMF signal Decoder and Micro controller chip, these two devices are playing major roll in this project work. The process begins from mobile phone, which is installed in the device, whenever it receives any call from any phone, generally somebody has to activate the answer key to establish a link between two phones, and then the conversation starts between two persons. This is general phenomenon, here the application is quite different, it is the function of mobile phone to control the device according to the command signals received from another phone, and therefore a call is to be established automatically. To achieve this, the receiving side mobile is supposed to be put in auto answering mode. After establishing link between the two phones, the DTMF decoder will come into the picture for decoding the DTMF signal, generated by activating the keypad of data transmitting telephone. Here the DTMF signal differs from one numerical key to the other 7

numerical key, whenever any key is depressed; two different low frequencies are generated by the exchange and transmitted through telecommunications network. The output of this DTMF decoder is fed to micro controller and based on this signal, the 8870 chip used as DTMF signal decoder generates. The microcontroller controls devices through Relays. For example: to give a command, initially a call has to be established, after that if we want to switch the device ON and OFF, number one of data transmitting telephone key pad must be activated, by which two different frequencies of 697Hz and 1207 Hz will be generated, on receipt of this signal in data receiving module, the DTMF decoder chip generates a binary code of 0001, based on this data the microcontroller drives the motors in one direction. The DTMF signal decoding circuit is designed using 8870 IC. The purpose of this unit is to decode the DTMF signals that are available at the input stage of the receiver side circuit. The out put of the data receiving mobile phone is amplified and fed to pin number 2 of this decoder chip, this chip is designed to generate binary code through its four out puts. With the help of some passive elements, 8870 IC produces BCD codes for the corresponding DTMF signals. The output BCD code from this circuit is fed to microcontroller. As described in previous chapters, after establishing communication link between two mobiles, and by activating different keys of caller mobile key pad, different low frequencies are produced and transmitted. For example; if number one key is activated, two different low frequencies of 697 Hz and 1209 Hz are produced, similarly when number two key is depressed, 697 Hz and 1336 Hz are produced, when 8870 IC receives this code, it generates 0010 code at its out puts. Like wise depending up on the different frequencies produced by activating the mobile key pad, different binary codes are produced, and based in this binary code the microcontroller controls the vehicle. The next important device used in this project work is microcontroller, it is playing major roll, there by the following description mainly focuses about Micro controller and its architecture, because it is treated as heart of the project work. Today, there is no such instrument that can function without Micro controller. Micro controllers have become an integral part of all instruments.

The Micro controller used in this project work is 89S52, basically this IC belongs to 8052 family. In1981, Intel Corporation introduced an 8- bit Micro controller, which is named as 8052. This controller is having 128 bytes of RAM, 4K bytes of ROM, two timers, one serial port, and four ports. Micro-controller works according to the program written in it. Most microcontrollers today are based on the Harvard architecture, which clearly defined the four basic components required for an embedded system. These include a CPU core, memory for the program (ROM or Flash memory), memory for data (RAM), one or more timers (customizable ones and watchdog timers), as well as I/O lines to communicate with external peripherals and complementary resources all this in a single integrated circuit. A microcontroller differs from a general-purpose CPU chip in that the former generally is quite easy to make into a working computer, with a minimum of external support chips. The idea is that the microcontroller will be placed in the device to control, hooked up to power and any information it needs, and that's that. A traditional microprocessor won't allow you to do this. It requires all of these tasks to be handled by other chips. For example, some number of RAM memory chips must be added. The amount of memory provided is more flexible in the traditional approach, but at least a few external memory chips must be provided, and additionally requires that many connections must be made to pass the data back and forth to them. For instance, a typical microcontroller will have a built in clock generator and a small amount of RAM and ROM (or EPROM or EEPROM), meaning that to make it work, all that is needed is some control software and a timing crystal (though some even have internal RC clocks). Microcontrollers will also usually have a variety of input/output devices, such as analog-to-digital converters, timers, UARTs or specialized serial communications interfaces like IC, Serial Peripheral Interface and Controller Area Network. Often these integrated devices can be controlled by specialized processor instructions. Originally, microcontrollers were only programmed in assembly language, or later in C code. Recent microcontrollers integrated with on-chip debug circuit accessed by In-circuit emulator via JTAG (Joint Text Action Group) enables a programmer to debug the software of an embedded system with a debugger. 9

More recently, however, some microcontrollers have begun to include a built-in high-level programming language interpreter for greater ease of use. BASIC is a common choice, and is used in the popular BASIC Stamp MCUs (Master Control Unit). Microcontrollers trade away speed and flexibility to gain ease of equipment design and low cost. There's only so much room on the chip to include functionality, so for every I/O device or memory increase the microcontroller includes, some other circuitry has to be removed. Finally, it must be mentioned on the chip to include functionality, so for every I/O device or memory increase microcontroller includes, some other circuitry has to be removed. Finally, it must be mentioned that some microcontroller architectures are available from many different vendors in so many varieties that they could rightly belong to a category of their own. Chief among these are the 8052 family.

2.2 Schematic diagram

Fig. 2.2 Circuit Diagram of MCD MT 8870 DTMF decoder IC MT8870/KT3170 serves as DTMF decoder. This IC takes DTMF signal coming via telephone line and converts that signal into respective BCD number. It uses same oscillator frequency used in the remote section so same crystal oscillator with frequency of 3.85M Hz is used in this IC.

10

Working of IC MT8870 The MT-8870 is a full DTMF Receiver that integrates both band split filter and decoder functions into a single 18-pin DIP. Its filter section uses switched capacitor technology for both the high and low group filters and for dial tone rejection. Its decoder uses digital counting techniques to detect and decode all 16 DTMF tone pairs into a 4-bit code. External component count is minimized by provision of an on-chip differential input amplifier, clock generator, and 10 latched tri-state interface bus. Minimal external components required include a low 3.579545MHz crystal, a timing resistor, and a timing capacitor. The MT-8870-02 can also inhibit the decoding of fourth column digits. MT-8870 operating functions include a band split filter that separates the high and low tones of the received pair, and a digital decoder that verifies both the frequency and duration of the received tones before passing the resulting 4-bit code to the output bus. The low and high group tones are separated by applying the dual-tone signal to the inputs of two 6th order switched capacitor band pass filters with bandwidths that correspond to the bands enclosing the low and high group tones. The filter also incorporates notches at 350 and 440 Hz, providing excellent dial tone rejection. Each filter output is followed by a single-order switched capacitor section that smoothes the signals prior to limiting. Signal limiting is low-level signals and noise. The MT-8870 decoder uses a digital counting technique to determine the frequencies of the limited tones and to verify that they correspond to standard DTMF frequencies. When the detector recognizes the simultaneous presence of two valid tones (known as signal condition), it raises the Early Steering flag (ESt). Any subsequent loss of signal condition will cause ESt to fall. Before a decoded tone pair is registered, the receiver checks for valid signal duration (referred to as character- recognition-condition). This check is performed by an external RC time constant driven by ESt. A short delay to allow the output latch to settle, registered. The contents of the output latch are made available on the 4-bit output bus by raising the three state control input (OE) to logic high. Inhibit mode is enabled by a logic high input to pin 5 (INH). It inhibits the detection of 1633 Hz.

11

The output code will remain the same as the previous detected code. On the M8870 models, this pin is tied to ground (logic low). The input arrangement of the MT8870 provides a differential input operational amplifier as well as a bias source (VREF) to bias the inputs at mid-rail. Provision is made for connection of a feedback resistor to the op-amp output (GS) for gain adjustment. The internal clock circuit is completed with the addition of a standard 3.579545 MHz crystal. The input arrangement of the MT-8870 provides a differential input operational amplifier as well as a bias source (VREF) to bias the inputs at mid-rail. Provision is made for connection of a feedback resistor to the opamp output (GS) for gain adjustment. The internal clock circuit is completed with the addition of a standard 3.579545 MHz crystal. The DTMF decoder circuit is designed with MT8870 series IC. All types of the MT8870 series use digital counting techniques to detect and decode all the 16 DTMF tone pairs into a 4-bit code output. The built-in dial tone rejection circuit eliminates the need for pre-filtering. When the input signal given at pin 2 (IN-) in single ended input configuration is recognized to be effective, the correct 4-bit decode signal of the DTMF tone is transferred to Q1 (Pin 11) through Q4 (Pin14) outputs. In this chapter, block diagram and circuit diagram of the project is explained. In next chapter, the components and features of 89S52 will be explained.

12

CHAPTER3 AT89S52 MICROCONTROLLER


In this chapter, components, pin diagram and features of 89S52 microcontroller will be explained.

3.1 Introduction to Microcontroller


The roll of microcontroller is very important in this project work, 89C52 is used here, this is quit popular IC generally used for many robotic applications. As described in block diagram chapter, with all latest features, this chip can be called as a mini computer. The prime use of a microcontroller is to control the operation of a machine using a fixed program that is stored in ROM and that does not changeover the lifetime of the system. The microcontroller design uses a much more limited set of instructions that are used to move code and data from internal memory to the ALU. Many instructions are coupled with pins on the IC package. The pins are programmable independently, that is capable of having several different functions depending on the program. The microcontroller is concerned with getting data from and to its own pins; architecture and instruction set are optimized to handle data in bit, byte and word size. Every application demands a microcontroller, today there is no such electronic instrument or robot that functions with out microcontroller. Generally for any application, often designers chose the 8 bit controller, because they are most popular microcontrollers in use today, another important aspect is cost effective.

3.2 Features of Microcontroller 89S52


The following are the features of 8052 microcontroller Eight bit CPU with registers 16 bit program counter and data pointer

13

8 bit program status word 8 bit stack pointer Internal ROM or EPROM (4k) Four register banks, each containing eight registers 16 bytes, which may be addressed at the bit level 80 bytes of general purpose data memory 32 input / output pins arranged as four 8 bit ports Two sixteen bit timer / counter Full duplex serial data receiver / transmitter Two external and three internal interrupt sources Oscillator and clock circuits Control registers

3.3 Description of Microcontroller 89S52


The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry- standard 80C51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, onchip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.

14

3.4 Pin Description of Microcontroller 89S52

Fig. 3.1 Pin Diagram of AT89S52 VCC Supply voltage. GND Ground. Port 0 Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance inputs. Port 0 can also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pullups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pullups are required during programm verification.

15

Port 1 Port 1 is an 8-bit bidirectional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups. In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, asshown in the following table. Port 1 also receives the low-order address bytes during Flash programming and verification. Table 3.1: Port 1 Pin Details

Port 2 Port 2 is an 8-bit bidirectional I/O port with internal pullups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.

16

Port 3 Port 3 is an 8-bit bidirectional I/O port with internal pullups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pullups. Port 3 also serves the functions of various special features of the AT89S52, as shown in the following table. Port 3 also receives some control signals for Flash programming and verification. Table 3.2: Port 2 Pin Details

RST Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives High for 96 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled. ALE/PROG Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking 17

purposes. Note, however, that one ALE pulse is skipped during each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode. PSEN Program Store Enable (PSEN) is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. EA/VPP External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH.Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset.EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming. XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting oscillator amplifier.

18

3.5 Registers and Memory


Special Function Registers A map of the on-chip memory area called the Special Function Register (SFR) space .Note that not all of the addresses are occupied, and unoccupied addresses may not be implemented on the chip. Read accesses to these addresses will in general return random data, and write accesses will have an indeterminate effect. User software should not write 1s to these unlisted locations, since they may be used in future products to invoke new features. In that case, the reset or inactive values of the new bits will always be 0. Timer 2 Registers Control and status bits are contained in registers T2CON and T2MOD for Timer 2. The register pair (RCAP2H, RCAP2L) are the Capture/Reload registers for Timer 2 in 16-bit capture mode or 16-bit auto-reload mode. Interrupt Registers The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the six interrupt sources in the IP register. Dual Data Pointer Registers To facilitate accessing both internal and external data memory, two banks of 16bit Data Pointer Registers are provided: DP0 at SFR address locations 82H-83H and DP1 at 84H-85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1.The user should always initialize the DPS bit to the appropriate value before accessing the respective Data Pointer Register. Power off Flag The Power Off Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR. POF is set to 1 during power up. It can be set and rest under software control and is not affected by reset.

19

Memory Organization MCS-51 devices have a separate address space for Program and Data Memory. Up to 64K bytes each of external Program and Data Memory can be addressed. Program Memory If the EA pin is connected to GND, all program fetches are directed to external memory. On the AT89S52, if EA is connected to VCC, program fetches to addresses 0000H through 1FFFH are directed to internal memory and fetches to addresses 2000H through FFFFH are to external memory. Data Memory The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the Special Function Registers. This means that the upper 128 bytes have the same addresses as the SFR space but are physically separate from SFR space. When an instruction accesses an internal location above address 7FH, the address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR space. Instructions which use direct addressing access of the SFR space. For example, the following direct addressing instruction accesses the SFR at location 0A0H (which is P2). MOV 0A0H, #data Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose address is 0A0H). MOV @R0, #data Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available as stack space.

3.6 Watch Dog Timer


The WDT is intended as a recovery method in situations where the CPU may be subjected to software upsets. The WDT consists of a 13-bit counter and the Watchdog Timer Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the WDT is enabled, it will increment every machine cycle while the oscillator is running. The WDT timeout period is dependent on the external clock frequency. There is no way to disable the WDT except through reset (either hardware reset or WDT overflow reset). 20

Using the WDT To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H).When the WDT is enabled, the user needs to service it by writing 01EH and 0E1H to WDTRST to avoid a WDT overflow. The 13-bit counter overflows when it reaches 8191 (1FFFH), and this will reset the device. When the WDT is enabled, it will increment every machine cycle while the oscillator is running. This means the user must reset the WDT at least every 8191 machine cycles. To reset the WDT the user must write 01EH and 0E1H to WDTRST. WDTRST is a write only register. The WDT counter cannot be read or written. When WDT overflows, it will generate an output RESET pulse at the RST pin. The RESET pulse duration is 96xTOSC, where TOSC=1/FOSC. To make the best use of the WDT, it should be serviced in those sections of code that will periodically be executed within the time required to prevent a WDT reset. WDT During Power-down and Idle In Power-down mode the oscillator stops, which means the WDT also stops. While in Power-down mode, the user does not need to service the WDT. There are two methods of exiting Power-down mode: by a hardware reset or via level-activated external interrupt which is enabled prior to entering Power-down mode. When Power down is exited with hardware reset, servicing the WDT should occur as it normally does whenever the AT89S52 is reset. Exiting Power-down with an interrupt is significantly different. The interrupt is held low long enough for the oscillator to stabilize. When the interrupt is brought high, the interrupt is serviced. To prevent the WDT from resetting the device while the interrupt pin is held low, the WDT is not started until the interrupt is pulled high. It is suggested that the WDT be reset during the interrupt service for the interrupt used to exit Power-down mode. To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best to reset the WDT just before entering Power-down mode. Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whether the WDT continues to count if enabled. The WDT keeps counting during IDLE (WDIDLE bit = 0) as the default state. To prevent the WDT from resetting periodically exit IDLE, service the WDT, and reenter IDLE mode. With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and resumes the count upon exit from IDLE. 21

UART The UART in the AT89S52 operates the same way as the UART in the AT89C51 and AT89C52. For further information on the UART operation, refer to the ATMEL Web site from the home page, select Products, then 8051-Architecture Flash Microcontroller, then Product Overview.

3.7 Timers and Counters


Timer 0 and 1 Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in the T89C51 and AT89C52.. From the home page, select Products, then 8051Architecture Flash Microcontroller, then Product Overview. Timer 2 Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The type of operation is selected by bit C/T2 in the SFR T2CON. Timer 2 has three operating modes: capture, auto-reload (up or down counting), and baud rate generator. The modes are selected by bits in T2CON,. Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is incremented every machine cycle. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency. Counters In the Counter function, the register is incremented in response to a 1-to-0 transition at its corresponding external input pin, T2. In this function, the external input is sampled during S5P2 of every machine cycle. When the samples show a high in one cycle and a low in the next cycle, the count is incremented. The new count value appears detected. Since two machine cycles (24 oscillator periods) are required to recognize a 1to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. To ensure that a given level is sampled at least once before it changes, the level should be held for at least one full machine cycle.

22

Auto-reload (Up or Down Counter) Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This feature is invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD (see Table 4). Upon reset, the DCEN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin.

3.8 Interrupts
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt.

Table 3.3: Interrupts

23

Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA User software should not write 1s to these bit positions, since they may be used in future AT89 products. Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON. Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be cleared in software. The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is polled in the same cycle in which the timer overflows.

In this chapter, the components, pin diagram and features of 89S52 is explained. In next chapter, DTMF decoder and cellular phones will be explained.

24

CHAPTER 4 DESCRIPTION OF CELLULAR PHONES


In this chapter, cellular system and DTMF decoder will be explained. The mobile phone (also called a wireless phone or cellular phone) is a shortrange, portable electronic device used for mobile voice or data communication over a network of specialized base stations known as cell sites. In addition to the standard voice function of a telephone, current mobile phones may support many additional services, and accessories, such as SMS for text messaging, email, packet switching for access to the Internet, gaming, Bluetooth, infrared, camera with video recorder and MMS for sending and receiving photos and video. Most current mobile phones connect to a cellular network of base stations (cell sites), which is in turn interconnected to the public switched telephone network (PSTN). The first commercial mobile phone service was launched in Japan in 1978. By November 2007, the total number of mobile phone subscriptions in the world had reached 3.3 billion or half of the human population, which also makes the mobile phone the most widely spread technology and the most common electronic device in the world. The first mobile phone to enable internet connectivity and wireless email, the Nokia Communicator, was released in 1996, creating a new category of expensive phones called smart phones. In 1999 the first mobile internet service was launched in Japan under the i-Mode service. By 2007 over 798 million people around the world accessed the internet or equivalent mobile internet services such as WAP and i-Mode at least occasionally using a mobile phone rather than a personal computer.

4.1 Cellular System


Mobile phones send and receive radio signals with any number of cell site base stations fitted with microwave antennas. These sites are usually mounted on a tower, pole or building, located throughout populated areas, then connected to a cabled communication network and switching system. The phones have a low-power transceiver that transmits voice and data to the nearest cell sites, normally not more than 8 to 13 km away. 25

When the mobile phone or data device is turned on, it registers with the mobile telephone exchange, or switch, with its unique identifiers, and can then be alerted by the mobile switch when there is an incoming telephone call. The handset constantly listens for the strongest signal being received from the surrounding base stations, and is able to switch seamlessly between sites. As the user moves around the network, the "handoffs" are performed to allow the device to switch sites without interrupting the call. Cell sites have relatively low-power (often only one or two watts) radio transmitters which broadcast their presence and relay communications between the mobile handsets and the switch. The switch in turn connects the call to another subscriber of the same wireless service provider or to the public telephone network, which includes the networks of other wireless carriers. Many of these sites are camouflaged to blend with existing environments, particularly in scenic areas. The dialogue between the handset and the cell site is a stream of digital data that includes digitized audio (except for the first generation analog networks). The technology that achieves this depends on the system which the mobile phone operator has adopted. The technologies are grouped by generation. The first-generation systems started in 1979 with Japan, are all analog and include AMPS and NMT. Second-generation systems, started in 1991 in Finland, are all digital and include GSM, CDMA and TDMA. The nature of cellular technology renders many phones vulnerable to 'cloning': anytime a cell phone moves out of coverage (for example, in a road tunnel), when the signal is re-established, the phone sends out a 're-connect' signal to the nearest cell-tower, identifying itself and signaling that it is again ready to transmit. With the proper equipment, it's possible to intercept the re-connect signal and encode the data it contains into a 'blank' phone -- in all respects, the 'blank' is then an exact duplicate of the real phone and any calls made on the 'clone' will be charged to the original account. Third-generation (3G) networks, which are still being deployed, began in Japan in 2001. They are all digital, and offer high-speed data access in addition to voice services and include W-CDMA (known also as UMTS), and CDMA2000 EV-DO. China will launch a third generation technology on the TD-SCDMA standard. Operators use a mix of pre designated frequency bands determined by the network requirements and local regulations. 26

In an effort to limit the potential harm from having a transmitter close to the user's body, the first fixed/mobile cellular phones that had a separate transmitter, vehiclemounted antenna, and handset (known as car phones and bag phones) were limited to a maximum 3 watts Effective Radiated Power. Modern handheld cell phones which must have the transmission antenna held inches from the user's skull are limited to a maximum transmission power of 0.6 watts ERP. Regardless of the potential biological effects, the reduced transmission range of modern handheld phones limits their usefulness in rural locations as compared to car/bag phones, and handhelds require that cell towers be spaced much closer together to compensate for their lack of transmission power. Some handhelds include an optional auxiliary antenna port on the back of the phone, which allows it to be connected to a large external antenna and a 3 watt cellular booster. Alternately in fringe-reception areas, a cellular repeater may be used, which uses a long distance high-gain dish antenna or yogi antenna to communicate with a cell tower far outside of normal range, and a repeater to rebroadcast on a small short-range local antenna that allows any cell phone within a few meters to function properly.

4.2 Handsets
Nokia is currently the world's largest manufacturer of mobile phones, with a global device market share of approximately 40% in 2008. Other major mobile phone manufacturers (in order of market share) include Samsung (14%), Motorola (14%), Sony Ericsson (9%) and LG (7%). These manufacturers account for over 80% of all mobile phones sold and produce phones for sale in most countries. The first smart phone was the Nokia 9000 Communicator in 1996 which incorporated PDA functionality to the basic mobile phone at the time. As miniaturization and increased processing power of microchips has enabled ever more features to be added to phones, the concept of the smart phone has evolved, and what was a high-end smart phone five years ago, is a standard phone today. Several phone series have been introduced to address a given market segment, such as the RIM Blackberry focusing on enterprise/corporate customer email needs; the Sony Ericsson Walkman series of music phones and Cyber shot series of camera phones; the Nokia N-Series of multimedia phones; and the Apple I Phone which provides full-featured web access and multimedia capabilities.

27

4.3 Mobile Phone Features


Mobile phones often have features beyond sending text messages and making voice calls, including Internet browsing, music (MP3) playback, memo recording, personal organizer functions, e-mail, instant messaging, built-in cameras and camcorders, ring tones, games, radio, Push-to-Talk (PTT), infrared and Bluetooth connectivity, call registers, ability to watch streaming video or download video for later viewing, video calling and serve as a wireless modem for a PC, and soon will also serve as a console of sorts to online games and other high quality games. The total value of mobile data services exceeds the value of paid services on the Internet. The largest categories of mobile services are music, picture downloads, video gaming, adult entertainment, gambling, video/TV.

4.4 Applications
The most commonly used data application on mobile phones is SMS text messaging, with 74% of all mobile phone users as active users (over 2.4 billion out of 3.3 billion total subscribers at the end of 2007). SMS text messaging was worth over 100 billion dollars in annual revenues in 2007 and the worldwide average of messaging use is 2.6 SMS sent per day per person across the whole mobile phone subscriber base. The first SMS text message was sent from a computer to a mobile phone in 1992 in the UK, while the first person-to-person SMS from phone to phone was sent in Finland in 1993.

4.5 DTMF Introduction


When we press a button in the telephone set keypad, a connection is made that generates a resultant signal of two tones at the same time. These two tones are taken from a row frequency and a column frequency. The resultant frequency signal is called "Dual Tone Multiple Frequency". These tones are identical and unique. A DTMF signal is the algebraic sum of two different audio frequencies, and can be expressed as follows: f(t) = A0sin(2**fa*t) + B0sin(2**fb*t) + ........... ------->(1)

28

Where fa and fb are two different audio frequencies with A and B as their peak amplitudes and f as the resultant DTMF signal. fa belongs to the low frequency group and fb belongs to the high frequency group. Each of the low and high frequency groups comprise four frequencies from the various keys present on the telephone keypad; two different frequencies, one from the high frequency group and another from the low frequency group are used to produce a DTMF signal to represent the pressed key. The amplitudes of the two sine waves should be such that (0.7 < (A/B) < 0.9)V -------->(2)

The frequencies are chosen such that they are not the harmonics of each other. The frequencies associated with various keys on the keypad are shown in above table. The servers in the telephone exchange identifies these signals and makes the connection to the person you are calling. When we press the digit 5 in the keypad it generates a resultant tone signal which is made up of frequencies 770Hz and 1336Hz. Pressing digit 8 will produce the tone taken from tones 852Hz and 1336Hz. In both the cases, the column frequency 1336 Hz is the same. These signals are digital signals which are symmetrical with the sinusoidal wave. A Typical frequency is shown in the figure below:

Fig. 4.1 Tone Frequency Volts Vs Sample

29

Along with these DTMF generator in our telephone set provides a set of special purpose groups of tones, which is normally not used in our keypad. These tones are identified as 'A', 'B', 'C', 'D'. These frequencies have the same column frequency but uses row frequencies given in these DTMF signals are used in controlling systems using telephones. By using some DTMF generating ICs we can generate DTMF tones without depending on the telephone set. The MT8870D is a complete DTMF receiver consisting of digital decoder. The decoder uses digital counting techniques to detect and decode all 16 DTMF tone pairs in to four bit code. The output 4 bit code is given as input to the microcontroller. DTMF decoder is a very easy to use program to decode DTMF dial tones found on telephone lines with touch tone phones. DTMF decoder is also used for receiving data transmissions over the air in amateur radio frequency bands.

4.6 Features of DTMF MT8870D


Complete DTMF Receiver Low power consumption Internal gain setting amplifier Power-down mode Inhibit mode

4.7 Main Applications


Receiver system Paging systems Repeater systems/mobile radio Credit card systems Remote control Telephone answering machine

4.8 DTMF Decoding Circuit


The decoding circuit is designed using 8870 DTMF receiver IC. The purpose of this device is to decode the DTMF signals that are available at the input stage (from the telephone line) of the receiver side circuit. With the help of some passive elements, 8870 IC produces BCD codes for the corresponding DTMF signals. The output BCD code from this circuit is fed to microcontroller. 30

Fig. 4.2 DTMF Decoding Circuit Gain Select Gives the access to output of front-end differential amplifier for connection of feedback resistor. Three state output Enable A Logic High enables the outputs Q1 to Q4 Internal pull up. The following is the functional table of the 8870 DTMF decoder IC: Table 4.1: Functional Table of DTMF F (Low) F(high) 697 1209 697 1336 697 1447 770 1209 770 1336 770 1447 852 1209 852 1336 852 1447 941 1209 941 1336 941 1447 Delayed Steering output KEY 1 2 3 4 5 6 7 8 9 0 * # TOE 1 1 1 1 1 1 1 1 1 1 1 1 Q4 0 0 0 0 0 0 0 1 1 1 1 1 Q3 0 0 0 1 1 1 1 0 0 0 0 1 Q2 0 1 1 0 0 1 1 0 0 1 1 0 Q1 1 0 1 0 1 0 1 0 1 0 1 0

It presents logic high when a received tone pair has been registered and the output latch is updated. It returns logic low when the voltage on St / Gt falls. Early Steering output 31

It presents logic high immediately when the digital algorithm detects a recognizable tone pair. Any momentary loss of signal condition will cause Est to return to logic low. Steering input / Guard time output A voltage greater than VTst detected at St causes the device to register the detected tone pair. The Gt output acts to reset the external steering time constant and its state is a function of Est and the voltage on St. The same above table can be shown in different pattern with 16 tone combinations shown below Table 4.2: 16 Tone Combination Symbol 697 770 852 941 Tone B [Hz] 1209 1336 1477 1633 I 4 7 * 2 5 8 0 3 6 9 # A B C D

Tone A [Hz]

The signal encoded as a pair of sinusoidal tones from the table above which are mixed with each other. DTMF is used by most public switched telephone networks (PSTN) systems for number dialing, and is also used for voice-response systems such as telephone banking and sometimes over private radio networks to provide signaling and transferring of small amounts of data.

Live tone signals are fed from telephone line radio in to sound card of computer. Either line or microphone in put jack is used. It is highly recommended to ensure galvanic decoupling between PC and telephone line or radio receiver. DTMF decoder output is clear text consisting of the symbols shown in table above. An exact log is displayed when

32

which number was dialed this log is automatically stored in to a log file for later exploration.

In this chapter, DTMF decoder and cellular phones is explained. In the next chapter, relay driver 2003, relays and power source will be explained.

33

CHAPTER 5 OTHER IMPORTANT COMPONENTS


In this chapter, relay driver 2003, relays and power source will be explained.

5.1 Description of ULN 2003


The ULN2003 is a monolithic high voltage and high current Darling ton transistor arrays. It consists of seven NPN darling ton pairs that features high-voltage outputs with common-cathode clamp diode for switching inductive loads. The collector-current rating of a single darling ton pair is 500mA. The darling ton pairs may be paralleled for higher current capability. Applications include relay drivers, hammer drivers, lamp drivers, display drivers(LED gas discharge), line drivers and logic buffers. The ULN2003 has a 2.7kW series base resistor for each darlington pair for operation directly with TTL or 5V CMOS devices.

5.2Logic and schematic Diagrams


Fig. 5.1 Logical and Schematic Diagrams of ULN 2003

5.3 Features
500mA rated collector current (Single output) High-voltage outputs: 50V 34

Inputs compatibale with various types of logic Relay driver application

5.4 Relays
In our project we can use relay as electronic switch to turn ON & OFF load.

Fig. 5.2 Block Diagram of Relay Just like the normal electrical fitting neutral is connected directly bulb and phase connected through switch as shown in fig. when switch is press ph is provided to bulb glow. Some process we provide N directly to device and Ph connected to common point connect switch NC (normal close) point so Ph is not provided to bulb and circuit is incomplete so bulb is off but when we set bit of micro controller transistor T1 conduct and current flowing through coil of Relay and coil get energise so it produce magnetic field across it and pick common point toward NO (normally open) position so Ph is connected to bulb an its turn ON. Like this we can turn ON and OFF coil devices through relay. A relay makes use of the electrical field generated around a conductor carrying an electric current. In a relay thin wire is wound around a soft iron core to become a powerful electro-magnet. As current flows through the coil a metal arm is attracted by the magnetic causes the switches to either open or close. On some relays, as one switch 35

opens another closes. This type of relay is called a double throw type. A relay may have two arms that move at the same time. This type of relay is called a double pole type.

5.5 Power Source

Fig. 5.3 12V Power Supply Circuit To generate required power source to drive the vehicle 12V, 1.2 AH, rechargeable, lead acid heavy duty battery is used. Here we required two different DC levels of +5V & +12V, the battery as it is delivering 12V is used to drive the DC motors & H Bridge, where as for the remaining electronic circuitry consists of microcontroller & DTMF decoder chip requires +5V constant source. To generate a stable supply of +5V, 7805 three terminal voltage regulator chip is used which provides constant supply, though the battery terminal voltage falls down to 8V. The DC motors are designed to operate at 12V DC & each motor consumes a maximum current of 150 milli-amps, there by two motors together consumes 300 milli-amps, the remaining circuitry including microcontroller will consume another 150 milli-amps, hence the entire system consumes around 450 milli-amps approximately. The battery back up time = battery rating / consumed energy. In this chapter, relay driver 2003, relays and power source is explained. In the next chapter , the keil software will be explained.

CHAPTER 6 SOFTWARE SECTION


CROSS COMPILER (CX51) USING KEIL SOFTWARE
36

In chapter 6, the keil software will be explained.

6.1 Introduction
The C programming language is a general-purpose programming language that provides code efficiency, elements of structured programming, and a rich set of operators. C is not a big language and is not designed for any one particular area of application. Its generality combined with its absence of restrictions, makes C a convenient and effective programming solution for a wide variety of software tasks. Many applications can be solved more easily and efficiently with C than with other more specialized languages. The Cx51 Optimizing C Compiler is a complete implementation of the American National Standards Institute (ANSI) standard for the C language. Cx51 is not a universal C compiler adapted for the 8051 target. It is a ground-up implementation dedicated to generating extremely fast and compact code for the 8051 microprocessor. Cx51 provides you with the flexibility of programming in C and the code efficiency and speed of assembly language. The C language on its own is not capable of performing operations (such as input and output) that would normally require intervention from the operating system. Instead, these capabilities are provided as part of the standard library. Because these functions are separate from the language itself, C is especially suited for producing code that is portable across a wide number of platforms.

6.2 Compiling With Cx5


The compiler control directives allow you to:

Direct the Cx51 compiler to generate a listing file Control the amount of information included in the object file 37

Specify optimization level and memory models

Running Cx51 from the Command Prompt To invoke the C51 or CX51 compiler, enter C51 or CX51 at the command prompt. On this command line, you must include the name of the C source file to be compiled, as well as any other necessary control directives required to compile your source file. The format for the Cx51 command line is: C51 sourcefile [directives] CX51 sourcefile [directives] Or C51 @commandfile CX51 @commandfile Where: Sourcefile is the name of the source program you want to compile. Directives are the directives you want to use to control the function of the Compiler refers to Control Directives on page 20 for a detailed list of the available directives. Commandfile is the name of a command input file that may contain sourcefile and directives. A commandfile is used, when the Cx51 invocation line gets complex and exceeds the limits of the Windows command prompt.

6.3 Language Extensions


The Cx51 compiler provides several extensions to ANSI Standard C to support the elements of the 8051 architecture. These include extensions for: Memory Areas Memory Types Memory Models Memory Type Specifiers Variable Data Type Specifiers Bit Variables and Bit-addressable Data Special Function Registers 38

Pointers Function Attributes

Memory Areas The 8051 architecture supports several physically separate memory areas or memory spaces for program and data. Each memory area offers certain advantages and disadvantages. There are memory spaces that may be:

Read from but not written to Read from or written to Read from or written to more quickly than other memory spaces

Program Memory Program (CODE) memory is read only; it cannot be written to. Program memory may reside within the 8051 CPU, it may be external, or it may be both, depending upon the 8051 derivative and the hardware design. There may be up to 64 Kbytes of program memory. Program code, including all functions and library routines, is stored in program memory. Constant variables may also be stored in program memory. The 8051 executes programs stored in program memory only. Program memory may be accessed using the code memory type specifier in the Cx51 compiler. Internal Data Memory Internal data memory resides within the 8051 CPU and is read/write. Up to 256 bytes of internal data memory are available depending upon the 8051 derivative. The first 128 bytes of internal data memory are both directly and indirectly addressable. The upper 128 bytes of data memory (from 0x80 to 0xFF) can be addressed only indirectly. There is also a 16 byte area starting at 20h that is bit-addressable.Access to internal data memory is very fast because it can be accessed using an 8-bit address. However, internal data memory is limited to a maximum of 256 bytes. Internal data can be broken down into three distinct memory types: data, idata, and bdata. The data memory specifier always refers to the first 128 bytes of internal data memory. Variables stored here are accessed using direct addressing. The idata memory specifier refers to all 256 bytes of internal data memory; however, this memory type specifier code. The bdata memory specifier refers to the 16 bytes of bit-addressable

39

memory in the internal data area (20h to 2Fh). This memory type specifier allows you to declare data types that can also be accessed at the bit level. External Data Memory External data memory is read/write. Access to external data is slower than access to internal data memory because the external data memory is indirectly accessed through a data pointer register which must be loaded with an address. Several 8051 devices provide on-chip XRAM space that is accessed with the same instructions as the traditional external data space. This XRAM space is typically enabled via dedicated chip configuration SFR registers and overlaps the external memory space. There may be up to 64 Kbytes of external data memory; though, this address space does not necessarily have to be used as memory. Your hardware design may map peripheral devices into the memory space. If this is the case, your program would access external data memory to program and control the peripheral. This technique is referred to as memory-mapped I/O. The Cx51 Compiler offers two different memory types that access external data: xdata and pdata. The xdata memory specifier refers to any location in the 64Kbyte address space of external data memory. The pdata memory type specifier refers to only one (1) page or 256 bytes of external data memory. See Compact Model on page 95 for more information on pdata. Memory Models The memory model determines the default memory type to use for function arguments, automatic variables, and declarations with no explicit memory type specifier. You specify the memory model on the Cx51 compiler command line using the SMALL, COMPACT and LARGE control directives.

Memory Types The Cx51 compiler explicitly supports the architecture of the 8051 and its derivatives and provides access to all memory areas of the 8051. Each variable may be explicitly assigned to a specific memory space. 40

Accessing the internal data memory is considerably faster than accessing the external data memory. For this reason, place frequently used variables in internal data memory. Place larger, less frequently used variables in external data memory. The following table summarizes the available memory type Specifiers. Table 6.1: Different Memory Types

Function Declarations The Cx51 compiler provides a number of extensions for standard C function declarations. These extensions allow you to: Specify a function as an interrupt procedure Choose the register bank used Select the memory model Specify re-entrancy Specify alien (PL/M-51) functions You may include these extensions or attributes (many of which may be combined) in the function declaration. Use the following standard format for our Cx51 function declarations. [return_type] funcname ([args]) [{small | compact | large}] [re-entrant] [interrupt] [using n] Where: Return_type is the type of the value returned from the function. If no type is specified, int is assumed. Funcname is the name of the function. Args is the argument list for the function. Small, compact, or large is the explicit memory model for the 41

function. Reentrant indicates that the function is recursive or reentrant. Interrupt indicates that the function is an interrupt function. Using specifies which register bank the function uses.

6.4 Interfacing C Programs to Assembler


You can easily interface your programs to routines written in 8051 Assembler. The A51 Assembler is an 8051 macro assembler that emits object modules in OMF-51 format. By observing a few programming rules, you can call assembly routines from C and vice versa. Public variables declared in the assembly module are available to your C programs. There are several reasons to call an assembly routine from your C program.

You may have assembly code already written that you wish to use You may need to improve the speed of a particular function You may want to manipulate SFRs or memory-mapped I/O devices directly from assembly

Parameter Passing In Registers C functions may pass parameters in registers and fixed memory locations. A maximum of 3 parameters may be passed in registers. All other parameters are passed using fixed memory locations. The following tables define what registers are used for passing parameters.

42

Table 6.2: Parameters Passing in Registers

The following examples clarify how registers are selected for parameter passing. Table 6.3: Examples for Parameters Passing

Parameter Passing In Fixed Memory Locations Table 6.4: Parameters Passing in Fixed Memory Locations

43

6.5 From the C Program to the Machine Language


The C source code is very high level language, meaning that it is far from being at the base level of the machine language that can be executed by a processor. This machine language is basically just zero's and one's and is written in Hexadecimal format, that why they are called HEX files. There are several types of HEX files; we are going to produce machine code in the INTEL HEX-80 format, since this is the output of the KEIL IDE that we are going to use. Figure7.1 .A shows that to convert a C program to machine language, it takes several steps depending on the tool you are using, however, the main idea is to produce a HEX file at the end. This HEX file will be then used by the 'burner' to write every byte of data at the appropriate place in the EEPROM of the 89S52

Fig. 6.1 Block Diagram to Convert C Program to Machine Language

6.6 Variables and Constants


One of the most basic concepts of programming is to handle variables. Knowing the exact type and size of a variable is a very important issue for microcontroller programmers, because the RAM is usually limited is size. There are two main design considerations to be taken in account when choosing the variables types: the occupied space in ram and the processing speed. Logically, a variable that occupies a big number of registers in RAM will be more slowly processed than a small variable that fits on a for you to chose the right variable type for each one of your applications, you will have to refer to the following table: 44

Table 6.5: Different Data Types


Data Type Bit signed char unsigned char signed int unsigned int signed long unsigned long Float Bits 1 8 8 16 16 32 32 32 Bytes -1 1 2 2 4 4 4 Value Range 0 to 1 -128 to +127 0 to 255 -32768 to +32767 0 to 65535 -2147483648 to 2147483647 0 to 4294967295 1.175494E-38 to 3.402823E+38

This table shows the number of bits and bytes occupied by each types of variables, noting that each byte will fit into a register. You will notice that most variables can be either 'signed' or unsigned 'unsigned', and the major difference between the two types is the range, but both will occupy the same exact space in memory. The names of the variables shown in the table are the same that are going to be used in the program for variables declarations. Note that in C programming language, any variable have to be declared to be used. To understand the difference between those types, consider the following example source code where we start by declaring three 'unsigned char' variables, and one 'signed char' and then perform some simple operations: Unsigned char a, b, c; signed char d; a = 100; b = 200; c = a - b; d = a b; In that program the values of 'c' will be equal to '155'! and not '-100' as you though, because the variable 'c' is an unsigned type, and when a the value to be stored in a variable is bigger than the maximum value range of this variable, it overflows and rolls back to the other limit. Back to our example, the program is trying to store '-100' in 'c', but since 'c' is unsigned, its range of values is from '0 to 255' so, trying to store a value below zero, will cause the variable to overflow, and the compiler will subtract the '-100' from the other limit plus 1, from '255 + 1' giving '156'. We add 1 to the range because the overflow 45

and roll back operation from 0 to 255 counts for the subtraction of one bit. On the other hand, the value ofd will be equal to '-100' as expected, because it is a 'signed' variable. Generally, we try to avoid storing value that are out of range, because sometime, even if t he compiler doesn't halt on that error, the results can be sometimes totally un-expected. Note that in the C programming language, any code line is ended with a semicolon ';', except for the lines ending with brackets '{' '}'. Like in any programming language, the concept of a variables 'array' can also be used for microcontrollers programming. an array is like a table or a group of variables of the same type, each one can be called by a specific number, for example an array can be declared this way: Char display[10]; this will create a group of 10 variables. Each one of them is accessible by its number, example: display[0] = 100; display[3] = 60; display[1] = display[0] - display[3]; Where 'display[1]' will be equal to '40'. Note that 'display' contains 10 different variables, numbered from 0 to 9. In that previous example, according to the variable declaration, there is not such variable location as display [10]', and using it will cause an error in the compiler. CONSTANTS Sometimes, you want to store a very large amount of constant values, that wouldn't fit in the RAM or simply would take too much space. you can store this DATA in the FLASH memory reserved for the code, but it wont be editable, once the program is burned on your chip. The advantage of this technique is that it can be used to store a huge amount of variables, noting that the FLASH memory of the 89S52 is 8K bytes, 32 times bigger than the RAM memory.It is, however, your responsibility to distribute this memory between your program and your DATA.

46

To specify that a variable is to be stored in the FLASH memory, we use exactly the same variable types names but we add the prefix 'code' before it. Example: code unsigned char message[500]; This line would cause this huge array to be stored in the FLASH memory. This can be interesting for displaying messages on an LCD screen. To access the pins and the ports through programming, there are a number of pre-defined variables (defined in the header file, as you shall see later) that dramatically simplifies that task. There are 4 ports, Port 0 to Port 3, each one of them can be accessed using the char variables P0, P1, P2 and P3 respectively. In those char types variables, each one of using the bit type variables PX_0 to PX_7, where X takes a value between 0 and 3, depending on the port being accessed. For example P1_3 is the pin number 3 of port 1. You can also define your own names, using the '#define' directive. Note that this is compiler directive, meaning that the compiler will use this directive to read and understand the code, but it is not a statement or command that can be translated to machine language. For example, you could define the following: #define LED1 P1_0 With the definition above, the compiler will replace every occurrence of LED1 by P1_0. This makes your code much easier to read, especially when the new names you give make more sense. You could also define a numeric constant value like this: #define led_on_time 184 Then, each time you write led_on_time, it will be replaced by 184. Note that this is not a variable and accordingly, you cannot write something like: led_on_time = 100; //That's wrong, you cannot change a constant's value in code. All C programs have this common organization scheme, sometimes it's followed, sometimes it's not, however, it is imperative for this category of programming that this organization scheme be followed in order to be able to develop your applications successfully.

47

Headers Include and Constants Definitions In this part, header files (.h) are included into your source code. Those headers files can be system headers to declare the name of SFRs, to define new constants, or to include mathematical functions like trigonometric functions, root square calculations or numbers approximations. Variabledeclarations More precisely, this part is dedicated to 'Global Variables' declarations. Variables declared in this place can be used anywhere in the code. Usually in microcontroller programs, variables are declared as global variables instead of local variables, unless you are running short of RAM memory and want to save some space, so we use local variables, whose values will be lost each time you switch from a function to another. Functionsbody Here you group all your functions. Those functions can be simple ones that can be called from another place in your program, as they can be called from an 'interrupt vector' Initialization The particularity of this part is that it is executed only one time when the microcontroller was just subjected to a 'RESET' or when power is just switched ON, then the processor continue executing the rest of the program but never executes this part again. Infiniteloop An infinite loop in a microcontroller program is what is going to keep it alive, because a processor have to be allays running for the system to function, exactly like a heart have to be always beating for a person to live. Usually this part is the core of any program, and its from here that all the other functions are called and executed.

48

6.8 Using The KEIL Environment


KEIL Micro Vision3 is the name of a software dedicated to the development and testing of a family of microcontrollers based on 8051 technology, like the 89S52 which we are going to use along this tutorial. To create a project, write and test the previous example source code, follow the following steps: Open Keil and start a new project

Fig. 6.2 Open Keil and Start a New Project

You will prompted to chose a name for your new project, Create a separate folder where all the files of your project will be stored, chose a name and click save. The following window will appear where you will be asked to select a device for Target 'Target 1':

49

Fig. 6.3 Windows for Selecting a Device From the list at the left, seek for the brand name ATMEL, then under ATMEL, select AT89S52. You will notice that a brief description of the device appears on the right. Leave the two upper check boxes unchecked and click OK. The AT89S52 will be called your 'Target device', which is the final destination of your source code. You will be asked whether to 'copy standard 8051 start up code'

Click File, New, and something similar to the following window should appear. The box named 'Text1' is where your code should be written later

50

Fig. 6.4 Creating Text File Now you have to click 'File, Save as' and chose a file name for your source code ending with the letter '.c'. You can name is 'code.c' for example, and click save. Then you have to add this file to your project work space at the left as shown in the following screen shot:

51

Fig. 6.5 Adding File to the Project

After right-clicking on 'source group 1', click on 'Add files to group...', then you will be prompted to browse the file to add to 'source group 1', chose the file that you just saved, eventually 'code.c' and add it to the source group. You will notice that the file is added to the project tree at the left. 53

In some versions of this software you have to turn ON manually the option to generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target 'target 1', then under the 'output' tab, by checking the box 'generate HEX file'. This step is very important as the HEX file is the compiled

Output of your project that is going to be transferred to the microcontroller. You can then start to write the source code in the window titled 'code.c' then before testing your source code, you have to compile your source code, and correct eventual syntax errors. In KEIL IDE, this step is called 'rebuild all targets' and has this icon:

52

Fig. 6.6 Compiling Source Code You can use the output window to track eventual syntax errors, but also to check the FLASH memory occupied by the program (code = 49) as well as the registers occupied in the RAM (data = 9). If after rebuilding the targets, the 'output window' shows that there is0 errors, then you are ready to test the performance of your code. In keil, like in most development environment, this step is called Debugging, and has this icon: change; some new icons will appear, like the run icon circled in the following figure: .

After clicking on the debug icon, you will notice that some part of the user interface will

53

Fig. 6.7 Debugging the Source Code You can click on the 'Run' icon and the execution of the program will start. In our example, you can see the behaviour of the pin 0 or port one, but clicking on 'peripherals, I/O ports, Port 1'. You can always stop the execution of the program by clicking on the stop button ( ) and you can simulate a reset by clicking on the 'reset' button .

You can also control the execution of the program using the following icons: which allows you to follow the execution step by step. Then, when you're finished with the debugging.

In this chapter, the keil software is explained. In the next chapter, results and conclusion of the project will be explained.

54

CHAPTER 7 RESULTS AND CONCLUSION


7.1 Results
The results of Mobile Controlled Devices for different inputs are presented below with help of figures

Fig. 7.1 Photograph showing Mobile Controlled Devices

55

Fig. 7.2 Photograph showing OFF state of bulb

56

Fig. 7.3 Photograph showing the ON state of bulb

57

7.2 Conclusion
The project work Mobile Controlled devices is designed and developed success fully, tested and results are found to be satisfactory. In any concept of mobile controlled wire less devices, it is essential to attach one mobile phone to the devices. This mobile phone can not be used for normal functions the main function of this phone is to control the vehicle according to the DTMF signals received from the caller phone. The operator of these devices, who is holding the caller phone, can control the devices remotely any where from the world. This project is having reasonable cost as the efficiency, reliability and safety to control home appliances. Using highly advanced ICs and with the help of growing technology the project has been successfully implemented.

7.3 Advantages and Applications


Advantages Unlimited range Generally remote controlled devices are designed with RF or IR communication links, in this regard the range is restricted. When we use RF communication link, the range (distance between the transmitter & receiver) is depends up on the radiating power of the transmitter. To increase the range huge rating of power transmitter must be designed, which is bulky and difficult to operate it. If we use IR (infrared) remote technology, the range is very less under any conditions the range can not be increased more then 100 feet. The advantage of using cell phone technology is, now a days telecommunications network is expanded to each and every corner of the world, there by using this communication link the robot designed here can be controlled any where from the world. 2. Noise free operation In general in RF circuits lot of noise is produced and transmitted, because a very high frequency is generated and used as carrier in RF transmitter, due to heavy noise some times the receiver may not recognize the command signals, which are transmitted over carrier as a modulated signals. In this condition, there may be chance that our rover may behave badly due to wrong commands. This problem will not arise in mobile

58

communication link, because the low frequencies in the form DTMF signals are accurate and well-organized. 3. Un limited control options Presently the system uses only four control options to on and off two devices. Here the task is quite simple, but many more control options are essential to enhance the technology. To do so as it is with out combining or grouping the DTMF signals, 16 different DTMF signals can be generated from the mobile keypad, there by 16 control options can be implemented. This can be increased to n number of control options by grouping the DTMF signals in different combinations. This is not possible in other wireless control systems. 4. Easy to operate The operation is quite simple, after establishing a communication link between the two mobiles, simply by activating the numeric keys of calling mobile any body can operate the system easily. Applications 1. In Long Distance Computer Communication In such system the information from the remote terminal can be accessed, using modem. There could be a situation where the terminal from which we want to down load or upload information may be off from the mains. In such situation data transfer cannot be possible. This situation can be avoided by replacing local switch by MCS. 2. In Industries Or Plants Where the main switching is required in extreme conditions such as high conditions (temperature), under pressure, gaseous condition or extremely cool conditions, where human interpretation is not possible. 3. In Satellite Communication When the satellite is set up initially the MCS can be used to switch various functions. On such as Amplifier, Transponders etc and get acknowledge even in difficulty.

59

4. In Fax machine, the Fax machine is required to keep on constant to receive messages at any time MCS system can be to switch the Fax machine whenever required and not at all the time thus considerably saving power. 5. Multi Access Rural Radio System Similarly in Multi Access Rural Radio System, where the number of calls are quite low and power requirement is high and can be switched ON and OFF using MCS.

7.4 Future Scope:


The mobile controlled devices is very useful in future fast and advance life. Through further improvement we can control the appliances by giving timing with the microcontrollers and computers. This application is very useful in industry where the energy consumption per second is very large so that the product cost can be reduced. And also we can introduce security code for usage of this mobile control.

60

APPENDICES DATASHEETS OF AT89C52


Absolute Maximum Ratings:

Dc Characteristics:

61

External Program and Data Memory Characteristics:

62

REFERENCES
Books
1. Kenneth J. Ayala, The 8051 Microcontroller Architecture, Programming & Applications, Penram International, 2nd Edition, 2002. 2. Myke Predko, Programming and Customizing The 8051 Microcontroller, Tata Mc Graw Hill. 3. Muhammad Ali Muzidi and Janice Gillespe Mazidi, The 8051 Microcontroller and Embedded Systems, Prentice Hall of India Pvt. Ltd, 3rd Edition 2002.

URLS
1. 2. 3. 4. www.microchip.com www.keil.com www.ultrasonicsensors.com www.atmel.com

63

You might also like