Sunteți pe pagina 1din 56

HOME AUTOMATION THROUGH WIRELESS INFRA RED REMOTE

In this project we show that how we provide a complete automation in any home with the help of TV remote. With the help of TV remote we not only switch on/off the electrical appliances but at the same time we can control the speed/ intensity the AC load. In this project we use one Atmel base microcontroller to provide a automation. We use two seven segment display to display the speed level of Ac load. In this project we provide two outputs for load variations. Two output is connected through Triac control circuit. In this project we use two Triac for two loads. Separate seven segments for separate load. We provide manual input for this controller to vary the intensity of load. We use two on/off and two increment and decrement switch to vary the speed. Four electromagnetic relay to provide a on off of electrical load. Four separate switches are connected with the controller to provide a on/off signal. Zero cross over signal is provided to the controller via Opto-coupler circuit to pin no 13 of the circuit . Infra red eye ( remote sensor) is connected to the pin no 12 of the controller . Signal from the remote is targeted to the sensor and sensor provide a signal to the controller . With the help of this signal we not only provide a on/off signal but at the same time we vary the intensity of the two load separately

COMPONENTS USED MICROCONTROLLER = 89S52. MOC 3021= OPTO-COUPLER FOR TRIAC DRIVER( 2) PC 817 OPTOCOUPLER FOR ZERO CROSS OVER INPUT TSOP 1738 FOR REMOTE SENSOR(1) SEVEN SEGMENT DISPLAY COMMON ANODE (2) ELECTROMAGNETIC RELAY (4) NPN TRANSISTOR (4) PNP TRANSISITOR(6) DIODE= IN 4007(8) 7805 REGULATOR PUSH TO ON SWITCHES (10) TRIAC BT 136 (2) CRYSTAL 12 Mhtz RESISTOR: 10K (4) 1K (10) 470 OHM (10) 100 OHM (10)

Triac is a power electronic component that conducts in both directions when triggered through gate. .As it can be seen that at time t1, angle of sinusoid is 45' which means that if we triggered Triac at this angle i-e at 45', only shaded blue area will pass through the Triac and hence through the load. Observe that shaded blue are has RMS Voltage less than the pure sinusoid. This is the basic principle by which RMS Voltage control is accomplished. Firing needs a small pulse at gate that can be give through microcontroller also. Similarly at firing angle 90' (firing angle is an angle with reference zero crossing at which the Triac is triggered using gate pulse) , only red part of sinusoid will pass through the Triac giving us the RMS 110V for 220V.

Coutesy of Motrola,Inc

MOC3021 is an optotriac (product of Motorola) that is used for isolation between power and driving circuitry. Note that when C828 on the base is applied voltage>0.7V, optotriac gets triggered. As the triac gets triggered now, the positive or negative voltage (whatever maybe) get pass through the gate of BT136 (triac) and hence triggered it. It should be noted here that by using above arrangement we can control the RMS voltage in both directions. What needs to be taken care of, is the triggering time or firing angle.
7

There is a need of a zero-crossing detector that will give us the reference for providing delay for desired firing angle. In above example, for firing angle to be 90' for 220V 50Hz AC signal, we need to have a delay of 2.5 ms (t1=2.5ms) right after each zero crossing. Usually MOC3021 is driven through microcontroller, which gives the firing pulse on the basis of interrupt generated by the zero-crossing detector.

The above circuit is mainly used as a dimmer and is often used speed controlling of AC motor. There are other versions of the
8

above circuits available that caters for the inductive load which will be discussed later.

