ABSTRACT Security is primary concern for every one. This Project describes a design ofeffective security alarm system that can monitor an industry with different sensors.Unauthorized access, Temperature increment, IR detection can be monitored by the statusof each individual sensor. Obviously, this burglar alarm also has an input to arm thealarm, a tamper input and a couple of outputs to control a siren and Auto dialing system.The alarm is also fitted with a so-called panic button. The burglar alarm is built around the 8051 micro controller from Atmel. Thismicro controller provides all the functionality of the burglar alarm. It also takes care offiltering of the signals at the inputs. Only after an input has remained unchanged for 30milliseconds, is this new signal level passed on for processing by the micro controllerprogram. This time can be varied by adopting small changes in the source code. A maximum of 5 sensors can be connected to the burglar alarm. These sensorsneed to have their contacts closed when in the inactive state (i.e. Normally Closed). Inaddition, each sensor needs to have its tamper connection wired as well. A power supplyvoltage of +5 VDC is available for each sensor at the corresponding wiring terminals. The uniqueness of this project is not only alerting the neighbors by siren, it alsodials a mobile number which is already programmed into the system. A mobile numberor a land line number can be programmed into the system. As this system works onexisting telephone line, it can dial the number even the subscriber is out of station. This project uses regulated 5V, 500mA power supply. 7805 three terminal voltageregulator is used for voltage regulation. Bridge type full wave rectifier is used to rectifythe ac out put of secondary of 230/12V step down transformer.
INTRODUCTIONSecurity is the condition of being protected against danger or loss. In the general sense,security is a concept similar to safety. The nuance between the two is an added emphasison being protected from dangers that originate from outside. Individuals or actions thatencroach upon the condition of protection are responsible for the breach of security. Theword "security" in general usage is synonymous with "safety," but as a technical term"security" means that something not only is secure but that it has been secured. One ofthe best options for providing good security is by using a technology namedEMBEDDED SYSTEMS.INTRODUCTION TO EMBEDDED SYSTEMS An embedded system can be defined as a computing device that does a specificfocused job. Appliances such as the air-conditioner, VCD player, DVD player, printer,fax machine, mobile phone etc. are examples of embedded systems. Each of theseappliances will have a processor and special hardware to meet the specific requirement ofthe application along with the embedded software that is executed by the processor formeeting that specific requirement. The embedded software is also called “firm ware”.The desktop/laptop computer is a general purpose computer. You can use it for a varietyof applications such as playing games, word processing, accounting, softwaredevelopment and so on. In contrast, the software in the embedded systems is always fixedlisted below:· Embedded systems do a very specific task, they cannot be programmed to do differentthings. . Embedded systems have very limited resources, particularly the memory.Generally, they do not have secondary storage devices such as the CDROM or the floppydisk. Embedded systems have to work against some deadlines. A specific job has to becompleted within a specific time. In some embedded systems, called real-time systems,the deadlines are stringent. Missing a deadline may cause a catastrophe-loss of life ordamage to property. Embedded systems are constrained for power. As many embeddedsystems operate through a battery, the power consumption has to be very low.
· Some embedded systems have to operate in extreme environmental conditions such asvery high temperatures and humidity.Application AreasNearly 99 per cent of the processors manufactured end up in embedded systems. Theembedded system market is one of the highest growth areas as these systems are used invery market segment- consumer electronics, office automation, industrial automation,biomedical engineering, wireless communication, data communication,telecommunications, transportation, military and so on.Consumer appliances: At home we use a number of embedded systems which includedigital camera, digital diary, DVD player, electronic toys, microwave oven, remotecontrols for TV and air-conditioner, VCO player, video game consoles, video recordersetc. Today’s high-tech car has about 20 embedded systems for transmission control,engine spark control, air-conditioning, navigation etc. Even wristwatches are nowbecoming embedded systems. The palmtops are powerful embedded systems using whichwe can carry out many general-purpose tasks such as playing games and wordprocessing.Office automation: The office automation products using em embedded systems arecopying machine, fax machine, key telephone, modem, printer, scanner etc.Industrial automation: Today a lot of industries use embedded systems for processcontrol. These include pharmaceutical, cement, sugar, oil exploration, nuclear energy,electricity generation and transmission. The embedded systems for industrial use aredesigned to carry out specific tasks such as monitoring the temperature, pressure,humidity, voltage, current etc., and then take appropriate action based on the monitoredlevels to control other devices or to send information to a centralized monitoring station.In hazardous industrial environment, where human presence has to be avoided, robots areused, which are programmed to do specific jobs. The robots are now becoming very
powerful and carry out many interesting and complicated tasks such as hardwareassembly.Medical electronics: Almost every medical equipment in the hospital is an embeddedsystem. These equipments include diagnostic aids such as ECG, EEG, blood pressuremeasuring devices, X-ray scanners; equipment used in blood analysis, radiation,colonscopy, endoscopy etc. Developments in medical electronics have paved way formore accurate diagnosis of diseases.Computer networking: Computer networking products such as bridges, routers,Integrated Services Digital Networks (ISDN), Asynchronous Transfer Mode (ATM),X.25 and frame relay switches are embedded systems which implement the necessarydata communication protocols. For example, a router interconnects two networks. Thetwo networks may be running different protocol stacks. The router’s function is to obtainthe data packets from incoming pores, analyze the packets and send them towards thedestination after doing necessary protocol conversion. Most networking equipments,other than the end systems (desktop computers) we use to access the networks, areembedded systems.Telecommunications: In the field of telecommunications, the embedded systems can becategorized as subscriber terminals and network equipment. The subscriber terminalssuch as key telephones, ISDN phones, terminal adapters, web cameras are embeddedsystems. The network equipment includes multiplexers, multiple access systems, PacketAssemblers Dissemblers (PADs), sate11ite modems etc. IP phone, IP gateway, IPgatekeeper etc. are the latest embedded systems that provide very low-cost voicecommunication over the Internet.Wireless technologies: Advances in mobile communications are paving way for manyinteresting applications using embedded systems. The mobile phone is one of the marvelsof the last decade of the 20’h century. It is a very powerful embedded system thatprovides voice communication while we are on the move. The Personal Digital Assistantsand the palmtops can now be used to access multimedia services over the Internet.
Mobile communication infrastructure such as base station controllers, mobile switchingcenters are also powerful embedded systems.Insemination: Testing and measurement are the fundamental requirements in allscientific and engineering activities. The measuring equipment we use in laboratories tomeasure parameters such as weight, temperature, pressure, humidity, voltage, current etc.are all embedded systems. Test equipment such as oscilloscope, spectrum analyzer, logicanalyzer, protocol analyzer, radio communication test set etc. are embedded systems builtaround powerful processors. Thank to miniaturization, the test and measuring equipmentare now becoming portable facilitating easy testing and measurement in the field byfield-personnel.Security: Security of persons and information has always been a major issue. We need toprotect our homes and offices; and also the information we transmit and store.Developing embedded systems for security applications is one of the most lucrativebusinesses nowadays. Security devices at homes, offices, airports etc. for authenticationand verification are embedded systems. Encryption devices are nearly 99 per cent ofthe processors that are manufactured end up in~ embedded systems. Embedded systemsfind applications in . every industrial segment- consumer electronics, transportation,avionics, biomedical engineering, manufacturing, process control and industrialautomation, data communication, telecommunication, defense, security etc. Used toencrypt the data/voice being transmitted on communication links such as telephone lines.Biometric systems using fingerprint and face recognition are now being extensively usedfor user authentication in banking applications as well as for access control in highsecurity buildings.Finance: Financial dealing through cash and cheques are now slowly paving way fortransactions using smart cards and ATM (Automatic Teller Machine, also expanded asAny Time Money) machines. Smart card, of the size of a credit card, has a small micro-controller and memory; and it interacts with the smart card reader! ATM machine andacts as an electronic wallet. Smart card technology has the capability of ushering in a
cashless society. Well, the list goes on. It is no exaggeration to say that eyes whereveryou go, you can see, or at least feel, the work of an embedded system!Overview of Embedded System ArchitectureEvery embedded system consists of custom-built hardware built around a CentralProcessing Unit (CPU). This hardware also contains memory chips onto which thesoftware is loaded. The software residing on the memory chip is also called the‘firmware’. The embedded system architecture can be represented as a layeredarchitecture as shown in Fig.The operating system runs above the hardware, and the application software runs abovethe operating system. The same architecture is applicable to any computer including adesktop computer. However, there are significant differences. It is not compulsory tohave an operating system in every embedded system. For small appliances such as remotecontrol units, air conditioners, toys etc., there is no need for an operating system and youcan write only the software specific to that application. For applications involvingcomplex processing, it is advisable to have an operating system. In such a case, you needto integrate the application software with the operating system and then transfer the entiresoftware on to the memory chip. Once the software is transferred to the memory chip, thesoftware will continue to run for a long time you don’t need to reload new software.Now, let us see the details of the various building blocks of the hardware of an embeddedsystem. As shown in Fig. the building blocks are;
· Central Processing Unit (CPU)· Memory (Read-only Memory and Random Access Memory)· Input Devices· Output devices· Communication interfaces· Application-specific circuitryCentral Processing Unit (CPU):The Central Processing Unit (processor, in short) can be any of the following:microcontroller, microprocessor or Digital Signal Processor (DSP). A micro-controller isa low-cost processor. Its main attraction is that on the chip itself, there will be many othercomponents such as memory, serial communication interface, analog-to digital converteretc. So, for small applications, a micro-controller is the best choice as the number ofexternal components required will be very less. On the other hand, microprocessors aremore powerful, but you need to use many external components with them. D5P is usedmainly for applications in which signal processing is involved such as audio and videoprocessing.Memory:
The memory is categorized as Random Access 11emory (RAM) and Read Only Memory(ROM). The contents of the RAM will be erased if power is switched off to the chip,whereas ROM retains the contents even if the power is switched off. So, the firmware isstored in the ROM. When power is switched on, the processor reads the ROM; theprogram is program is executed.Input devices:Unlike the desktops, the input devices to an embedded system have very limitedcapability. There will be no keyboard or a mouse, and hence interacting with theembedded system is no easy task. Many embedded systems will have a small keypad-youpress one key to give a specific command. A keypad may be used to input only the digits.Many embedded systems used in process control do not have any input device for userinteraction; they take inputs from sensors or transducers 1’fnd produce electrical signalsthat are in turn fed to other systems.Output devices:The output devices of the embedded systems also have very limited capability. Someembedded systems will have a few Light Emitting Diodes (LEDs) to indicate the healthstatus of the system modules, or for visual indication of alarms. A small Liquid CrystalDisplay (LCD) may also be used to display some important parameters.Communication interfaces:The embedded systems may need to, interact with other embedded systems at they mayhave to transmit data to a desktop. To facilitate this, the embedded systems are providedwith one or a few communication interfaces such as RS232, RS422, RS485, UniversalSerial Bus (USB), IEEE 1394, Ethernet etc.Application-specific circuitry: Sensors, transducers, special processing and control circuitry may be required fat anembedded system, depending on its application. This circuitry interacts with theprocessor to carry out the necessary work. The entire hardware has to be given power
supply either through the 230 volts main supply or through a battery. The hardware has todesigned in such a way that the power consumption is minimized.BLOCK DIAGRAM
POWER SUPPLY:The input to the circuit is applied from the regulated power supply. The a.c. input i.e.,230V from the mains supply is step down by the transformer to 12V and is fed to arectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order toget a pure d.c voltage, the output voltage from the rectifier is fed to a filter to remove anya.c components present even after rectification. Now, this voltage is given to a voltageregulator to obtain a pure constant dc voltage. 230V AC 50Hz D.C Output Step down Bridge Filter Regulator transformer Rectifier Fig: Power supplyTransformer: Usually, DC voltages are required to operate various electronic equipment andthese voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thusthe a.c input available at the mains supply i.e., 230V is to be brought down to therequired voltage level. This is done by a transformer. Thus, a step down transformer isemployed to decrease the voltage to a required level.
Rectifier: The output from the transformer is fed to the rectifier. It converts A.C. intopulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this project, abridge rectifier is used because of its merits like good stability and full wave rectification.Filter: Capacitive filter is used in this project. It removes the ripples from the output ofrectifier and smoothens the D.C. Output received from this filter is constant until themains voltage and load is maintained constant. However, if either of the two is varied,D.C. voltage received at this point changes. Therefore a regulator is applied at the outputstage.Voltage regulator: As the name itself implies, it regulates the input applied to it. A voltage regulatoris an electrical regulator designed to automatically maintain a constant voltage level. Inthis project, power supply of 5V and 12V are required. In order to obtain these voltagelevels, 7805 and 7812 voltage regulators are to be used. The first number 78 representspositive supply and the numbers 05, 12 represent the required output voltage levels.MICROCONTROLLERS:
Microprocessors and microcontrollers are widely used in embeddedsystems products. Microcontroller is a programmable device. A microcontroller has aCPU in addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all ona single chip. The fixed amount of on-chip ROM, RAM and number of I/O ports inmicrocontrollers makes them ideal for many applications in which cost and space arecritical. The Intel 8051 is Harvard architecture, single chip microcontroller (µC) whichwas developed by Intel in 1980 for use in embedded systems. It was popular in the 1980sand early 1990s, but today it has largely been superseded by a vast range of enhanceddevices with 8051-compatible processor cores that are manufactured by more than 20independent manufacturers including Atmel, Infineon Technologies and MaximIntegrated Products. 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of dataat a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by theCPU. 8051 is available in different memory types such as UV-EPROM, Flash and NV-RAM. The present project is implemented on Keil Uvision. In order to program thedevice, Proload tool has been used to burn the program onto the microcontroller. The features, pin description of the microcontroller and the software tools usedare discussed in the following sections.FEATURES OF AT89s52:
• 8K Bytes of Re-programmable Flash Memory.• RAM is 256 bytes.• 4.0V to 5.5V Operating Range.• Fully Static Operation: 0 Hz to 33 MHz’s• Three-level Program Memory Lock.• 256 x 8-bit Internal RAM.• 32 Programmable I/O Lines.• Three 16-bit Timer/Counters.• Eight Interrupt Sources.• Full Duplex UART Serial Channel.• Low-power Idle and Power-down Modes.• Interrupt recovery from power down mode.• Watchdog timer.• Dual data pointer.• Power-off flag.• Fast programming time.• Flexible ISP programming (byte and page mode).Description:The AT89s52 is a low-voltage, high-performance CMOS 8-bit microcomputer with 8Kbytes of Flash programmable memory. The device is manufactured using Atmel’s highdensity nonvolatile memory technology and is compatible with the industry-standardMCS-51 instruction set. The on chip flash allows the program memory to bereprogrammed in system or by a conventional non volatile memory programmer. Bycombining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89s52 is apowerful microcomputer, which provides a highly flexible and cost-effective solution tomany embedded control applications.
In addition, the AT89s52 is designed with static logic for operation down to zerofrequency and supports two software selectable power saving modes. The Idle Modestops the CPU while allowing the RAM, timer/counters, serial port and interrupt systemto continue functioning. The power-down mode saves the RAM contents but freezes theoscillator disabling all other chip functions until the next hardware reset. Fig: Pin diagram
PIN DESCRIPTION:Vcc Pin 40 provides supply voltage to the chip. The voltage source is +5V.GND Pin 20 is the ground.Port 0Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sinkeight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance 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 hasinternal pull-ups.Port 0 also receives the code bytes during Flash programming and outputs the code bytesduring Program verification. External pull-ups are required during program verification.Port 1Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output bufferscan sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled highby the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that areexternally being pulled low will source current (IIL) because of the internal pull-ups. Inaddition, 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, as shown inthe following table.Port 1 also receives the low-order address bytes during Flash programming andverification.
Port 2Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output bufferscan sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled highby the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that areexternally being pulled low will source current (IIL) because of the internal pull-ups.Port 2 emits the high-order address byte during fetches from external program memoryand during accesses to external data memory that uses 16-bit addresses (MOVX @DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. Duringaccesses to external data memory that uses 8-bit addresses (MOVX @ RI), Port 2 emitsthe contents of the P2 Special Function Register. The port also receives the high-orderaddress bits and some control signals during Flash programming and verification.Port 3Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output bufferscan sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled highby the internal pull-ups and can be used as inputs. As inputs, Port 3 pins that areexternally being pulled low will source current (IIL) because of the pull-ups. Port 3receives some control signals for Flash programming and verification.Port 3 also serves the functions of various special features of the AT89S52, as shown inthe following table.
RSTReset input. A high on this pin for two machine cycles while the oscillator is runningresets the device. This pin drives high for 98 oscillator periods after the Watchdog timesout. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. Inthe default state of bit DISRTO, the RESET HIGH out feature is enabled.ALE/PROGAddress Latch Enable (ALE) is an output pulse for latching the low byte of the addressduring 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 andmay be used for external timing or clocking purposes. Note, however, that one ALE pulseis skipped during each access to external data memory.If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With thebit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin isweakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is inexternal execution mode.
PSENProgram Store Enable (PSEN) is the read strobe to external program memory. When theAT89S52 is executing code from external program memory, PSEN is activated twiceeach machine cycle, except that two PSEN activations are skipped during each access toexternal data memory.EA/VPPExternal Access Enable. EA must be strapped to GND in order to enable the device tofetch 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 the12-volt programming enable voltage (VPP) during Flash programming.XTAL1Input to the inverting oscillator amplifier and input to the internal clock operating circuit.XTAL2Output from the inverting oscillator amplifier.Oscillator ConnectionsC1, C2 = 30 pF ± 10 pF for Crystals = 40 pF ± 10 pF for Ceramic ResonatorsExternal Clock Drive Configuration
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier thatcan be configured for use as an on-chip oscillator. Either a quartz crystal or ceramicresonator may be used. To drive the device from an external clock source, XTAL2 shouldbe left unconnected while XTAL1 is driven. There are no requirements on the duty cycleof the external clock signal, since the input to the internal clocking circuitry is through adivide-by-two flip-flop, but minimum and maximum voltage high and low timespecifications must be observed.Special Function RegistersA map of the on-chip memory area called the Special Function Register (SFR) space isshown in the following table.It should be noted that not all of the addresses are occupied and unoccupied addressesmay not be implemented on the chip. Read accesses to these addresses will in generalreturn 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 infuture products to invoke new features. In that case, the reset or inactive values of thenew bits will always be 0.Timer 2 Registers:
Control and status bits are contained in registers T2CON and T2MOD for Timer 2. Theregister pair (RCAP2H, RCAP2L) is the Capture/Reload register for Timer 2 in 16-bitcapture mode or 16-bit auto-reload mode.Interrupt Registers:The individual interrupt enable bits are in the IE register. Two priorities can be set foreach 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 16-bit DataPointer Registers are provided: DP0 at SFR address locations 82H-83H and DP1 at 84Hand 85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1. The usershould ALWAYS initialize the DPS bit to the appropriate value before accessing therespective 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 byreset.
Memory OrganizationMCS-51 devices have a separate address space for Program and Data Memory. Up to64K bytes each of external Program and Data Memory can be addressed.Program MemoryIf 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 0000Hthrough 1FFFH are directed to internal memory and fetches to addresses 2000H throughFFFFH are to external memory.Data MemoryThe AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy aparallel address space to the Special Function Registers. This means that the upper 128bytes have the same addresses as the SFR space but are physically separate from SFRspace.When an instruction accesses an internal location above address 7FH, the address modeused in the instruction specifies whether the CPU accesses the upper 128 bytes of RAMor the SFR space. Instructions which use direct addressing access the SFR space.
For example, the following direct addressing instruction accesses the SFR at location0A0H (which is P2). MOV 0A0H, #dataInstructions that use indirect addressing access the upper 128 bytes of RAM. Forexample, 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, #dataNote that stack operations are examples of indirect addressing, so the upper 128 bytes ofdata RAM are available as stack space.Watchdog Timer (One-time Enabled with Reset-out) The WDT is intended as a recovery method in situations where the CPU may besubjected to software upsets. The WDT consists of a 14-bit counter and the WatchdogTimer Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. Toenable 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 isrunning. The WDT timeout period is dependent on the external clock frequency. There isno way to disable the WDT except through reset (either hardware reset or WDT overflowreset). When WDT overflows, it will drive an output RESET HIGH pulse at the RST pin.
Using the WDT To enable the WDT, a user must write 01EH and 0E1H in sequence to theWDTRST register (SFR location 0A6H). When the WDT is enabled, the user needs toservice it by writing 01EH and 0E1H to WDTRST to avoid a WDT overflow. The 14-bitcounter overflows when it reaches 16383 (3FFFH), and this will reset the device. Whenthe WDT is enabled, it will increment every machine cycle while the oscillator isrunning. This means the user must reset the WDT at least every 16383 machine cycles. To reset the WDT the user must write 01EH and 0E1H to WDTRST. WDTRST isa write-only register. The WDT counter cannot be read or written. When WDToverflows, it will generate an output RESET pulse at the RST pin. The RESET pulseduration is 98xTOSC, where TOSC = 1/FOSC. To make the best use of the WDT, itshould be serviced in those sections of code that will periodically be executed within thetime required to prevent a WDT reset.WDT during Power-down and IdleIn Power-down mode the oscillator stops, which means the WDT also stops. While inPower down mode, the user does not need to service the WDT. There are two methods ofexiting Power-down mode: by a hardware reset or via a level-activated external interruptwhich is enabled prior to entering Power-down mode. When Power-down is exited withhardware reset, servicing the WDT should occur as it normally does whenever theAT89S52 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 isbrought high, the interrupt is serviced. To prevent the WDT from resetting the devicewhile the interrupt pin is held low, the WDT is not started until the interrupt is pulledhigh. It is suggested that the WDT be reset during the interrupt service for the interruptused to exit Power-down mode.To ensure that the WDT does not overflow within a few states of exiting Power-down, itis 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 determinewhether 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 the AT89S52while in IDLE mode, the user should always set up a timer that will periodically exitIDLE, service the WDT, and reenter IDLE mode. With WDIDLE bit enabled, the WDTwill stop to count in IDLE mode and resumes the count upon exit from IDLE.UARTThe Atmel 80C51 Microcontrollers implement three general purpose, 16-bit timers/counters. They are identified as Timer 0, Timer 1 and Timer 2 and can be independentlyconfigured to operate in a variety of modes as a timer or as an event counter. Whenoperating as a timer, the timer/counter runs for a programmed length of time and thenissues an interrupt request. When operating as a counter, the timer/counter countsnegative transitions on an external pin. After a preset number of counts, the counterissues an interrupt request. The various operating modes of each timer/counter aredescribed in the following sections.A basic operation consists of timer registers THx and TLx (x= 0, 1) connected in cascadeto form a 16-bit timer. Setting the run control bit (TRx) in TCON register turns the timeron by allowing the selected input to increment TLx. When TLx overflows it incrementsTHx; when THx overflows it sets the timer overflow flag (TFx) in TCON register.Setting the TRx does not clear the THx and TLx timer registers. Timer registers can beaccessed to obtain the current count or to enter preset values. They can be read at anytime but TRx bit must be cleared to preset their values, otherwise the behavior of thetimer/counter is unpredictable.The C/Tx# control bit (in TCON register) selects timer operation, or counter operation,by selecting the divided-down peripheral clock or external pin Tx as the source for thecounted signal. TRx bit must be cleared when changing the mode of operation, otherwisethe behavior of the timer/counter is unpredictable. For timer operation (C/Tx# = 0), the
timer register counts the divided-down peripheral clock. The timer register is incrementedonce every peripheral cycle (6 peripheral clock periods). The timer clock rate is FPER /6, i.e. FOSC / 12 in standard mode or FOSC / 6 in X2 mode. For counter operation(C/Tx# = 1), the timer register counts the negative transitions on the Tx external inputpin. The external input is sampled every peripheral cycle. When the sample is high in onecycle and low in the next one, the counter is incremented.Since it takes 2 cycles (12 peripheral clock periods) to recognize a negative transition,the maximum count rate is FPER / 12, i.e. FOSC / 24 in standard mode or FOSC / 12 inX2 mode. There are no restrictions on the duty cycle of the external input signal, but toensure that a given level is sampled at least once before it changes, it should be held forat least one full peripheral cycle. In addition to the “timer” or “counter” selection, Timer0 and Timer 1 have four operating modes from which to select which are selected by bit-pairs (M1, M0) in TMOD. Modes 0, 1and 2 are the same for both timer/counters. Mode 3is different.The four operating modes are described below. Timer 2, has three modes of operation:‘capture’, ‘auto-reload’ and ‘baud rate generator’.Timer 0Timer 0 functions as either a timer or event counter in four modes of operation.Timer 0 is controlled by the four lower bits of the TMOD register and bits 0, 1, 4 and 5 ofthe TCON register. TMOD register selects the method of timer gating (GATE0), timer orcounter operation (T/C0#) and mode of operation (M10 and M00). The TCON registerprovides timer 0 control functions: overflow flag (TF0), run control bit (TR0), interruptflag (IE0) and interrupt type control bit (IT0).For normal timer operation (GATE0= 0), setting TR0 allows TL0 to be incremented by
the selected input. Setting GATE0 and TR0 allows external pin INT0# to control timeroperation.Timer 0 overflow (count rolls over from all 1s to all 0s) sets TF0 flag, generating aninterrupt request. It is important to stop timer/counter before changing mode.Mode 0 (13-bit Timer)Mode 0 configures timer 0 as a 13-bit timer which is set up as an 8-bit timer (TH0register) with a modulo 32 prescaler implemented with the lower five bits of the TL0register. The upper three bits of TL0 register are indeterminate and should be ignored.Prescaler overflow increments the TH0 register.As the count rolls over from all 1’s to all 0’s, it sets the timer interrupt flag TF0. Thecounted input is enabled to the Timer when TR0 = 1 and either GATE = 0 or INT0 = 1.(Setting GATE = 1 allows the Timer to be controlled by external input INT0, to facilitatepulse width measurements). TR0 is a control bit in the Special Function register TCON.GATE is in TMOD.The 13-bit register consists of all 8 bits of TH0 and the lower 5 bits of TL0. The upper 3bits of TL0 are indeterminate and should be ignored. Setting the run flag (TR0) does notclear the registers.Mode 0 operation is the same for Timer 0 as for Timer 1. There are two different GATEbits, one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3).Timer/Counter x (x = 0 or 1) in Mode 0
Mode 1 (16-bit Timer)Mode 1 is the same as Mode 0, except that the Timer register is being run with all 16bits. Mode 1 configures timer 0 as a 16-bit timer with the TH0 and TL0 registersconnected in cascade. The selected input increments the TL0 register.Timer/Counter x (x = 0 or 1) in Mode 1Mode 2 (8-bit Timer with Auto-Reload)Mode 2 configures timer 0 as an 8-bit timer (TL0 register) that automatically reloadsfrom the TH0 register. TL0 overflow sets TF0 flag in the TCON register and reloads TL0with the contents of TH0, which is preset by software.When the interrupt request is serviced, hardware clears TF0. The reload leaves TH0unchanged. The next reload value may be changed at any time by writing it to the TH0register. Mode 2 operation is the same for Timer/Counter 1.Timer/Counter x (x = 0 or 1) in Mode 2
Mode 3 (Two 8-bit Timers)Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers.This mode is provided for applications requiring an additional 8-bit timer or counter. TL0uses the timer 0 control bits C/T0# and GATE0 in the TMOD register, and TR0 and TF0in the TCON register in the normal manner. TH0 is locked into a timer function (countingFPER /6) and takes over use of the timer 1 interrupt (TF1) and run control (TR1) bits.Thus, operation of timer 1 is restricted when timer 0 is in mode 3.Timer/Counter 0 in Mode 3: Two 8-bit CountersTimer 1Timer 1 is identical to timer 0, except for mode 3, which is a hold-count mode. Thefollowing comments help to understand the differences:• Timer 1 functions as either a timer or event counter in three modes of operation. Timer1’s mode 3 is a hold-count mode.• Timer 1 is controlled by the four high-order bits of the TMOD register and bits 2, 3, 6and 7 of the TCON register. The TMOD register selects the method of timer gating
(GATE1), timer or counter operation (C/T1#) and mode of operation (M11 and M01).The TCON register provides timer 1 control functions: overflow flag (TF1), run controlbit (TR1), interrupt flag (IE1) and interrupt type control bit (IT1).• Timer 1 can serve as the baud rate generator for the serial port. Mode 2 is best suited forthis purpose.• For normal timer operation (GATE1 = 0), setting TR1 allows TL1 to be incremented bythe selected input. Setting GATE1 and TR1 allows external pin INT1# to control timeroperation.• Timer 1 overflow (count rolls over from all 1s to all 0s) sets the TF1 flag generating aninterrupt request.• When timer 0 is in mode 3, it uses timer 1’s overflow flag (TF1) and run control bit(TR1). For this situation, use timer 1 only for applications that do not require an interrupt(such as a baud rate generator for the serial port) and switch timer 1 in and out of mode 3to turn it off and on.• It is important to stop timer/counter before changing modes.Mode 0 (13-bit Timer)Mode 0 configures Timer 1 as a 13-bit timer, which is set up as an 8-bit timer (TH1register) with a modulo-32 prescaler implemented with the lower 5 bits of the TL1register. The upper 3 bits of the TL1 register are ignored. Prescaler overflow incrementsthe TH1 register.Mode 1 (16-bit Timer)Mode 1 configures Timer 1 as a 16-bit timer with the TH1 and TL1 registers connectedin cascade. The selected input increments the TL1 register.Mode 2 (8-bit Timer with Auto Reload)Mode 2 configures Timer 1 as an 8-bit timer (TL1 register) with automatic reload fromthe TH1 register on overflow. TL1 overflow sets the TF1 flag in the TCON register andreloads TL1 with the contents of TH1, which is preset by software. The reload leavesTH1 unchanged.
Mode 3 (Halt)Placing Timer 1 in mode 3 causes it to halt and hold its count. This can be used to haltTimer 1 when TR1 run control bit is not available i.e., when Timer 0 is in mode 3.Timer 2Timer 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 (shown in Table 5-2).Timer 2 has three operating modes: capture, auto-reload (up or down counting), and baudrate generator. The modes are selected by bits in T2CON, as shown in Table 10-1. Timer2 consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register isincremented every machine cycle. Since a machine cycle consists of 12 oscillator periods,the count rate is 1/12 of the oscillator frequency.In the Counter function, the register is incremented in response to a 1-to-0 transition at itscorresponding external input pin, T2. In this function, the external input is sampledduring S5P2 of every machine cycle. When the samples show a high in one cycle and alow in the next cycle, the count is incremented. The new count value appears in theregister during S3P1 of the cycle following the one in which the transition was detected.Since two machine cycles (24 oscillator periods) are required to recognize a 1-to-0transition, the maximum count rate is 1/24 of the oscillator frequency. To ensure that agiven level is sampled at least once before it changes, the level should be held for at leastone full machine cycle.
Capture ModeIn the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0,Timer 2 is a 16-bit timer or counter which upon overflow sets bit TF2 in T2CON. This bitcan then be used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the sameoperation, but a 1-to-0 transition at external input T2EX also causes the current value inTH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, thetransition at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, cangenerate an interrupt. Timer in Capture ModeAuto-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 inthe SFR T2MOD. Upon reset, the DCEN bit is set to 0 so that timer 2 will default tocount up. When DCEN is set, Timer 2 can count up or down, depending on the value ofthe T2EX pin.
T2MOD – Timer 2 Mode Control RegisterThe above figure shows Timer 2 automatically counting up when DCEN = 0. In thismode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 countsup to 0FFFFH and then sets the TF2 bit upon overflow. The overflow also causes thetimer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The valuesin Timer in Capture ModeRCAP2H and RCAP2L are preset by software. If EXEN2 = 1,a 16-bit reload can be triggered either by an overflow or by a 1-to-0 transition at externalinput T2EX. This transition also sets the EXF2 bit. Both the TF2 and EXF2 bits cangenerate an interrupt if enabled.Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 10-2. Inthis mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makesTimer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflowalso causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timerregisters, TH2 and TL2, respectively.A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit andcauses 0FFFFH to be reloaded into the timer registers.The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.
Baud Rate GeneratorTimer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON.Note that the baud rates for transmit and receive can be different if Timer 2 is used for thereceiver or transmitter and Timer 1 is used for the other function. Setting RCLK and/orTCLK puts Timer 2 into its baud rate generator mode.
The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2Hand RCAP2L, which are preset by software.The baud rates in Modes 1 and 3 are determined by Timer 2’s overflow rate according tothe following equation.The Timer can be configured for either timer or counter operation. In most applications, itis configured for timer operation (CP/T2 = 0). The timer operation is different for Timer2 when it is used as a baud rate generator. Normally, as a timer, it increments everymachine cycle (at 1/12 the oscillator frequency). As a baud rate generator, however, itincrements every state time (at 1/2 the oscillator frequency). The baud rate formula isgiven below.Where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bitunsigned integer.Timer 2 as a baud rate generator is shown in the below figure. This figure is valid only ifRCLK or TCLK = 1 in T2CON. Note that a rollover in TH2 does not set TF2 and willnot generate an interrupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX willset EXF2 but will not cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus,when Timer 2 is in use as a baud rate generator, T2EX can be used as an extra externalinterrupt.Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator mode,TH2 or TL2 should not be read from or written to. Under these conditions, the Timer is
incremented every state time, and the results of a read or write may not be accurate. TheRCAP2 registers may be read but should not be written to, because a write might overlapa reload and cause write and/or reload errors. The timer should be turned off (clear TR2)before accessing the Timer 2 or RCAP2 registers. Timer 2 in Baud Rate Generator ModeProgrammable Clock OutA 50% duty cycle clock can be programmed to come out on P1.0, as shown in the belowfigure. This pin, besides being a regular I/O pin, has two alternate functions. It can beprogrammed to input the external clock for Timer/Counter 2 or to output a 50% dutycycle clock ranging from 61 Hz to 4 MHz (for a 16-MHz operating frequency).
Timer 2 in Clock-Out ModeTo configure the Timer/Counter 2 as a clock generator, bit C/T2 (T2CON.1) must becleared and bit T2OE (T2MOD.1) must be set. Bit TR2 (T2CON.2) starts and stops thetimer. The clock-out frequency depends on the oscillator frequency and the reload valueof Timer 2 capture registers (RCAP2H, RCAP2L), as shown in the following equation.In the clock-out mode, Timer 2 roll-overs will not generate an interrupt. This behavior issimilar to when Timer 2 is used as a baud-rate generator. It is possible to use Timer 2 as abaud-rate generator and a clock generator simultaneously. Note, however, that the baudrate and clock-out frequencies cannot be determined independently from one anothersince they both use RCAP2H and RCAP2L.Interrupts
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 andINT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. Theseinterrupts are all shown in Figure 13-1.Each of these interrupt sources can be individually enabled or disabled by setting orclearing a bit in Special Function Register IE. IE also contains a global disable bit, EA,which disables all interrupts at once. Note that Table 13-1 shows that bit position IE.6 isunimplemented. User software should not write a 1 to this bit position, since it may beused in future AT89 products.Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in registerT2CON. Neither of these flags is cleared by hardware when the service routine isvectored to. In fact, the service routine may have to determine whether it was TF2 orEXF2 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 thetimers 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 timeroverflows.
Idle ModeIn idle mode, the CPU puts itself to sleep while all the on-chip peripherals remain active.The mode is invoked by software. The content of the on-chip RAM and all the specialfunctions registers remain unchanged during this mode. The idle mode can be terminatedby any enabled interrupt or by a hardware reset.Note that when idle mode is terminated by a hardware reset, the device normally resumesprogram execution from where it left off, up to two machine cycles before the internalreset algorithm takes control. On-chip hardware inhibits access to internal RAM in thisevent, but access to the port pins is not inhibited. To eliminate the possibility of anunexpected write to a port pin when idle mode is terminated by a reset, the instructionfollowing the one that invokes idle mode should not write to a port pin or to externalmemory.Power-down ModeIn the Power-down mode, the oscillator is stopped, and the instruction that invokesPower-down is the last instruction executed. The on-chip RAM and Special FunctionRegisters retain their values until the Power-down mode is terminated. Exit from Powerdown mode can be initiated either by a hardware reset or by an enabled external interrupt.Reset redefines the SFRs but does not change the on-chip RAM. The reset should not beactivated before VCC is restored to its normal operating level and must be held activelong enough to allow the oscillator to restart and stabilize. Status of External Pins During Idle and Power-down ModesProgram Memory Lock Bits
The AT89S52 has three lock bits that can be left un programmed (U) or can beprogrammed (P) to obtain the additional features listed in the table. Lock Bit Protection ModesWhen lock bit 1 is programmed, the logic level at the EA pin is sampled and latchedduring reset. If the device is powered up without a reset, the latch initializes to a randomvalue and holds that value until reset is activated. The latched value of EA must agreewith the current logic level at that pin in order for the device to function properly.Programming the Flash – Parallel ModeThe AT89S52 is shipped with the on-chip Flash memory array ready to be programmed.The programming interface needs a high-voltage (12-volt) program enable signal and iscompatible with conventional third-party Flash or EPROM programmers.The AT89S52 code memory array is programmed byte-by-byte.Programming Algorithm:Before programming the AT89S52, the address, data, and control signals should be set upaccording to the “Flash Programming Modes”. To program the AT89S52, take thefollowing steps:1. Input the desired memory location on the address lines.2. Input the appropriate data byte on the data lines.3. Activate the correct combination of control signals.4. Raise EA/VPP to 12V.5. Pulse ALE/PROG once to program a byte in the Flash array or the lock bits. The bytewrite cycle is self-timed and typically takes no more than 50 µs. Repeat steps 1 through
5, changing the address and data for the entire array or until the end of the object file isreached.Data Polling:The AT89S52 features Data Polling to indicate the end of a byte write cycle. During awrite cycle, an attempted read of the last byte written will result in the complement of thewritten data on P0.7. Once the write cycle has been completed, true data is valid on alloutputs, and the next cycle may begin. Data Polling may begin any time after a writecycle has been initiated.Ready/Busy:The progress of byte programming can also be monitored by the RDY/BSY output signal.P3.0 is pulled low after ALE goes high during programming to indicate BUSY. P3.0 ispulled high again when programming is done to indicate READY.Program Verify:If lock bits LB1 and LB2 have not been programmed, the programmed code data can beread back via the address and data lines for verification. The status of the individual lockbits can be verified directly by reading them back.Reading the Signature Bytes:The signature bytes are read by the same procedure as a normal verification of locations000H, 100H, and 200H, except that P3.6 and P3.7 must be pulled to a logic low. Thevalues returned are as follows.(000H) = 1EH indicates manufactured by Atmel(100H) = 52H indicates AT89S52(200H) = 06HChip Erase:
In the parallel programming mode, a chip erase operation is initiated by using the propercombination of control signals and by pulsing ALE/PROG low for a duration of 200 ns -500 ns.In the serial programming mode, a chip erase operation is initiated by issuing the ChipErase instruction. In this mode, chip erase is self-timed and takes about 500 ms. Duringchip erase, a serial read from any address location will return 00H at the data output.Programming the Flash – Serial ModeThe Code memory array can be programmed using the serial ISP interface while RST ispulled to VCC. The serial interface consists of pins SCK, MOSI (input) and MISO(output). After RST is set high, the Programming Enable instruction needs to be executedfirst before other operations can be executed. Before a reprogramming sequence canoccur, a Chip Erase operation is required.The Chip Erase operation turns the content of every memory location in the Code arrayinto FFH. Either an external system clock can be supplied at pin XTAL1 or a crystalneeds to be connected across pins XTAL1 and XTAL2. The maximum serial clock(SCK) frequency should be less than 1/16 of the crystal frequency. With a 33 MHzoscillator clock, the maximum SCK frequency is 2 MHz.Serial Programming AlgorithmTo program and verify the AT89S52 in the serial programming mode, the followingsequence is recommended:1. Power-up sequence: a. Apply power between VCC and GND pins. b. Set RST pin to “H”.
If a crystal is not connected across pins XTAL1 and XTAL2, apply a 3 MHz to 33 MHzclock to XTAL1 pin and wait for at least 10 milliseconds.2. Enable serial programming by sending the Programming Enable serialinstruction to pin MOSI/P1.5. The frequency of the shift clock supplied at pinSCK/P1.7 needs to be less than the CPU clock at XTAL1 divided by 16.3. The Code array is programmed one byte at a time in either the Byte or Page mode. Thewrite cycle is self-timed and typically takes less than 0.5 ms at 5V.4. Any memory location can be verified by using the Read instruction which returns thecontent at the selected address at serial output MISO/P1.6.5. At the end of a programming session, RST can be set low to commence normal deviceoperation.Power-off sequence (if needed): 1. Set XTAL1 to “L” (if a crystal is not used). 2. Set RST to “L”. 3. Turn VCC power off.Data Polling:The Data Polling feature is also available in the serial mode. In this mode, during a writecycle an attempted read of the last byte written will result in the complement of the MSBof the serial output byte on MISO.Serial Programming Instruction SetThe Instruction Set for Serial Programming follows a 4-byte protocol and is shown in thetable given below.
Serial Programming Instruction SetProgramming Interface – Parallel ModeEvery code byte in the Flash array can be programmed by using the appropriatecombination of control signals. The write operation cycle is self-timed and once initiated,will automatically time itself to completion.
After Reset signal is high, SCK should be low for at least 64 system clocks before it goeshigh to clock in the enable data bytes. No pulsing of Reset signal is necessary. SCKshould be no faster than 1/16 of the system clock at XTAL1.For Page Read/Write, the data always starts from byte 0 to 255. After the command byteand upper address byte are latched, each byte thereafter is treated as data until all 256bytes are shifted in/out. Then the next instruction will be ready to be decoded.
Switches and PushbuttonsThere is nothing simpler than this! This is the simplest way of controlling appearance ofsome voltage on microcontroller’s input pin. There is also no need for additionalexplanation of how these components operate.Nevertheless, it is not so simple in practice... This is about something commonlyunnoticeable when using these components in everyday life. It is about contact bounce- acommon problem with m e c h a n i c a l switches. If contact switching does not happenso quickly, several consecutive bounces can be noticed prior to maintain stable state. Thereasons for this are: vibrations, slight rough spots and dirt. Anyway, whole this processdoes not last long (a few micro- or miliseconds), but long enough to be registered by themicrocontroller. Concerning pulse counter, error occurs in almost 100% of cases!
The simplest solution is to connect simple RC circuit which will “suppress” each quickvoltage change. Since the bouncing time is not defined, the values of elements are notstrictly determined. In the most cases, the values shown on figure are sufficient.If complete safety is needed, radical measures should be taken! The circuit, shown on thefigure (RS flip-flop), changes logic state on its output with the first pulse triggered bycontact bounce. Even though this is more expensive solution (SPDT switch), the problemis definitely resolved! Besides, since the condensator is not used, very short pulses can bealso registered in this way. In addition to these hardware solutions, a simple softwaresolution is commonly applied too: when a program tests the state of some input pin andfinds changes, the check should be done one more time after certain time delay. If thechange is confirmed it means that switch (or pushbutton) has changed its position. Theadvantages of such solution are obvious: it is free of charge, effects of disturbances areeliminated too and it can be adjusted to the worst-quality contacts.AUTO DIALER:The very simplest working telephone would look like this inside:
As you can see, it only contains three parts and they are all simple: • A switch to connect and disconnect the phone from the network - This switch is generally called the hook switch. It connects when you lift the handset. • A speaker - This is generally a little 50-cent, 8-ohm speaker of some sort. • A microphone - In the past, telephone microphones have been as simple as carbon granules compressed between two thin metal plates. Sound waves from your voice compress and decompress the granules, changing the resistance of the granules and modulating the current flowing through the microphone.Most people find that annoying, so any "real" phone contains a device called a duplexcoil or something functionally equivalent to block the sound of your own voice fromreaching your ear. A modern telephone also includes a bell so it can ring and a touch-tone keypad and frequency generator. A "real" phone looks like this:
A "real" telephoneStill, its pretty simple. In a modern phone there is an electronic microphone, amplifierand circuit to replace the carbon granules and loading coil. The mechanical bell is oftenreplaced by a speaker and a circuit to generate a pleasant ringing tone.Here in our project we will be replacing the HOOK SWITCH with a RELAY so that theswitching can be controlled with the microcontroller itself. That is nothing but we areconnecting to the telephone line when ever we want by just activating that relay.Redial: The telephone stores in memory the last number you called. The number will remainin the Redial memory until you dial another number.To dial the same number again 1. Lift the handset or press your telephones Hands free button. 2. Listen for the dial tone, and press Redial. This is done manually but as we want all this to be done automatically we will bereplacing the redial button with another RELAY. Here we are using two relays for
controlling the ON and OFF of the phone and for redialing. So now every thing isautomatic as the relays are being controlled by the microcontroller itself.RELAYS: A relay is an electrically controllable switch widely used in industrial controls,automobiles and appliances.The relay allows the isolation of two separate sections of a system with two differentvoltage sources i.e., a small amount of voltage/current on one side can handle a largeamount of voltage/current on the other side but there is no chance that these two voltagesmix up. Inductor Fig: Circuit symbol of a relayOperation:
When current flows through the coil, a magnetic field is created around the coili.e., the coil is energized. This causes the armature to be attracted to the coil. Thearmature’s contact acts like a switch and closes or opens the circuit. When the coil is notenergized, a spring pulls the armature to its normal state of open or closed. There are alltypes of relays for all kinds of applications. Fig: Relay Operation and use of protection diodes Transistors and ICs must be protected from the brief high voltage spike producedwhen the relay coil is switched off. The above diagram shows how a signal diode (eg1N4148) is connected across the relay coil to provide this protection. The diode isconnected backwards so that it will normally not conduct. Conduction occurs only whenthe relay coil is switched off, at this moment the current tries to flow continuouslythrough the coil and it is safely diverted through the diode. Without the diode no currentcould flow and the coil would produce a damaging high voltage spike in its attempt tokeep the current flowing.In choosing a relay, the following characteristics need to be considered:
1. The contacts can be normally open (NO) or normally closed (NC). In the NC type, thecontacts are closed when the coil is not energized. In the NO type, the contacts are closedwhen the coil is energized.2. There can be one or more contacts. i.e., different types like SPST (single pole singlethrow), SPDT (single pole double throw) and DPDT (double pole double throw) relays.3. The voltage and current required to energize the coil. The voltage can vary from a fewvolts to 50 volts, while the current can be from a few milliamps to 20milliamps. The relayhas a minimum voltage, below which the coil will not be energized. This minimumvoltage is called the “pull-in” voltage.4. The minimum DC/AC voltage and current that can be handled by the contacts. This isin the range of a few volts to hundreds of volts, while the current can be from a few ampsto 40A or more, depending on the relay.SENSOR BOARD:The different sensors used in this project are as follows: 1. REED SWITCHES or MAGNETIC SENSORS 2. LED & LDR section 3. TEMPERATURE SENSOR 4. PANIC SWITCH 5. IR tx AND IR rx.Let us see the description of each sensor.
REED SWITCHES OR MAGNETIC SENSORS:The reed switch is an electrical switch operated by an applied magnetic field. The basicreed switch consists of two identical flattened ferromagnetic reeds, sealed in a dry inert-gas atmosphere within a glass capsule, thereby protecting the contact fromcontamination. The reeds are sealed in the capsule in such a way that their free endsoverlap and are separated by a small air gap. Fig: Reed SwitchThe contacts may be normally open, closing when a magnetic field is present, ornormally closed and opening when a magnetic field is applied.A magnetic field from an electromagnet or a permanent magnet will cause the contacts topull together, thus completing an electrical circuit. The stiffness of the reeds causes themto separate, and open the circuit, when the magnetic field ceases. Good electrical contactis assured by plating a thin layer of precious metal over the flat contact portions of thereeds.Since the contacts of the reed switch are sealed away from the atmosphere, they areprotected against atmospheric corrosion. The hermetic sealing of a reed switch makes
them suitable for use in explosive atmospheres where tiny sparks from conventionalswitches would constitute a hazard.REED SENSOR:A reed sensor is a device built using a reed switch with additional functionality likeability to withstand higher shock, easier mounting, additional intelligent circuitry, etc.In production, a metal reed is inserted in each end of a glass tube and the end of the tubeheated so that it seals around a shank portion on the reed. Infrared-absorbing glass isused, so an infrared heat source can concentrate the heat in the small sealing zone of theglass tube. The thermal coefficient of expansion of the glass material and metal partsmust be similar to prevent breaking the glass-to-metal seal. The glass used must have ahigh electrical resistance and must not contain volatile components such as lead oxideand fluorides. The leads of the switch must be handled carefully to prevent breaking theglass envelope.How does a reed switch work?When a magnetic force is generated parallel to the reed switch, the reeds become fluxcarriers in the magnetic circuit. The overlapping ends of the reeds become oppositemagnetic poles, which attract each other. If the magnetic force between the poles isstrong enough to overcome the restoring force of the reeds, the reeds will be drawntogether.One important quality of the switch is its sensitivity, the amount of magnetic energynecessary to actuate it. Sensitivity is measured in units of Ampere-turns, corresponding tothe current in a coil multiplied by the number of turns. Typical pull-in sensitivities forcommercial devices are in the 10 to 60 AT range.
Uses:Reed switches are widely used for electrical circuit control, particularly in thecommunications field. Reed switches are commonly used in mechanical systems asproximity switches as well as in door and window sensors in burglar alarm systems andtamper proofing methods. These were formerly used in the keyboards for computerterminals, where each key had a magnet and a reed switch actuated by depressing thekey. Speed sensors on bicycles use a reed switch to detect when the magnet on the wheelpasses the sensor.Advantages: 1. They are hermetically sealed in glass environment. 2. Free from contamination, and are safe to use in harsh industrial and explosive environments. 3. Reed switches are immune to electrostatic discharge (ESD) and do not require any external ESD protection circuits. The isolation resistance between the contacts is as high as 1015 ohms, and contact resistance is as low as 50 milliohms. 4. They can directly switch loads as low as a few microwatts without the help of external amplification circuits, to as high as 120W. 5. When the reed switches are combined with magnets and coils, they can be used to form many different types of relays.The arrangement of the reed switch in our project is as shown in the figure above. Wewill be using two reed switches, one at the door and other at the window.
LED AND LDR SECTION:LDR:LDRs or Light Dependent Resistors are very useful especially in light/dark sensorcircuits. Normally the resistance of an LDR is very high, sometimes as high as 1000 000ohms, but when they are illuminated with light resistance drops dramatically.
When the light level is low the resistance of the LDR is high. This prevents current fromflowing to the base of the transistors. Consequently the LED does not light.However, when light shines onto the LDR its resistance falls and current flows into thebase of the first transistor and then the second transistor. The LED lights.Here in our project to avoid the light from led to fall on to LDR we place a box in whichwe will keep our jewelry. If any one removes the box the light from led falls directly onto the LDR and then the transistor will be on which is monitored by the microcontroller.Temperature Sensor:A sensor can be defined as a device which can convert one form of energy into electricalenergy. Here we are using a sensor to sense the temperature around us. For this purposewe will be taking help of LM 35 which is a temperature sensor.LM35:The LM35 series are precision integrated-circuit temperature sensors, whose outputvoltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thushas an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not
required to subtract a large constant voltage from its output to obtain convenientCentigrade scaling. The LM35 does not require any external calibration or trimming toprovide typical accuracies of ±1⁄4°C at room temperature and ±3⁄4°C over a full −55 to+150°C temperature range. Low cost is assured by trimming and calibration at the waferlevel. The LM35’s low output impedance, linear output, and precise inherent calibrationmake interfacing to readout or control circuitry especially easy. It can be used with singlepower supplies, or with plus and minus supplies. As it draws only 60 μA from its supply,it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate overa −55° to +150°C temperature range.Features • Calibrated directly in ° Celsius (Centigrade) • Linear + 10.0 mV/°C scale factor • 0.5°C accuracy guarantee able (at +25°C) • Rated for full −55° to +150°C range • Suitable for remote applications • Low cost due to wafer-level trimming • Operates from 4 to 30 volts • Less than 60 μA current drain • Low self-heating, 0.08°C in still air • Nonlinearity only ±1⁄4°C typical • Low impedance output, 0.1 W for 1 mA load.Typical Applications
The arrangement of this sensor in our board is as shown in the figure below.In this we directly connect the output of the sensor to the base of the transistor as ofLM35 for every 1˚C rise of temperature the output will increase for 10mV. Now if thetemperature reaches 70˚C the output voltage will be 0.7V which is enough for thetransistor junction to be biased. Hence the transistor gets on and the output is sensed bythe microcontroller.Panic Switch:This is nothing but a simple switch which is connected in the sensor board. Thearrangement of this is as shown in the figure below.
The response of this switch is monitored by the microcontroller and the correspondingaction takes place.IR Section:IR Tx.:TSAL6200 is a high efficiency infrared emitting diode in GaAlAs on GaAs technology,molded in clear, bluegrey tinted plastic packages. In comparison with the standard GaAson GaAs technology these emitters achieve more than 100 % radiant power improvementat a similar wavelength. The forward voltages at low current and at high pulse currentroughly correspond to the low values of the standard technology. Therefore these emittersare ideally suitable as high performance replacements of standard emitters.Features• Extra high radiant power and radiant intensity• High reliability• Low forward voltage• Suitable for high pulse current operation• Standard T-1¾ (∅ 5 mm) package• Angle of half intensity ϕ = ± 17°• Peak wavelength λp = 940 nm• Good spectral matching to Si photodetectorsApplications
Infrared remote control units with high power requirementsFree air transmission systemsInfrared source for optical counters and card readersIR source for smoke detectors. Most photo-detecting modules for industrial use are using modulated light toavoid interference by the ambient light. The detected signal is filtered with a band passfilter and disused signals are filtered out. Therefore, only the modulated signal from thelight emitter can be detected. Of course, the detector must not be saturated by ambientlight because it is effective when the detector is working in its linear region.
In this project, pulsed light is used to cancel ambient light. This is suitable forarrayed sensors that are scanned in sequence to avoid interference from the next sensor.The microcontroller starts to scan the sensor status, sample the output voltage, turns onthe LED and samples again the output voltage. The difference between the two samplesis the optical current created by the LED, as the output voltage produced by the ambientlight is canceled. The other sensors are also scanned the same way in sequence.The IR TX and RX are placed adjacent to each other. The TX transmits the IR radiationcontinuously and these will pass away when there is no object interrupting the signal. TheIR receiver does not receive the IR radiation in this case. When there is an obstacle orwhen some one interrupts the IR signal, the rays transmitted by the IR transmitter will getreflected back and these reflected rays will be received by the IR receiver. Thus, the IRreceiver receives the signal now in this case. The microcontroller detects this change anddoes the necessary action.DRIVER CIRCUIT: Digital systems and microcontroller pins lack sufficient current to drive thecircuits like relays, buzzer circuits etc. While these circuits require around 10milli ampsto be operated, the microcontroller’s pin can provide a maximum of 1-2milli ampscurrent. For this reason, a driver such as a power transistor is placed in between themicrocontroller and the buzzer circuit.
Vcc BUZZER AT89S52 GROUND P1.0The operation of this circuit is as follows:The input to the base of the transistor is applied from the microcontroller port pin P1.0.The transistor will be switched on when the base to emitter voltage is greater than 0.7V(cut-in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1(>0.7V), the transistor will be switched on and thus the buzzer will be ON.When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in offstate and the buzzer will be OFF. Thus the transistor acts like a current driver to operatethe buzzer accordingly.
BUZZER INTERFACING WITH THE MICROCONTROLLER: DRIVER BUZZER AT 89s52 CIRCUIT P1.0
WORKING PROCEDURE:This is a stand alone project to provide security to industries using an advancedtechnology called embedded systems. In this we are providing security by taking 5different sensors. They are namely: 1. Reed sensor 2. LED & LDR 3. Temperature Sensor 4. Panic Switch 5. IR Tx & IR Rx.The working of all these sensors will start only when the arm key which is connected tothe main board is made on.Here we will be using Reed switches at two different places viz. At doors and atwindows. When using at doors we have two conditions to be checked, they are, whetherthe person is leaving outside or coming inside.The microcontroller continuously checks all the sensors. When this door sensor istriggered, it waits for a small amount of time allowing the person to close or open thedoor within that predefined delay. If the user closes or opens the door within the givendelay, the controller will not ring the buzzer or the alarm and will wait again for anothersensor to be activated. If the user can’t close or open the door in the given time, thecontroller will enter into the next case which is called as the entry delay.Another reed sensor is placed at the window. If the window is opened then the buzzer isactivated and then the auto-dialer action is performed.
After this comes the LED & LDR section. In this we will be placing all important thingsin a box and place that box on the LDR such that it objects the light falling from the LED.If any one removes the box the light falls on the ldr and then the microcontroller detects itand the buzzer will be activated and then the auto-dialer.The next sensor is Temperature sensor. This sensor gets activated only when thetemperature in the room exceeds 70 degrees. This is because of the hardware connectionswe have made. When this sensor is activated the buzzer followed by auto-dialer is alsoactivated.The next one is the panic switch. This can be activated by pressing this switch which willlead to the activation of buzzer and auto-dialer.Next comes the IR section. This contains a IR Tx. and IR Rx. This is arranged in such amanner that the IR signal falls continuously on the IR Rx. When ever an obstacle ispassed through this pair this sensor gets activated. When this sensor is activated the alarmis on and auto-dialer is activated.The final sensor is the Smoke detector. Internally this has a pair of IR Tx. and Rx. Thissensor is activated when there is a fire accident which results in smoke. This smoke isdetected by this sensor and then the buzzer is activated followed by auto-dialer.