HARDWARE DESCRIPTION
In infra red receiver we again we use one microcontroller 2051. Pin no 20 is connected to the positive supply. Crystal is connected to the pin no 4 and 5. Complete circuit is work on 5 volt regulated power supply. For this purpose we use one step down transformer, two diode and on capacitor circuit. After capacitor we use one 5 volt regulator circuit. Output of the regulator is connected to the 2051 regulator circuit. . Infra red eye is connected to the external interrupt pin no p3.2. One point of the infra red eye is connected to the positive supply. One pin is for the signal and third pin is ground. When any signal is coming on the infra red eye then infra red eye sense the signal and this signal give a interrupt to the p3.2. One ac signal is also provided to the pin no p3.3 to give zero crossing action. For this purpose we use one full wave rectifier and this pulsating dc is provided to the optocoupler. Optocupler convert this signal into opposite direction and the same time give a optical isolation to this pin. Optocoupler is a combination of one infra red transmitter and one phototransistor. Output of the phototransistor is connected to the external interrupt no 1. There is a two external interrupt in this microcontroller. In this microcontroller one is connected to the infra red eye and second is connected to the zero crossing ac voltage. Output pin s of the microcontroller is connected to the port p1. Note that output of the microcontroller is active low, so to drive the transistor and relay coil we use one inverter ic. There is a four output for the four on/off signal.

10

P1.1, P1.1, P1.2, P1.3 is connected to the inverter ic 4049. This inverter ic is hex inverter ic. We use four output of the inverter ic to the base of the npn transistor through 470 ohm resistor. Emitter of the NPN transistor is connected to the forward bias. Collector is reverse bias through the Relay coil. When we send the on/off signal from the remote then from this signal output of the microcontroller is zero and this output is inverted by the ic 4049 and further switch on the transistor and relay coil. One reverse bias diode is connected between relay to protect the transistor when relay off and send a back emf to the transistor. Six more switches are connected to the circuit to on/off and control the speed of the fan. Firstly we on the switch when the microcontroller send the fan on signal then p1.6 p1.7 pins and low and output led is also on. Note that led is connected in reverse bias on this pin. P1.4 and P1.5 are connected to two rest pins of the IC 4049. Output available on the p1.5 and p1.6 is inverted by the inverter ic and this output is connected to the pin no 2 of the opto triac. This opto triac is a very special triac. By this triac we control the firing angle of the triac. Pin no 4 and 6 are connected to the triac through load. We control the brightness of the triac through the pulse train of the pulse width modulation. As we as we press the up or down key. New pulse width is available on the output. By this output we compare with the zero crossing action and by the result we control the brightness of the lamp or speed of the fan. Pulse width modulation is the most important part of this project to control the speed of the fan or control the brightness of the lamp.

11

BASICS OF MOTION CONTROL : Definitions of motion control vary widely in industry today. Depending on the application, motion control can refer to simple on/off control or a sequencing of events, controlling the speed of a motor, moving objects from one point to another or precisely constraining the speed, acceleration, and position of a system throughout a move. Varying interpretations used in the field may confuse engineers working for the first time in some aspect of motion control. Motion control means different things to different sections of industry. As an introduction, this chapter differentiates among motion control techniques. It puts each technique into perspective in terms of where typical applications arise. In many cases, motion control techniques are intimately tied to the controller as well as to the positioning hardware and actuator. No overview of motion control would be complete without a discussion of the various control options that are widely used. These include simple timers and counters, chip level and board level computers, programmable logic controllers, and pneumatic sequencers. BASIC TYPES : Industrial motion control can be divided into four categories: sequencing, speed control, point to point control, and incremental motion: Sequencing refers to the control of several operations so that they all occur in a particular order. Perhaps the simplest example of sequential motion is the progression of events that take place through the mechanical linkages of a player piano. When a player piano plays a tune, holes in a paper roll cause piano wires to be struck in a

12

specific sequence. Similarly, opening and closing valves can be sequenced mechanically with camshafts. Sequencing generally becomes too complicated to be handled mechanically in industrial equipment such as conveyor lines, or process machines such as fryers in fast food restaurants. The key factor that defines these as sequencing applications is a need for move and stop on and off control of events that must take place in a certain progression. Soak time or the position of material on an assembly line determine when operations should start and stop. For example, consider a conveyor line that moves parts from one assembly station to another. The controller might position a part at one station until an operator punches an advance button. This might start the part moving to the next station. Here it might enter a cleaning bath for a programmed soak time. At the end of this period, it might move to a new station for final assembly, and so forth. This sort of timing and sequencing is handled through pneumatic, electronic, or electromechanical controllers. Of these, electronic and electromechanical controls are most common. For simple on off control, timers and counters may suffice. These devices contain electrical contacts that can be opened and closed at time intervals that an operator either enters on a keypad or sets with switches. Counters are similar devices that actuate contacts when a count reaches a preset number. The count increments or decrements when sensors such as proximity switches or limit switches sense an object. When a sequencing operation consists of more than a few steps, more elaborate controls become necessary. These controls can take the form of discrete elements such as time delay relays that act in response to input signals from sensors and switches.
13

Over the past two decades, use of numerous relays for sequencing has increasingly given way to programmable logic controllers (PLCs). PLCs contain computers that synthesize actions such as timing and counting to sequence operations. The advantage PLCs have over banks of relays is that a PLC can be simply reprogrammed to provide different sequences and different timing intervals. In contrast, changes made to sequences controlled only by relays may require physical rewiring and reconfiguring, a process that can be time consuming and expensive. Speed control refers to applications involving machines run at varying speeds or torques. The source of power for such applications is generally either an internal combustion engine, or an electric, hydraulic, or pneumatic motor. Speed can be controlled either mechanically or, in the case of electric motors electronically. In contrast to mechanical speed control technology, which usually employs gearing or belts to change speed, electronic speed control manipulates applied electrical power to control velocity and torque. Electronic speed control in ac motors employ special amplifiers or drives. These generally vary ac motor speed. Though such electronic controls are more expensive than mechanical speed controls, they provide the advantage of reduced energy costs. Applications for such equipment include fans, blowers, pumps and compressors. Point to point motion control, in contrast with velocity control, generally refers to applications where something must move from one point to another at a constant speed. An important requirement in such applications is that there are two factors that must be controlled speed and distance. Examples of point to point movement are in xy tables and in machining, where a tool moves in a straight line while it touches a workplace along one axis.
14

Because such applications demand monitoring and control of both velocity and position, they need a controller to keep track of system operating conditions at any given time. These controllers can be either hardwired electronic logic, and computer or a PLC. In general, the simplest positioning system of this sort might be found on older milling machines. These contain an x-y positioning system for moving the fixture holding the workplace. The positioning system involves ac or dc motors, an adjustable speed drive, clutch, and a position transducer that reads out the position of each table axis. The positioning mechanism for such a system is usually a ball screw.

HOW TO PROGRAM BLANK CHIP.


8051 micro controller
The 8051 The 8051 developed and launched in the early 80`s, is one of the most popular micro controller in use today. It has a reasonably large amount of built in ROM and RAM. In addition it has the ability to access external memory. The generic term `8x51` is used to define the device. The value of x defining the kind of ROM, i.e. x=0, indicates none, x=3, indicates mask ROM, x=7, indicates EPROM and x=9 indicates EEPROM or Flash.

Different micro controllers in market.

PIC One of the famous microcontrollers used in the industries. It is based on RISC Architecture which makes the microcontroller process faster than other microcontroller.

15

INTEL These are the first to manufacture microcontrollers. These are not as sophisticated other microcontrollers but still the easiest one to learn. ATMEL Atmels AVR microcontrollers are one of the most powerful in the embedded industry. This is the only microcontroller having 1kb of ram even the entry stage. But it is unfortunate that in India we are unable to find this kind of microcontroller.

Intel 8051 Intel 8051 is CISC architecture which is easy to program in assembly language and also has a good support for High level languages. The memory of the microcontroller can be extended up to 64k. This microcontroller is one of the easiest microcontrollers to learn. The 8051 microcontroller is in the field for more than 20 years. There are lots of books and study materials are readily available for 8051.

First of all we select and open the assembler and wrote a program code in the file. After wrote a software we assemble the software by using internal assembler of the 8051 editor. If there is no error then assembler assemble the software abd 0 error is show the output window.

16

now assembler generate a ASM file and HEX file. This hex file is useful for us to program the blank chip. Now we transfer the hex code into the blank chip with the help of serial programmer kit. In the programmer we insert a blank chip 0f 89s51 series . these chips are multi time programmable chip. This programming kit is seperatally available in the market and we transfer the hex code into blank chip with the help of the serial programmer kit

17

18

19

20

AT89C52 8-bit Microcontroller with 8K Bytes Flash


Features Compatible with MCS-51 Products 8K Bytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz Three-level Program Memory Lock 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Eight Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes Description The AT89C52 is a low-power, high-performance CMOS 8-bit microcomputer with 8K bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmels highdensity nonvolatile memory technology and is compatible with the industrystandard 80C51 and 80C52 instruction set and pinout. 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 Flash on a monolithic chip, the Atmel AT89C52 is a powerful microcomputer which provides a highly-flexible and cost-effective solution to many embedded control applications.

21

22

23

The AT89C52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, three 16-bit timer/counters, a sixvector two-level interrupt architecture, full-duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89C52 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 the RAM contents but freezes the oscillator, disabling all other chip functions until the next hardware reset.

Pin Description
VCC Supply voltage. GND Ground. Port 0 Port 0 is an 8-bit open drain bi-directional 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 highimpedance inputs. Port 0 can also be configured to be the multiplexed loworder address/data bus during accesses to external program and data memory. In this mode, P0 has internal pullups.

24

Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pullups are required during program verification. Port 1 Port 1 is an 8-bit bi-directional 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, as shown in the following table. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2 Port 2 is an 8-bit bi-directional 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.

25

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 pullups 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. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification. Port 3 Port 3 is an 8-bit bi-directional 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 AT89C51, as shown in the following table. Port 3 also receives some control signals for Flash programming and verification.

RST
26

Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. ALE/PROG Address Latch Enable 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 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 ALEdisable bit has no effect if the microcontroller is in external execution mode.

PSEN
Program Store Enable is the read strobe to external program memory. When the AT89C52 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.

27

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 when 12-volt programming is selected. XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2 Output from the inverting oscillator amplifier.

28

Special Function Registers

A map of the on-chip memory area called the Special Function Register (SFR) space is shown in Table 1. 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 (shown in Table 2) and T2MOD (shown in Table 4) for Timer 2.
29

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.

30

Data Memory
The AT89C52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the special Function Registers. That means 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 that use direct addressing access SFR space. For example, the following direct addressing instruction accesses the SFR at location 0A0H (which is P2). 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. Timer 0 and 1 Timer 0 and Timer 1 in the AT89C52 operate the same way as Timer 0 and Timer 1 in the AT89C51. 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 (shown in Table 2). 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, as shown in Table 3. Timer 2 consists of two 8-bit registers, TH2
31

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.

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 in the register 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-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.

Capture Mode
In 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 bit can then be used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1- to-0 transition at external input T2EX also causes the current value in TH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt. The capture mode is illustrated in Figure 1. 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
32

DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin.

Figure 2 shows Timer 2 automatically counting up when DCEN = 0. In this mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in 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 external input T2EX. This transition also sets the EXF2 bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled. Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 3. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2, respectively.

33

A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers. The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.

34

35

Baud Rate Generator


Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON (Table 2). Note that the baud rates for transmit and receive can be different if Timer 2 is used for the receiver or transmitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK puts Timer 2 into its baud rate generator mode, as shown in Figure 4. The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are preset by software. The baud rates in Modes 1 and 3 are determined by Timer 2s overflow rate according to the following equation.

The Timer can be configured for either timer or counter operation. In most applications, it is configured for timer operation (CP/T2 = 0). The timer operation is different for Timer 2 when it is used as a baud rate generator. Normally, as a timer, it increments every machine cycle (at 1/12 the oscillator frequency). As a baud rate generator, however, it increments every state time (at 1/2 the oscillator frequency). The baud rate formula is given below.

where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer. Timer 2 as a baud rate generator is shown in Figure 4. This figure is valid only if RCLK or TCLK = 1 in T2CON. Note that a rollover in TH2 does
36

not set TF2 and will not generate an interrupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX will set 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 external interrupt. 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. The RCAP2 registers may be read but should not be written to, because a write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or RCAP2 registers.

Programmable Clock Out

37

A 50% duty cycle clock can be programmed to come out on P1.0, as shown in Figure 5. This pin, besides being a regular I/O pin, has two alternate functions. It can be programmed to input the external clock for Timer/Counter 2 or to output a 50% duty cycle clock ranging from 61 Hz to 4 MHz at a 16 MHz operating frequency. To configure the Timer/Counter 2 as a clock generator, bit C/T2 (T2CON.1) must be cleared and bit T2OE (T2MOD.1) must be set. Bit TR2 (T2CON.2) starts and stops the timer. The clock-out frequency depends on the oscillator frequency and the reload value of 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 is similar to when Timer 2 is used as a baud-rate generator. It is possible to use Timer 2 as a baud-rate generator and a clock generator simultaneously. Note, however, that the baud-rate and clock-out frequencies cannot be determined independently from one another since they both use RCAP2H and RCAP2L. UART
The UART in the AT89C52 operates the same way as the UART in the AT89C51.

Interrupts The AT89C52 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. These interrupts are all shown in Figure 6. 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, which disables all interrupts at once. Note that Table shows that bit position IE.6 is unimplemented. In the AT89C51, bit position IE.5 is also unimplemented. User software should
38

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.

39

Oscillator Characteristics

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator, as shown in Figure 7. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven, as shown in Figure 8. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.
Idle Mode

In idle mode, the CPU puts itself to sleep while all the onchip peripherals remain active. The mode is invoked by software. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset. Note that when idle mode is terminated by a hardware reset, the device normally resumes program execution from where it left off, up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but access to the port pins is not inhibited. To eliminate the possibility of an unexpected write to a port pin when idle mode is terminated by a reset, the instruction following the one that invokes idle mode should not write to a port pin or to external memory.

40

Power-down Mode
In the power-down mode, the oscillator is stopped, and the instruction that invokes power-down is the last instruction executed. The on-chip RAM and Special Function Registers retain their values until the power-down mode is terminated. The only exit from power-down is a hardware reset. Reset redefines the SFRs but does not change the on-chip RAM. The reset should not be activated before VCC is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize.

41

Program Memory Lock Bits


The AT89C52 has three lock bits that can be left unprogrammed (U) or can be programmed (P) to obtain the additional features listed in the following table.

When lock bit 1 is programmed, the logic level at the EA pin is sampled and latched during reset. If the device is powered up without a
42

reset, the latch initializes to a random value and holds that value until reset is activated. The latched value of EA must agree with the current logic level at that pin in order for the device to function properly. Programming the Flash The AT89C52 is normally shipped with the on-chip Flash memory array in the erased state (that is, contents = FFH) and ready to be programmed. The programming interface accepts either a high-voltage (12volt) or a low-voltage (VCC) program enable signal. The Low-voltage programming mode provides a convenient way to program the AT89C52 inside the users system, while the high-voltage programming mode is compatible with conventional thirdparty Flash or EPROM programmers. The AT89C52 is shipped with either the high-voltage or low-voltage programming mode enabled. The respective top-side marking and device signature codes are listed in the following table.

The AT89C52 code memory array is programmed byte-bybyte in either programming mode. To program any nonblank byte in the on-chip Flash Memory, the entire memory must be erased using the Chip Erase Mode. Programming Algorithm Before programming the T89C52, the address, data and control signals should be set up according to the Flash programming mode table and Figure 9 and Figure 10. To program the AT89C52, take the following steps.
43

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 for the high-voltage programming mode. 5. Pulse ALE/PROG once to program a byte in the Flash array or the lock bits. The byte-write cycle is self-timed and typically takes no more than 1.5 ms. Repeat steps 1 through 5, changing the address and data for the entire array or until the end of the object file is reached.

Data Polling The AT89C52 features Data Polling to indicate the end of a write cycle. During a write cycle, an attempted read of the last byte written will result in the complement of the written data on PO.7. Once the write cycle has been completed, true data is valid on all outputs, and the next cycle may begin. Data Polling may begin any time after a write cycle has been initiated. Ready/Busy The progress of byte programming can also be monitored by the RDY/BSY output signal. P3.4 is pulled low after ALE goes high during programming to indicate BUSY. P3.4 is pulled 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 be read back via the address and data lines for verification. The lock bits cannot be verified directly. Verification of the lock bits is achieved by observing that their features are enabled. Chip Erase The entire Flash array is erased electrically by using the proper combination of control signals and by holding ALE/PROG low for 10 ms. The code array is written with all 1s. The chip erase operation must be executed before the code memory can be reprogrammed. Reading the Signature Bytes The signature bytes are read by the same procedure as a normal verification of locations 030H, 031H, and 032H,

44

except that P3.6 and P3.7 must be pulled to a logic low. The values returned are as follows. (030H) = 1EH indicates manufactured by Atmel (031H) = 52H indicates 89C52 (032H) = FFH indicates 12V programming (032H) = 05H indicates 5V programming Programming Interface
Every code byte in the Flash array can be written, and the entire array can be erased, by using the appropriate combination of control signals. The write operation cycle is selftimed and once initiated, will automatically time itself to completion.

All major programming vendors offer worldwide support for the Atmel microcontroller series. Please contact your local programming vendor for the appropriate software revision.

45

46

47

48

RELAYS In order to enable a circuit to be isolated from the system only under faulty conditions, protective relays are used. In normal cases, it is open circuit relay. The relay is usually provided with 4 terminals, two of which are connected to relay winding and other two are connected to the circuit to be controlled. It has following characteristics : Sensitivity Speed Selectivity

TYPES OF RELAYS :

Electromagnetic Attraction Type : These relays are actuated by DC or AC quantities. Electromagnetic Induction Type : Its operation depends upon EMI phenomena. Thermal Relays : Its operation depends upon the heating effect of electric Current. Distance Relays : Its operation depends upon the ratio of voltage to current.

ELECTROMAGNETIC RELAY :

49

These relays are electromagnetically operated. The parts of these relays are an iron core & its surrounding coil of wire. An iron yoke provides a low reluctance path for magnetic flux, the yoke being shaped so that the magnetic circuit can be closed by a movable piece of iron called the armature, and a set of contacts. The armature is hinged to the yoke and is held by a string in such a way that there is an air gap in the magnetic circuit. Figure shows the principle of operation of this relay. When an electric current flows in the coil, the armature is attracted to the iron core. Electrical switching contacts are mounted on the armature. When the armature coil is energized, these movable contacts break their connections with one set of fixed contacts and close a connection to a previously open contact. When electric power is removed from the relay coil, spring returns the armature to its original position. Standard voltages for D.C. relay are 6,12,24,48 & 110 volts and for A.C. relays are 6,12,24,48,120 & 240 volts.

Fig. Basic Diagram Showing the Operating Principle of a Relay

50

LIGHT EMITTING DIODE

Light emitting diode (LED) is basically a P-N junction semiconductor diode particularly designed to emit visible light. There are infrared emitting LEDs which emit invisible light. The LEDs are now available in many colours red, green and yellow. A normal LED emits at 2.4V and consumes MA of current. The LEDs are made in the form of flat tiny P-N junction enclosed in a semispherical dome made up of clear coloured epoxy resin. The dome of a LED acts as a lens and diffuser of light. The diameter of the base is less than a quarter of an inch. The actual diameter varies somewhat with different makes. The common circuit symbols for the LED are shown in Fig. It is similar to the conventional rectifier diode symbol with two arrows pointing out. There are two leadsone for anode and the other for cathode. LEDs often have leads of dissimilar length and the shorter one is the cathode. All manufacturers do not strictly adhere this to. Sometimes the cathode side has a flat base. If there is doubt, the polarity of the diode should be identified. A simple bench method is to use the ohmmeter incorporating 3-volt cells for ohmmeter function. When connected with the ohmmeter: one way there will be no deflection and when connected the other way round there will be a large deflection of a pointer. When this occurs the anode lead is connected to the negative of test lead and cathode to the positive test lead of the ohmmeter.

51

If low range (Rxl) of the ohmmeter is used the LED would light up in most cases because the low range of ohmmeter can pass sufficient current to light up the LED. Another safe method is to connect the test circuit shown in Fig. 2. Use any two dry cells in series with a current limiting resistor of 68 to 100 ohms. The resistor limits the forward diode current of the LED under test to a safe value. When the LED under test is connected to the test terminals in any way: if it does not light up, reverse the test leads. The LED will now light up. The anode of the LED is that which is connected to the A terminal (positive pole of the battery). This method is safe, as reverse voltage can never exceed 3 volts in this test.

ELECTRICAL CHARACTERISTICS OF LEDS: Electrically, a LED is similar to the conventional diode in that it has relatively low forward voltage threshold. Once this is exceeded the junction has a low slope resistance and conducts current readily. An external resistor must limit this current. Forward voltage drew across red LED is nominally 1.6 V but spread with commercial diodes, it may be as high as 2 volts or so, while the Green LED drops 2.4V. This difference accounts for use of lower limiting resistor used with the Green LED. Another important parameter of the LED is its maximum reverse voltage rating. For typical Red device it is of the order of 3 volts. But for Green LED it is somewhat higher- 5 to 10 volts. The LED produces light only when a d.c. current is passed in the forward direction and the amount of light emitted by a LED is proportional to the forward current over a broad range. It means that light intensity increases in an approximately linear manner with increasing current.

52

SEVEN DISPLAY:-

SEGMENT

DISPLAY

DECIMAL

A popular type consists of seven small, bar-shaped LED segment arranged so that depending on which combinations are energized, the numbers 0 to 9 light up. All the LED cathodes (or sometimes anodes) are joined to form a common connection. Current limiting resistors are required (e.g. 270 ohms), preferably one per segment. Common cathode method of connecting an array of display elements.

Anode Connection

The main requirements for a suitable LED material are:Common Cathode 1) 2) 3) It must have on energy gap of appropriate width. Both P and N types must exist, preferably with low resistivities. Efficient radioactive pathways must be present.

Generally, energy gaps greater than or equal to about 2 are required.


53

Commercial LED materials:: Gallium arsenide (Ga As) doped with Si Gallium Phosphide (GaP) doped with N & Bi Gallium arsenide Phosphide (Ga As1-x Px) Gallium aluminium arsenide (Gax Al1-x As)

LED CONSTRUCTIONS: To reduce reflection losses in LEDs there are two obvious ways: a) The first is to ensure that most rays strike the surface at less than the critical angle. This may be achieved by shaping the semiconductor /air interface into a hemisphere. The second technique is to encapsulate the junction in a transparent medium of high refractive index. This is usually a plastic material with refractive index of about 1.5. Moulding the plastic into an approximately hemispherical shape can minimize the losses at the plastic lair interface.

b)

54

55

56

S-ar putea să vă placă și