You are on page 1of 112

Overview Of Microcontroller

A microcontroller is an integrated chip that is often part of an embedded system. The microcontroller includes a CPU, RAM, ROM, I/O ports and timers like a standard computer but because they are designed to execute only a single specific task to control a single system, they are much smaller and simplified so that they can include all the functions required on a single chip. Early controllers were built from discrete components and they were large in size. Later microprocessors were build and microcontrollers were able to fit onto a circuit board. Microcontroller now places all of the needed components onto a single chip. With the advent of VLSI technology, microcontroller chip are becoming essentially single chip microcomputers. Microcontrollers collect data from the input devices, process the data and make decision based on the result of process. The input may be for sensing and measurement of some aspects of the environment and output may be generation of one or more control signals that effect the environment in a desirable manner. Input may be simple binary valued signal from switch, group of binary digits from ADC, serial data from computer, pulses from infrared receiver or signals from sensors. Output may be solenoid, relay, LCD, LED, indicators, Optodevices, motors etc. Assembly language is stored in either internal ROM or external ROM. Internal RAM is used for processing and temporary storage. Microcontrollers have become common in many areas, and can be found in variety of applications like intercom, telephones, mobiles, security system, door openers, curtain controller, answering machines, fax, television, CNC machines, washing machines, VCR/VCD, DVD players, remote controls, musical instruments, sewing machine, camera, Microwave ovens, laser printers computer equipments, instrumentation and many other home appliances. They are widely used in automobiles and have become a central part of industrial robotics. The microcontrollers is most essential IC for continuous process- based industries like chemical refinery, pharmaceuticals, steels, programmable logic control system(PLC) and distributed control system(DCS). Microcontrollers do not require significant processing power because they are usually used to control a single process and execute simple instructions. The automotive market has been a major driver of microcontrollers, many of which have been developed for automotive applications. Because of automotive microcontrollers have to 1

withstand harsh environmental conditions, they may be highly reliable and durable. Automotive microcontrollers, like their counterparts are very inexpensive and are able to deliver powerful features that would otherwise be impossible, or too costly to implement.

Brief History Of 89S52 Microcontroller Family:-

Intel Corporation introduced an 8 bit 8051 microcontroller in 1981. This microcontroller has 128 byte RAM, 4K bytes ROM, two timers one serial ports and four I/O ports on single chip.8051 is a 8 bit processor because CPU can work 8 bit data at a time. If data is larger then 8 bit, it has to be broken into pieces of 8 bit. Intel allowed other manufacturers to make flavors of 8051 with the condition that it should be code compatible with Intel 8051. There are 20 vendors like Philips, siemens; Dallas, OKI, Fujitsu, Atmel, etc. are building their own versions of the 8051.

Comparison Of Some 8051 Family.

Chip 8031 8032 8051 8052 8751 8752 89C51 89C52

ROM(bytes) --4K 8K 4K(EPROM) 8K(EPROM) 4K flash 8K flash

RAM(bytes) 128 256 128 256 128 256 128 256

Timers 2 3 2 3 2 3 2 3

I/O pins 32 32 32 32 32 32 32 32

89C1051 (20 pin) 89C2051 89S51

1K flash

64

15

2K flash 4K flash

128 128

2 2

15 40

Reasons For The Success Of Microcontroller:Microcontrollers have powerful, cleverly chosen electronics which is able to control a variety of processes and devices( industrial automatics, voltage, temperature, engines, etc) independently or by means of I/O instruments such as switches, buttons, sensors, LCD screens, relays. Etc. Their low cost makes them suitable for installing in places, which attracted no such interest in the past. This is the fast accountable for todays market being swamped with cheap automation and intelligent toys. Writing and loading a program into microcontroller is very easy. All that is required is; any PC (software is very friendly and intuitive) and one simple device (programmer) for loading a written program in microcontroller.

Block Diagram Of Microcontroller:-

A microcontroller is an integrated chip that is often part of an embedded system. The microcontroller includes a CPU, RAM, ROM, I/O ports and timers like a standard computer, but because they are designed to execute only a single specific task to control a single system, they are much smaller and simplified so that they can include all the functions required on a single chip. Simplified block diagram of the microcontroller is shown in figure1.

Fig 1: simplified block diagram of the microcontroller Microcontroller incorporates all features found in microprocessor Such as ALU, General purpose registers, accumulators, program counters, stack pointer, timing control unit, interrupts etc. In addition to these microcontrollers incorporates ROM, RAM, I/O, serial I/O, timers etc.

Parallel Serial Input-Output Port:-

Microcontroller contains parallel input output ports

to interface it with real world. For Example: 8051 contains 4 parallel input-output ports to interface with I/O devices. The 8085 microprocessor requires separate chips such as 8255 (programmable peripheral interface) to interface it with I/O devices. Microcontroller also has in built serial port. Serial communication with microcontroller is simpler.

Timers:

Microcontroller has inbuilt timers. 8051 has 2 16 bit timers. Timers provide

real time interrupt to the processor for specific events. It can be used as a counter to count number of events. Typical example is object counter. Interrupt is generated when count value overflows

ROM:

Microcontroller has inbuilt Read only memory (ROM) which is used to store

program code and data required during execution such as look up tables. 8051 microcontrollers has 4K-ROM, 8751 has 4K EPROM (erasable programmable read only memory), 89C51 has 4K flash memory. ROM is programmed during manufacturing process. EPROM can be programmed using EPROM programmer. It needs to erase 4

using ultraviolet eraser. 89C51 is very popular version of 8051 because it contains flash memory. It is ideal for fast development since flash memory can be erased and programmed in seconds. Erasing and programming can be done by microcontroller programmer unit itself.

RAM:

Microcontroller has inbuilt Random Access Memory. It is used to store

information for temporary use. CPU can write RAM as well as read it. Any information stored in the RAM is lost when power is switched off. 8031/8051has 128 bytes Ram while 8032/8052 has 256 byte of RAM.

General Microcontroller based System:-

Fig 2: general microcontroller based system

Microcontroller are dedicated to one task and run one specific program. The program is stored in ROM (read only memory) and generally does not change. Microcontroller often uses flash, EEPROM or EPROM as their storage device to allow field programmability so they are flexible to use. Once program is tested and found correct i.e. prototype is developed then OTP (one time programmable) microcontrollers can be used because they are chip. These are multiple architecture used in microcontrollers, the predominant architecture is CISC (complex instruction set computer), which allows the microcontroller to contain multiple control instructions that can be executed with a single macro instruction. Another is RISC (reduced instruction set computer ) architecture, which implements fewer instructions, but delivers greater simplicity and lower power consumption. A highly integrated chip that contains all the components comprising a controller. Typically this includes a CPU, RAM, some form of ROM, I/O ports, and timers. Unlike a generalpurpose computer, which also includes all of these components, a microcontroller is designed for a very specific task -- to control a particular system. As a result, the parts can be simplified and reduced, which cuts down on production costs.

Microcontrollers are sometimes called embedded microcontrollers, which just means that they are part of an embedded system -- that is, one part of a larger device or system.

MicroMo Electronics: Microcontrollers :Specializes in the design, assembly and application of high precision, miniature DC drive systems, components, and motion control systems.

Parallax Microcontrollers:Broad-line distributor web site features real-time stock status and pricing, online

ordering, RFQ, technical support, product datasheets and photos.

MICROCONTROLLER

A Microcontroller (also MCU or C) is a computer-on-a-chip. It is a type of microprocessor emphasizing high integration, low power consumption, self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). In addition to the usual arithmetic and logic elements of a general purpose microprocessor, the microcontroller typically integrates additional elements such as read-write memory for data storage, read-only memory, such as flash for code storage, EEPROM for permanent data storage, peripheral devices, and input/output interfaces. At clock speeds of as little as a few MHz or even lower, microcontrollers often operate at very low speed compared to modern day microprocessors, but this is adequate for typical applications. They consume relatively little power (militates), and will generally have the ability to sleep while waiting for an interesting peripheral event such as a

button press to wake them up again to do something. Power consumption while sleeping may be just nano watts, making them ideal for low power and long lasting battery applications. Microcontrollers are frequently used in automatically controlled products and devices, such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toys. By reducing the size, cost, and power consumption compared to a design using a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to electronically control many more processes.

EMBEDDED DESIGN:The majority of computer systems in use today are embedded in other machinery, such as telephones, clocks, appliances, and vehicles. An embedded system may have minimal requirements for memory and program length. Input and output devices may be discrete switches, relays, or solenoids. An embedded controller may lack any human-readable interface devices at all. For example, embedded systems usually don't have keyboards, screens, disks, printers, or other recognizable I/O devices of a personal computer. Microcontrollers may control electric motors, relays or voltages, and may read switches, variable resistors or other electronic devices.

HIGHER INTEGRATION:In contrast to general-purpose CPUs, microcontrollers may not implement an external address or data bus as they integrate RAM and non-volatile memory on the same chip as the CPU. Using fewer pins, the chip can be placed in a much smaller, cheaper package. Integrating the memory and other peripherals on a single chip and testing them as a unit increases the cost of that chip, but often results in decreased net cost of the embedded system as a whole. Even if the cost of a CPU that has integrated peripherals is slightly more than the cost of a CPU + external peripherals, having fewer chips typically allows a smaller and cheaper circuit board, and reduces the labor required to assemble and test the circuit board.

A microcontroller is a single integrated circuit, commonly with the following features: central processing unit - ranging from small and simple 4-bit processors to complex 32- or 64-bit processors discrete input and output bits, allowing control or detection of the logic state of an individual package pin serial input/output such as serial ports (UARTs) other serial communications interfaces like IC, Serial Peripheral Interface and Controller Area Network for system interconnect peripherals such as timers, event counters, PWM generators, and watchdog volatile memory (RAM) for data storage ROM, EPROM, [EEPROM] or Flash memory for program and operating parameter storage clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit many include analog-to-digital converters in-circuit programming and debugging support

This integration drastically reduces the number of chips and the amount of wiring and PCB space that would be needed to produce equivalent systems using separate chips. Furthermore, and on low pin count devices in particular, each pin may interface to several internal peripherals, with the pin function selected by software. This allows a part to be used in a wider variety of applications than if pins had dedicated functions. Microcontrollers have proved to be highly popular in embedded systems since their introduction in the 1970s. Some microcontrollers use a Harvard architecture: separate memory buses for instructions and data, allowing accesses to take place concurrently. Where a Harvard architecture is used, instruction words for the processor may be a different bit size than the length of internal memory and registers; for example: 12-bit instructions used with 8bit data registers.
10

The decision of which peripheral to integrate is often difficult. The microcontroller vendors often trade operating frequencies and system design flexibility against time-to-market requirements from their customers and overall lower system cost. Manufacturers have to balance the need to minimize the chip size against additional functionality. Microcontroller architectures vary widely. Some designs include general-purpose

microprocessor cores, with one or more ROM, RAM, or I/O functions integrated onto the package. Other designs are purpose built for control applications. A microcontroller instruction set usually has many instructions intended for bit-wise operations to make control programs more compact. For example, a general purpose processor might require several instructions to test a bit in a register and branch if the bit is set, where a microcontroller could have a single instruction that would provide that commonlyrequired function.

LARGE VOLUMES
Microcontrollers take the largest share of sales in the wider microprocessor market. Over 50% are "simple" controllers, and another 20% are more specialized digital signal processors (DSPs)[citation needed]. A typical home in a developed country is likely to have only one or two general-purpose microprocessors but somewhere between one and two dozen microcontrollers. A typical mid range automobile has as many as 50 or more microcontrollers. They can also be found in almost any electrical device: washing machines, microwave ovens, telephones etc.

11

Manufacturers have often produced special versions of their microcontrollers in order to help the hardware and software development of the target system. These have included EPROM versions that have a "window" on the top of the device through which program memory can be erased by ultra violet light, ready for reprogramming after a programming ("burn") and test cycle. An economical option for intermediate levels of production (usually a few score to a few thousand parts) is a one-time programmable (OTP) microcontroller. This uses the same die as the UV EPROM version of the part, and is programmed on the same equipment, but the package does not include the expensive quartz window required to admit UV light on to the chip. Other versions may be available where the ROM is accessed as an external device rather than as internal memory. A simple EPROM programmer, rather than a more complex and expensive microcontroller programmer, may then be used, however there is a potential loss of functionality through pin outs being tied up with external memory addressing rather than for general input/output. These kind of devices usually carry a higher cost but if the target production quantities are small, certainly in the case of a hobbyist, they can be the most economical option compared with the set up charges involved in mask programmed devices. A more rarely encountered development microcontroller is the "piggy back" version. This device has no internal ROM memory; instead pin outs on the top of the microcontroller form a socket into which a standard EPROM program memory device may be installed. The benefit of this approach is the release of microcontroller pins for Input and output use rather than program memory. These kinds of devices are normally expensive and are impractical for anything but the development phase of a project or very small production quantities.

12

The use of field-programmable devices on a microcontroller may allow field update of the firmware or permit late factory revisions to products that have been assembled but not yet shipped. Programmable memory also reduces the lead time required for deployment of a new product. Where a large number of systems will be made (say, several thousand), the cost of a mask-programmed memory is amortized over all products sold. A simpler integrated circuit process is used, and the contents of the read-only memory are set In the last step of chip manufacture instead of after assembly and test. However, maskprogrammed parts cannot be updated in the field. If product firmware updates are still contemplated, a socket may be used to hold the controller which can then be replaced by a service technician, if required.

13

AT-Command set overview

Command

Description Check if serial interface and GSM modem is working. Turn echo off, less traffic on serial line. Display of new incoming SMS. Selection of SMS memory. SMS string format, how they are compressed. Read new message from a given memory location. Send message to a given recipient. Delete message.

AT ATE0 AT+CNMI AT+CPMS

AT+CMGF

AT+CMGR AT+CMGS AT+CMGD

14

Status (AT)

The AT command is a status request used for testing if a compatible modem is connected and that the serial interface is working properly. AT command and possible responses

Command

Response

Comment Connected and working Serial line OK, modem error

AT

OK

ERROR

Echo off (ATE0)

The ATE0 command is used to configure the communication. By default, GSM modems are set to echo any received command back with an acknowledgement. An example of this is shown below. AT\r\n AT\r\nOK\r\n //Command sent to modem //Response from modem with echo enabled

After sending AT, the modem replies with AT\r\rOK\r\n. With echo off, ATE0, the modem would have answered \r\nOK\r\n when executing AT.

15

The echo off command will reduce traffic on the serial line. The ATE1 command will enable echo again.

ATE0 command and possible responses

Response Command (echo off) OK ATE0 ERROR Comment Echo off Could not turn echo off

New Message Indication (AT+CNMI)

AT+CNMI configures how the modem signals arrival of new messages to the connected terminal device and how they are stored in the modem. This feature is useful when it comes to reading new messages. Instead of polling the modem periodically for arrival of new messages, AT+CNMI can tell when a new message has arrived. The AVR will catch such indication, and set a flag. This ensures that the modem only takes up CPU resources when necessary.

AT+CNMI command and possible responses

16

Command

Response

Comment Mode set Error, could not set such mode.

1 2 3 4 5 AT+CNMI=*mode+ ,[mt] ,[bm] ,[ds] ,[bfr] OK

ERROR

NOTE:

1. [mode] integer type: how messages are buffered.

2. [mt] integer type: indication of new SMS, set to 1.

3. [bm] integer type: Not in use.

4. [ds] integer type: Not in use.

5. [bfr] integer type: Not in use.

17

What values *mode+, *mf+, *bm+, *ds+ and *bfr+ could take will be different from modem to modem. This should be tested off line with modem connected to the PC. An example is given below:

AT+CNMI=?\r\n

//Possible value request

+CNMI: (0,1),(0,1),(0,2),(0,2),(1)

//Possible parameter values

OK //Command executed OK

Preferred Message Storage (AT+CPMS)

The AT+CPMS command sets the target memory location for storing sent, read, deleted and received SMS messages. Most modems have multiple storage types:

SM: SIM card memory.

ME: Mobile Equipment storage. Dedicated storage within the modem for text messages only.

MT: Collection of all storage connected to the modem: SM, ME or others. The phone will chose one appropriate if this option is enabled.
18

AT+CPMS command and possible responses

Command

Response

Comment

+CPMS:*used1+,*total1+,*used2+, Memory configured 1 2 3 ,[M2] ,[M3] [total2],[used3],[total3] AT+CPMS=*M1+ OK \r\rOK\r\n +CMS ERROR Error

Notes:

1. [M1] string type: Memory from which messages are read and deleted.

2. [M2] string type: Memory to which messages are written and sent.

3. [M3] string type: Memory in which received messages are stored, if forwarding to pc is not set.

19

[used] integer type: is number of messages currently in x. [total] integer type: is total number of message locations in x.

Message format(AT+CMGF)

The AT+CMGF command is used to set input and output format of SMS messages. Two modes are available:

PDU mode: reading and sending SMS is done in a special encoded format.

Text mode: reading and sending SMS is done in plain text.

PDU mode is described later in section 2.2. This compressed format saves message payload and is default on most modems. PDU mode is implemented in the source code for this application note, it is possible to use text mode to reduce code footprint if the connected modem supports this. In text mode header fields as sender address, message length, validation period etc. can be read out in plain text together with the sent message. Please consult GSM

Command
1 2 3 AT+CPMS=*M1+ ,[M2] ,[M3]

Response

Comment

+CPMS:*used1+,*total1+,*used2+, Memory configured [total2],[used3],[total3]


20

\r\rOK\r\n +CMS ERROR Notes: Error

OK

1. [M1] string type: Memory from which messages are read and deleted.

2. [M2] string type: Memory to which messages are written and sent.

3. [M3] string type: Memory in which received messages are stored, if forwarding to pc is not set.

[used] integer type: is number of messages currently in x. [total] integer type: is total number of message locations in x.

Message format(AT+CMGF)

The AT+CMGF command is used to set input and output format of SMS messages. Two modes are available:

PDU mode: reading and sending SMS is done in a special encoded format.
21

Text mode: reading and sending SMS is done in plain text.

PDU mode is described later. This compressed format saves message payload and is default on most modems. PDU mode is implemented in the source code for this application note, it is possible to use text mode to reduce code footprint if the connected modem supports this. In text mode header fields as sender address, message length, validation period etc. can be read out in plain text together with the sent message.

for more about reading messages in text mode. This is not the main target for this application.

. AT+CMGF command and possible responses Command


1 AT+CMGF=*mode+

Response OK ERROR Error

Comment Mode selected

Notes:

1. [mode] integer type: 0 is PDU mode, 1 is text mode.

22

Read Message(AT+CMGR)

The AT+CMGR command is used to read a message from a given memory location. Execution of AT+CMGR returns a message at *index+ from selected memory [M1] (See section 2.1.4 for memory setup). The status of the message and the entire compressed message (PDU) is returned. To get any useful information out of the compressed message it should be decompressed. The PDU format and the compression and decompression is described in section 2.2.2. Table 2-7. AT+CMGR command and possible responses

Command
1 AT+CMGR=*index+

Response

Comment

2 3 4 +CMGR:*stat+ ,[alpha] , [length] Message read OK \r\n pdu]5

+CMS ERROR

Error, No such index

Notes:

1. [index] integer type: Read message from location [index].

2. [stat]: integer type: Status of message in memory: READ, UNREAD, SENT and UNSENT.

3. [alpha] integer type: Manufacturer specific field. Not used.

23

4. [length] integer type: Length of compressed message.

5. [pdu] string type: Compressed message.

Send Message(AT+CMGS)

This command enables the user to send SMS messages. Section 2.2.3 describes how to build such messages. How to include user defined text and recipient telephone number. After the user defined fields are set, the message can be compressed and sent using the AT+CMGS command. An example usage of AT+CMGS is given in section 2.2.3. Table AT+CMGS command and possible responses

Command
1 2 AT+CMGS=*length+ CR 3 4 [pdu] ctrl-Z

Response OK +CMS ERROR

Comment Message sent

Command error

Notes: 1. [length] integer type: Length of message.

2. CR = Carriage return

24

3. [pdu] string type: Compressed message

4. Ctrl-Z: Command terminator. ASCII character 26 (dec).

Delete Message (AT+CMGD)

This command is used to delete a received stored message from [M1] (See Table 2-5). Table. AT+CMGD command and possible responses This concludes the presentation of the implemented AT-Command set. More commands are discussed in ETSI standard GSM 07.05, and proposed as a reference when working with applications interfacing GSM compatible modems together with manufacturers datasheet.

Command
1 AT+CMGD=*index+

Response OK ERROR

Comment Message deleted Command error

Notes:

1. [index] integer type: Index of message to delete.

25

PDU format explained

There are two ways of sending and receiving SMS messages: by text mode and by PDU (Protocol Description Unit) mode. By default most phones and modems are setup to send SMS messages using a special compression format (PDU-mode). Some modems supports text-mode, in which any information and the message itself can be read as plain text. Note however that not all phones and modems support text-mode.

DESCRIPTION OF PROJECT

26

Interfacing of mobile phone with 8051:

We used a hands-free to take out the signal from mobile phone to transmit it to microcontroller. The operating voltage of mobile is 3.3 V and provides 3.7 volt at logic 1 and 0 v at logic0. To take it to the level equal of microcontroller we used Max 232 IC. It can sense input voltage lower than 2V.

MAX 232: The MAX232 is a dual driver/receiver that includes a capacitive voltage generator to supply EIA-232 voltage levels from a single 5-V supply. Each receiver converts EIA-232 inputs to 5-V TTL/CMOS levels. These receivers have a typical threshold of 1.3 V and a typical hysteresis of 0.5 V, and can accept 30-V inputs. Each driver converts TTL/CMOS input levels into EIA-232 levels.

Pin Diagram

27

logic diagram (positive logic)

What is Inside an LED?


LED's are special diodes that emit light when connected in a circuit. They are frequently used as "pilot" lights in electronic appliances to indicate whether the circuit is closed or not. A a clear (or often colored) epoxy case enclosed the heart of an LED, the semi-conductor chip.

28

11.RELAY

Introduction:A relay is an electrical switch that opens and closes under control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. It was invented by Joseph Henry in 1835. Because a relay is able to control an output circuit of higher power than the input circuit, it can be considered, in a broad sense, to be a form of an electrical amplifier.

Operation:-

When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing.

If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation, a light-emitting diode (LED) is used with a photo transistor.

29

Types of relay:-

Figure: 11.1: latching relay 1) Latching relay:-

A latching relay has two relaxed states (bistable). These are also called 'keep' relays. When the current is switched off, the relay remains in its last state. This is achieved with a solenoid operating a ratchet and cam mechanism, or by having two opposing coils with an over-center spring or permanent magnet to hold the armature and contacts in position while the coil is relaxed, or with a remnant core. In the ratchet and cam example, the first pulse to the coil turns the relay on and the second pulse turns it off.

In the two coil example, a pulse to one coil turns the relay on and a pulse to the opposite coil turns the relay off. This type of relay has the advantage that it consumes power only for an instant, while it is being switched, and it retains its last setting across a power outage.

2) Reed relay:-

30

A reed relay has a set of contacts inside a vacuum or inert gas filled glass tube, which protects the contacts against atmospheric corrosion. The contacts are closed by a magnetic field generated when current passes through a coil around the glass tube. Reed relays are capable of faster switching speeds than conventional relays. See also reed switch.

2.1) Mercury-wetted relay:-

A mercury-wetted relay is a form of reed relay in which the contacts are wetted with mercury. Such relays are used to switch low-voltage signals (one volt or less) because of its low contact resistance, or for high-speed counting and timing applications where the mercury eliminated contact bounce. Mercury wetted relays are position-sensitive and must be mounted vertically to work properly. Because of the toxicity and expense of liquid mercury, these relays are rarely specified for new equipment. See also mercury switch.

3) Polarized relay:-

A Polarized Relay placed the armature between the poles of a permanent magnet to increase sensitivity. Polarized relays were used in middle 20th Century telephone exchanges to detect faint pulses and correct telegraphic distortion. The poles were on screws, so a technician could first adjust them for maximum sensitivity and then apply a bias spring to set the critical current that would operate the relay.

4) Machine tool relay:-

A machine tool relay is a type standardized for industrial control of machine tools, transfer machines, and other sequential control. They are characterized by a large number of contacts (sometimes extendable in the field) which are easily converted from normally-open to normally-closed status, easily replaceable coils, and a form factor that allows compactly installing many relays in a control panel. Although such relays once were the 31

backbone of automation in such industries as automobile assembly, the programmable logic controller mostly displaced the machine tool relay from sequential control applications.

5) Contactor relay:-

A contactor is a very heavy-duty relay used for switching electric motors and lighting loads. With high current, the contacts are made with pure silver. The unavoidable arcing causes the contacts to oxidize and silver oxide is still a good conductor. Such devices are often used for motor starters. A motor starter is a contactor with an overload protection devices attached. The overload sensing devices are a form of heat operated relay where a coil heats a bi-metal strip, or where a solder pot melts, releasing a spring to operate auxiliary contacts. These auxiliary contacts are in series with the coil. If the overload senses excess current in the load, the coil is de-energized. Contactor relays can be extremely loud to operate, making them unfit for use where noise is a chief concern.

Pole & Throw:-

Circuit symbols of relays. "C" denotes the common terminal in SPDT and DPDT types. Since relays are switches, the terminology applied to switches is also applied to relays. According to this classification, relays can be of the following types:

32

* SPST - Single Pole Single Throw. These have two terminals which can be switched on/off. In total, four terminals when the coil is also included. * SPDT - Single Pole Double Throw. These have one row of three terminals. One terminal (common) switches between the other two poles. It is the same as a single change-over switch. In total, five terminals when the coil is also included. * DPST - Double Pole Single Throw. These have two pairs of terminals. Equivalent to two SPST switches or relays actuated by a single coil. In total, six terminals when the coil is also included. This configuration may also be referred to as DPNO.

* DPDT - Double Pole Double Throw. These have two rows of change-over terminals. Equivalent to two SPDT switches or relays actuated by a single coil. In total, eight terminals when the coil is also included. * QPDT - Quadruple Pole Double Throw. Often referred to as Quad Pole Double Throw, or 4PDT. These have four rows of change-over terminals. Equivalent to four SPDT switches or relays actuated by a single coil or two DPDT relays. In total, fourteen terminals when the coil is also included. 33

The contacts can be either Normally Open (NO), Normally Closed (NC), or change-over (CO) contacts.

* Normally-open contacts connect the circuit when the relay is activated; the circuit is disconnected when the relay is inactive. It is also called Form A contact or "make" contact. Form A contact is ideal for applications that require to switch a high-current power source from a remote device. * Normally-closed contacts disconnect the circuit when the relay is activated; the circuit is connected when the relay is inactive. It is also called Form B contact or "break" contact. Form B contact is ideal for applications that require the circuit to remain closed until the relay is activated. * Change-over contacts control two circuits: one normally-open contact and one normally-closed contact with a common terminal. It is also called Form C contact or "transfer" contact.

34

TRANSFORMER
Transformer is a device that transfers electrical energy from one circuit to another through inductively coupled wires. A changing current in the first circuit (the primary) creates a changing magnetic field; in turn, this magnetic field induces a changing voltage in the second circuit (the secondary). By adding a load to the secondary circuit, one can make current flow in the transformer, thus transferring energy from one circuit to the other. The secondary induced voltage VS is scaled from the primary VP by a factor ideally equal to the ratio of the number of turns of wire in their respective windings: By appropriate selection of the numbers of turns, a transformer thus allows an alternating voltage to be stepped up by making NS more than NP or stepped down, by making it less. A key application of transformers is to reduce the current before transmitting electrical energy over long distances through wires. Most wires have resistance and so dissipate electrical energy at a rate proportional to the square of the current through the wire. By transforming electrical power to a high-voltage, and therefore low-current form for transmission and back again afterwards, transformers enable the economic transmission of power over long distances. Consequently, transformers have shaped the electricity supply industry, permitting generation to be located remotely from points of demand. All but a fraction of the world's electrical power has passed through a series of transformers by the time it reaches the consumer.

35

Transformers are some of the most efficient electrical 'machines', with some large units able to transfer 99.75% of their input power to their output. Transformers come in a range of sizes from a thumbnail-sized coupling transformer hidden inside a stage microphone to huge units weighing hundreds of tonnes used to interconnect portions of national power grids. All operate with the same basic principles, though a variety of designs exist to perform specialized roles throughout home and industry.

BASIC PRINCIPLES:The transformer is based on two principles: first, that an electric current can produce a magnetic field (electromagnetism) and, second, that a changing magnetic field within a coil of wire induces a voltage across the ends of the coil ( electromagnetic induction). By changing the current in the primary coil, one changes the strength of its magnetic field; since the secondary coil is wrapped around the same magnetic field, a voltage is induced across the secondary.An ideal step-down transformer showing magnetic flux in the core A simplified transformer design is shown to the right. A current passing through the primary coil creates a magnetic field. The primary and secondary coils are wrapped around a core of very high magnetic permeability, such as iron; this ensures that most of the magnetic field lines produced by the primary current are within the iron and pass through the secondary coil as well as the primary coil.

36

INDUCTION LAW:The voltage induced across the secondary coil may be calculated from Faraday's law of induction, which states thatWhere VS is the instantaneous voltage, NS is the number of turns in the secondary coil and equals the total magnetic flux through one turn of the coil. If the turns of the coil are oriented perpendicular to the magnetic field lines, the flux is the product of the magnetic field strength B and the area A through which it cuts. The area is constant, being equal to the cross-sectional area of the transformer core, whereas the magnetic field varies with time according to the excitation of the primary. Since the same magnetic flux passes through both the primary and secondary coils in an ideal transformer, the instantaneous voltage across the primary winding equals Taking the ratio of the two equations for VS and VP gives the basic equationfor stepping up or stepping down the voltage

37

IDEAL POWER EQUATION

The ideal transformer as a circuit element

If the secondary coil is attached to a load that allows current to flow, electrical power is transmitted from the primary circuit to the secondary circuit. Ideally, the transformer is perfectly efficient; all the incoming energy is transformed from the primary circuit to the magnetic field and thence to the secondary circuit. If this condition is met, the incoming electric power must equal the outgoing power
Pincoming = IPVP = Poutgoing = ISVS

giving the ideal transformer equation

38

Thus, if the voltage is stepped up (VS > VP), then the current is stepped down (IS < IP) by the same factor. In practice, most transformers are very efficient (see below), so that this formula is a good approximation. The impedance in one circuit is transformed by the square of the turns ratio. For example, if an impedance ZS is attached across the terminals of the secondary coil, it appears to the primary circuit to have an impedance of . This relationship is reciprocal, so that the impedance ZP of the primary circuit appears to the secondary to be .

TECHNICAL DISCUSSION:The simplified description above avoids several complicating factors, in particular the primary current required to establish a magnetic field in the core, and the contribution to the field due to current in the secondary circuit. Models of an ideal transformer typically assume a core of negligible reluctance with two windings of zero resistance.[7] When a voltage is applied to the primary winding, a small current flows, driving flux around the magnetic circuit of the core. The current required to create the flux is termed the magnetising current; since the ideal core has been assumed to have near-zero reluctance, the magnetising current is negligible, although a presence is still required to create the magnetic field. The changing magnetic field induces an electromotive force (EMF) across each winding. Since the ideal windings have no impedance, they have no associated voltage drop, and so the voltages VP and VS measured at the terminals of the transformer, are equal to the corresponding EMFs. The primary EMF, acting as it does in opposition to the primary voltage, is sometimes termed the "back EMF".This is due to Lenz's law which

39

states that the induction of EMF would always be such that it will oppose development of any such change in magnetic field.

PRACTICAL CONSIDERATIONS:-

40

Flux leakage in a two-winding transformer

FLUX LEAKAGE:

Leakage Inductance

The ideal transformer model assumes that all flux generated by the primary winding links all the turns of every winding, including itself. In practice, some flux traverses paths that take it outside the windings. Such flux is termed leakage flux, and manifests itself as self-inductance in series with the mutually coupled transformer windings. Leakage results in energy being alternately stored in and discharged from the magnetic fields with each cycle of the power supply. It is not itself directly a source of power loss, but results in poorer voltage regulation, causing the secondary voltage to fail to be directly proportional to the primary, particularly under heavy load. Distribution transformers are therefore normally designed to have very low leakage inductance However, in some applications, leakage can be a desirable property, and long magnetic paths, air gaps, or magnetic bypass shunts may be deliberately introduced to a transformer's design to limit the short-circuit current it will supply. Leaky transformers may be used to supply loads that exhibit negative resistance, such as electric arcs, mercury vapor lamps, and neon signs; or for safely handling loads that become periodically short-

41

circuited such as electric arc welders. Air gaps are also used to keep a transformer from saturating, especially audio-frequency transformers that have a DC component added.

EFFECT OF FREQUENCY
The time-derivative term in Faraday's Law shows that the flux in the core is the integral of the applied voltage. An ideal transformer would, at least hypothetically, work under direct-current excitation, with the core flux increasing linearly with time. In practice, the flux would rise very rapidly to the point where magnetic saturation of the core occurred, causing a huge increase in the magnetising current and overheating the transformer. All practical transformers must therefore operate under alternating (or pulsed) current conditions. Transformer universal EMF equation If the flux in the core is sinusoidal, the relationship for either winding between its rms EMF E, and the supply frequency f, number of turns N, core cross-sectional area a and peak magnetic flux density B is given by the universal EMF equation:

. The EMF of a transformer at a given flux density increases with frequency, an effect predicted by the universal transformer EMF equation. By operating at higher frequencies, transformers can be physically more compact because a given core is able to transfer more power without reaching saturation, and fewer turns are needed to

42

achieve the same impedance. However properties such as core loss and conductor skin effect also increase with frequency. Aircraft and military equipment traditionally employ 400 Hz power supplies which are less efficient but this is more than offset by the reduction in core and winding weight. In general, operation of a transformer at its designed voltage but at a higher frequency than intended will lead to reduced magnetising current. At a frequency lower than the design value, with the rated voltage applied, the magnetising current may increase to an excessive level. Operation of a transformer at other than its design frequency may require assessment of voltages, losses, and cooling to establish if safe operation is practical. For example, transformers may need to be equipped with "volts per hertz" over-excitation relays to protect the transformer from overvoltage at higher than rated frequency. Knowledge of natural frequencies of transformer windings is of importance for the determination of the transient response of the windings to impulse and switching surge voltages.

ENERGY LOSSES:An ideal transformer would have no energy losses, and would therefore be 100% efficient. Despite the transformer being amongst the most efficient of electrical machines, with experimental models using superconducting windings achieving efficiencies of 99.85%,energy is dissipated in the windings, core, and surrounding structures. Larger transformers are generally more efficient, and those rated for electricity distribution usually perform better than 95%. A small transformer, such as a plug-in "power brick" used for low-power consumer electronics, may be no more than
43

85% efficient; although individual power loss is small, the aggregate losses from the very large number of such devices is coming under increased scrutiny. Transformer losses are attributable to several causes and may be differentiated between those originating in the windings, sometimes termed copper loss, and those arising from the magnetic circuit, sometimes termed iron loss. The losses vary with load current, and may furthermore be expressed as "no-load" or "full-load" loss, respectively. Winding resistance dominates load losses, whereas hysteresis and eddy currents losses contribute to over 99% of the no-load loss. The no-load loss can be significant, meaning that even an idle transformer constitutes a drain on an electrical supply, and lending impetus to development of low-loss transformers (also see energy efficient transformer).

Losses in the transformer arise from:


Winding Resistance :Current flowing through the windings causes resistive heating of the conductors. At higher frequencies, skin effect and proximity effect create additional winding resistance and losses.

Hysteresis losses :-

Each time the magnetic field is reversed, a small amount of energy is lost due to hysteresis within the core. For a given core material, the loss is proportional to the frequency, and is a function of the peak flux density to which it is subjected.

Eddy Currents :-

44

Ferromagnetic materials are also good conductors, and a solid core made from such a material also constitutes a single short-circuited turn throughout its entire length. Eddy currents therefore circulate within the core in a plane normal to the flux, and are responsible for resistive heating of the core material. The eddy current loss is a complex function of the square of supply frequency and inverse square of the material thickness.

Magnetostriction:Magnetic flux in a ferromagnetic material, such as the core, causes it to physically expand and contract slightly with each cycle of the magnetic field, an effect known as magnetostriction. This produces the buzzing sound commonly associated with transformers,[6] and in turn causes losses due to frictional heating in susceptible cores.

Mechanical losses :In addition to magnetostriction, the alternating magnetic field causes fluctuating electromagnetic forces between the primary and secondary windings. These incite vibrations within nearby metalwork, adding to the buzzing noise, and consuming a small amount of power.[19]

Stray losses :-

Leakage inductance is by itself lossless, since energy supplied to its magnetic fields is returned to the supply with the next half-cycle. However, any leakage flux that intercepts nearby conductive materials such as the transformer's support structure will give rise to eddy currents and be converted to heat.

45

ANALOG TO DIGITAL CONVERTER:

The output of the various parameters is fed to A/D converter. The channel selection depends upon the address selection sent by the Micro-controller. This ADC is having three address inputs to select one out of eight channels of the ADC. This ADC 0809 is a successive approx. Analog to digital converter and the clock rate at which the conversion is fed from the IC 555 timer configured as astable multi-vibrator. The digital output after conversion is fed to Micro-controller

For ADC to start converting the data after selecting the channel by sending the address inputs, the start conversion signal is to be sent by Micro-controller. Then ADC starts converting the analog signals voltage into corresponding digital data. For Ex: The following table shows the digital data corresponding to analog input.

46

After conversion, the ADC generates EOC (End of conversion). This indicates to Micro-controller that the conversion is completed and takes the digital data corresponding to analog input. The following is Circuit diagram of A/D Converter along with its clock generator:

In the above circuit diagram 555 timer IC is used for generating the required clock pulses.

Counter type A/D Converter:

A counter type A/D converter (Also called servo or ramp A/D converters) consists of a comparator, voltage output DAC, binary counter, and the necessary control logic. When the start command is received, the control logic resets the binary counter, enables the clock, and begins counting. The counter outputs control the DAC inputs, so the DAC output voltage will begin to rise when the counter begins to increment. As long as analog input voltage Vx is less than Vref (The DAC output), 47

the comparator output is HIGH, when Vx and Vref are equal, however, the comparator output goes low, which turns off the clock and stops the counter output at this time represents the value of Vx. The following is the block diagram of binary A/D converter.

SUCCESSIVE APPROXIMATION A/D CONVERTERS:

Successive approximation A/D conversion is best suited for many applications where speed is important. This type of A/D converter requires only N+1 clock cycles to make the conversion, and some designs allow truncation of the conversion process after fewer cycles if the final value is found prior to N+1 Cycles. The successive approximation converter operates by making several successive trails at comparing the analog input voltage with a reference generated by a DAC.

PARALLEL OR FLASH A/D converters:

48

The parallel A/D Converter is probably the fastest A/D circuit known; indeed, the very fastest ordinary commercial products use this method. Some sources call the parallel A/D converter the flash circuit because of its inherent high speed. The parallel A/D converter consists of a blank of (2N-1) voltage comparators biased by reference potential Vref though a resistor Network that keeps the individual comparators 1-LSB a port. Since the input voltage is applied to all the comparators simultaneously, the speed of conversion is limited essentially by slow rate of the slowest comparator in the bank, and also by the decoder circuit propagation time. The decoder converts the output code to binary code needed by the computers. The A/D converter is a circuit that is used to produce a binary number output that represents an analog voltage applied to the input.

CLOCK GENERATOR:

The required clock for the ADC is generated using 555 Timer IC that is configured as Astable multi-vibrator (Self Oscillator). In this mode of operation the required frequency can be adjusted using two external components i.e., resistor and capacitor. Keeping capacitor value constant where as by varying the value of resistor the frequency can be adjusted from 1Hz to 500KHz. Here the required frequency is 100 KHz approximately.

In the above circuit diagram 555 timer IC is used for generating the required clock pulses. Frequency can be adjusted using variable resistor 100K (RB). In this circuit, the external capacitor charges through RA+RB and discharges through RB. Thus the duty cycle may be precisely set by the ratio of these two resistors. In this mode of operation, the capacitor charges and discharges between 1/3 VCC and 2/3 VCC. As in the triggered mode, the charge and discharge times, and therefore the frequency are independent of the supply voltage. Here the timing resistor is now split into two sections, RA and RB, with the discharge transistor (Pin 7) connected to junction of Ra and Rb. When the power supply is connected, the timing capacitor C charges towards 2/3 VCC through Ra and Rb. When the capacitor 49

voltage reaches 2/3 VCC, the upper comparator triggers the flip-flop and the capacitor starts to discharge towards ground through Rb. When the discharge reaches 1/3 VCC the lower comparator is triggered and a new cycle is started. The capacitor is then periodically charged and discharged between 2/3 VCC and 1/3 VCC respectively. The output state is high during the charging cycle for a time period t1, so that

The output state is LOW during the discharge cycle for a time period t2, given by

t2 = 0.693 RbC

Thus, the total period charge and discharge is

T = t1 + t2 = 0.693 (Ra + 2Rb) C (Seconds)

So that the output frequency is given as

50

Code:
;--------------------------------------------------------------------------------------------------------; CONSTANT DECLARATIONS

;---------------------------------------------------------------------------------------------------------

CR LF CD

EQU EQU EQU

0DH 0AH 10H

CONT COUNT

EQU EQU

16 3

L1 L2

EQU EQU

80H 0C0H

LCD_DB4 LCD_DB5 LCD_DB6 LCD_DB7 LCD_RS LCD_E

EQU EQU EQU EQU EQU EQU

P0.0 P0.1

;PORT 1 IS USED FOR DATA ;USED FOR DATA

P0.2 ;FOR DATA P0.3 P0.5 ;FOR DATA ;LCD REGISTER SELECT LINE

P0.4 ;LCD ENABLE LINE

51

CH_A CH_B CH_C

BIT BIT BIT

P1.0 P0.6 P0.7

ALE OE SC EOC BIT

BIT BIT BIT P1.3

P1.1 P1.4 P1.2

ADC OUT

EQU EQU

P2 P3

;--------------------------------------------------------------------------------------------------------; VARIABLE DECLARATIONS

;--------------------------------------------------------------------------------------------------------;ASCI_RSULT ;RAM_ADDR DATA DATA 20H 25H

DSEG

AT

20H

; THIS IS

INTERNAL DATA MEMORY

FLAGS: UF1

DS BIT

1 FLAGS.0

52

UF2 UF3 UF4 UF5 UF6

BIT BIT BIT BIT BIT

FLAGS.1 FLAGS.2 FLAGS.3 FLAGS.4 FLAGS.5

ASCI_RSULT: RAM_ADDR: VAR:

DS DS DS

3 3 1

;-----------------------------------------------------------------------------------------------------------------------------------------------;----------------------------------------------------------------------------------------------------------------------------- ------------------; ***CURSOR CONTROL INSTRUCTIONS***

OFFCUR BLINKCUR

EQU EQU

0CH 0DH

; ***DISPLAY CONTROL INSTRUCTIONS***

CLRDSP ONDSP

EQU EQU

01H 0CH

; ***SYSTEM INSTRUCTIONS***

53

CONFIG ENTRYMODE EQU

EQU 6

28H

; 4-BIT DATA,2 LINES,5X7 MATRIX LCD

; INCREMENT CURSOR DON'T SHIFT DISPLAY

;--------------------------------------------------------------------------------------------------------; BY PASS INTERRUPT VECTOR

;--------------------------------------------------------------------------------------------------------CSEG AT 00H

SJMP

LCD4_MAIN

;--------------------------------------------------------------------------------------------------------; MAIN LINE CODE

;--------------------------------------------------------------------------------------------------------CSEG AT 30H

LCD4_MAIN: MOV MOV MOV MOV SP, #60H ADC, #0FFH VAR, #00H FLAGS, #00H

MOV MOV

TMOD,#20H TH1,#-3

;TIMER 1 IN MODE 2 ;9600 BAUD RATE

54

MOV SETB CLR

SCON,#50H TR1 RI

;8-BIT, 1 STOP BIT, REN ENABLED ;START TIMER 1

SETB CLR CLR CLR

EOC ALE SC OE

SETB SETB SETB SETB

OUT.2 OUT.3 OUT.4 OUT.5

ACALL CALL CALL

CLEAR_M HALF_SEC HALF_SEC

ACALL MOV ACALL

M_SND DPTR,#POWER SENDSTRING

55

;********************************************************************************************* ******** CALL CALL CALL CALL CALL CALL CALL CALL RESETLCD4 DISPLAY HALF_SEC HALF_SEC HALF_SEC HALF_SEC HALF_SEC HALF_SEC

AGAIN:

ACALL

CH0 CALL ACALL CALL ACALL CALL ACALL HALF_SEC CH1 HALF_SEC CH2 HALF_SEC CH3

AJMP

AGAIN

;-----------------------------------------------------------------------------------------------------------CH0: CLR CH_C

56

CLR CLR ACALL SETB ACALL SETB ACALL CLR CLR JB JNB SETB ACALL MOV MOV CLR ACALL MOV ACALL

CH_B CH_A DELAY ALE DELAY SC DELAY ALE SC EOC, $ EOC, $ OE DELAY A, ADC VAR, A OE CONV R4, #L2+2 WRLCDCOM4

MOV MOV NXT1: MOV A, @R1

R2, #COUNT-1 R1, #ASCI_RSULT+1

57

MOV ACALL CALL DEC DJNZ

R4, A WRLCDDATA DELAY R1 R2, NXT1

MOV CLR CJNE CLR CLR JB ACALL MOV ACALL SETB SJMP

A, VAR C A,#10D, NEXT OUT.2 UF2 UF1, EXX M_SND DPTR,#PMP_ON SENDSTRING UF1 EXX

NEXT:

JNC

EXX CLR CLR JB ACALL M_SND OUT.2 UF2 UF1, EXX

58

MOV ACALL SETB

DPTR,#PMP_ON SENDSTRING UF1

EXX:

RET

;-----------------------------------------------------------------------------------------------------------;-----------------------------------------------------------------------------------------------------------CH1: CLR CH_C CLR SETB ACALL SETB ACALL SETB ACALL CLR CLR JB JNB SETB ACALL MOV OE DELAY A, ADC CH_B CH_A DELAY ALE DELAY SC DELAY ALE SC EOC, $ EOC, $

59

MOV CLR ACALL MOV ACALL

VAR, A OE CONV R4, #L2+7 WRLCDCOM4

MOV MOV NXT2: MOV A, @R1 MOV ACALL CALL DEC DJNZ

R2, #COUNT R1, #ASCI_RSULT+2

R4, A WRLCDDATA DELAY R1 R2, NXT2

MOV CLR CJNE SETB CLR JB ACALL MOV

A, VAR C A,#250D, NEXT1 OUT.2 UF1 UF2, EXX1 M_SND DPTR,#PMP_OFF

60

ACALL SETB SJMP

SENDSTRING UF2 EXX1

HY1:

SETB

OUT.2 CLR JB ACALL MOV ACALL SETB SJMP M_SND DPTR,#PMP_OFF SENDSTRING UF2 EXX1 UF1 UF2, EXX1

NEXT1: EXX1:

JNC RET

HY1

;-----------------------------------------------------------------------------------------------------------;-----------------------------------------------------------------------------------------------------------CH2: CLR CH_C SETB CLR ACALL SETB CH_B CH_A DELAY ALE

61

ACALL SETB ACALL CLR CLR JB JNB SETB ACALL MOV MOV CLR ACALL MOV ACALL

DELAY SC DELAY ALE SC EOC, $ EOC, $ OE DELAY A, ADC VAR, A OE CONV R4, #L2+13 WRLCDCOM4

MOV MOV NXT3: MOV A, @R1 MOV ACALL CALL DEC

R2, #COUNT R1, #ASCI_RSULT+2

R4, A WRLCDDATA DELAY R1

62

DJNZ

R2, NXT3

MOV CLR CJNE SETB JB ACALL MOV ACALL SETB CLR SJMP

A, VAR C A,#250D, NEXT2 OUT.3 UF4, EXX2 M_SND DPTR,#VLV1_CL SENDSTRING UF4 UF3 EXX2

NEXT11: JNC

EXX2 SETB JB ACALL MOV ACALL SETB CLR M_SND DPTR,#VLV1_CL SENDSTRING UF4 UF3 OUT.3 UF4, EXX2

63

SJMP

EXX2

HY2:

CLR

OUT.3 JB ACALL MOV ACALL SETB CLR SJMP M_SND DPTR,#VLV1_OP SENDSTRING UF3 UF4 EXX2 UF3, EXX2

;----------------------------------------------------------------------------------------------------------NEXT2: JNC HY2 MOV CLR CJNE SETB JB ACALL MOV ACALL SETB CLR EXX2: RET M_SND DPTR,#VLV1_CL SENDSTRING UF4 UF3 A, VAR C A,#10D, NEXT11 OUT.3 UF4, EXX2

64

;-----------------------------------------------------------------------------------------------------------;-----------------------------------------------------------------------------------------------------------CH3: CLR CH_C SETB SETB ACALL SETB ACALL SETB ACALL CLR CLR JB JNB SETB ACALL MOV MOV CLR ACALL MOV ACALL OE DELAY A, ADC VAR, A OE CONV R4, #L1+1 WRLCDCOM4 CH_B CH_A DELAY ALE DELAY SC DELAY ALE SC EOC, $ EOC, $

65

MOV MOV NXT4: MOV A, @R1 MOV ACALL CALL DEC DJNZ

R2, #COUNT R1, #ASCI_RSULT+2

R4, A WRLCDDATA DELAY R1 R2, NXT4

MOV CLR CJNE SETB JB ACALL MOV ACALL SETB CLR SJMP

A, VAR C A,#250D, NEXT3 OUT.4 UF6, EXX3 M_SND DPTR,#VLV2_CL SENDSTRING UF6 UF5 EXX3

66

NEXT44: JNC

EXX3 SETB JB ACALL MOV ACALL SETB CLR SJMP M_SND DPTR,#VLV2_CL SENDSTRING UF6 UF5 EXX3 OUT.4 UF6, EXX3

HY3:

CLR

OUT.4 JB ACALL MOV ACALL SETB CLR SJMP M_SND DPTR,#VLV2_OP SENDSTRING UF5 UF6 EXX3 UF5, EXX3

;----------------------------------------------------------------------------------------------------------NEXT3: JNC HY3 MOV CLR CJNE A, VAR C A,#10D, NEXT44

67

SETB JB ACALL MOV ACALL SETB CLR EXX3: RET

OUT.4 UF6, EXX3 M_SND DPTR,#VLV2_CL SENDSTRING UF6 UF5

;---------------MAIN PROGRAM----------------------------------------------------------CONV: ACALL BIN_DEC_CONV ACALL RET DEC_ASCI_CONV

;-------------CONVERTING BIN (HEX) TO DEC (00-FF TO 000-255)---------------BIN_DEC_CONV:

MOV ; MOV MOV DIV MOV INC

R0, #RAM_ADDR A, ADC B, #10 AB @R0, B R0

68

MOV DIV MOV INC MOV RET

B, #10 AB @R0, B R0 @R0, A

;--------------CONVERTING DEC DIGITS TO DISPLAYABLE ASCII DIGITS-------------------------------------DEC_ASCI_CONV:

MOV MOV MOV H2: MOV ORL MOV INC INC DJNZ RET

R0, #RAM_ADDR R1, #ASCI_RSULT R2, #COUNT A, @R0 A, #30H @R1, A R0 R1 R2, H2

;--------------------------------------------------------------------------------------------------------;TEMP: ; MOV R2, #COUNT

69

; ; ;NXT: ; ; ; ; ; ;RET MOV

MOV

R1, #ASCI_RSULT+1

A, @R1 MOV ACALL CALL DEC DJNZ R4, A WRLCDDATA DELAY1 R1 R2, NXT

;********************************************************************************************* ***** ; INITIALIZE THE LCD 4-BIT MODE ;********************************************************************************************* ***** INITLCD4: CLR CLR MOV LCD_RS LCD_E R4, #CONFIG ; LCD REGISTER SELECT LINE ; ENABLE LINE ; FUNCTION SET - DATA BITS, ; LINES, FONTS CALL MOV CALL MOV WRLCDCOM4 R4, #ONDSP WRLCDCOM4 R4, #ENTRYMODE ; SET ENTRY MODE ; DISPLAY ON

70

CALL MOV CALL RET

WRLCDCOM4 R4, #CLRDSP WRLCDCOM4

; INCREMENT CURSOR RIGHT, NO SHIFT ; CLEAR DISPLAY, HOME CURSOR

;********************************************************************************************* ***** ; SOFTWARE VERSION OF THE POWER ON RESET ;********************************************************************************************* ***** RESETLCD4: CLR CLR CLR CLR SETB SETB SETB CLR MOV CALL SETB CLR MOV CALL LCD_RS LCD_E LCD_DB7 LCD_DB6 LCD_DB5 LCD_DB4 LCD_E LCD_E A, #4 MDELAY LCD_E LCD_E A, #1 MDELAY ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 4 MILLISECONDS ; LCD REGISTER SELECT LINE ; ENABLE LINE ; SET BIT PATTERN FOR... ; ... POWER-ON-RESET

71

SETB CLR MOV CALL CLR SETB CLR MOV CALL MOV CALL MOV CALL MOV CALL MOV ACALL

LCD_E LCD_E A, #1 MDELAY LCD_DB4 LCD_E LCD_E A, #1 MDELAY R4, #CONFIG WRLCDCOM4 R4, #08H WRLCDCOM4 R4, #1 WRLCDCOM4 R4,#ENTRYMODE WRLCDCOM4 JMP INITLCD4

; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND

; SPECIFY 4-BIT OPERATION ; START ENABLE PULSE ; END ENABLE PULSE ; DELAY 1 MILLISECOND

; FUNCTION SET

; DISPLAY OFF

; CLEAR DISPLAY, HOME CURSOR

; SET ENTRY MODE

;********************************************************************************************* ***** ; SUB RECEIVES A COMMAND WORD TO THE LCD ; COMMAND MUST BE PLACED IN R4 BY CALLING PROGRAM

72

;********************************************************************************************* ***** WRLCDCOM4: CLR CLR PUSH MOV MOV MOV MOV MOV MOV MOV MOV MOV SETB CLR MOV MOV MOV MOV MOV MOV LCD_E LCD_RS ACC A, R4 C, ACC.4 LCD_DB4, C C, ACC.5 LCD_DB5, C C, ACC.6 LCD_DB6, C C, ACC.7 LCD_DB7, C LCD_E LCD_E C, ACC.0 LCD_DB4, C C, ACC.1 LCD_DB5, C C, ACC.2 LCD_DB6, C ; SIMILARLY, LOAD LOW NIBBLE ; PULSE THE ENABLE LINE ; SELECT READ COMMAND ; SAVE ACCUMULATOR ; PUT DATA BYTE IN ACC ; LOAD HIGH NIBBLE ON DATA BUS ; ONE BIT AT A TIME USING... ; BIT MOVE OPERATOINS

73

MOV MOV CLR SETB CLR CALL POP RET

C, ACC.3 LCD_DB7, C LCD_E LCD_E LCD_E DELAY ACC ; PULSE THE ENABLE LINE

;********************************************************************************************* ***** ; SUB TO RECEIVE A DATA WORD TO THE LCD ; DATA MUST BE PLACED IN R4 BY CALLING PROGRAM ;********************************************************************************************* ***** WRLCDDATA: CLR SETB LCD_E LCD_RS PUSH MOV MOV MOV MOV MOV MOV A, R4 C, ACC.4 LCD_DB4, C C, ACC.5 LCD_DB5, C C, ACC.6 ACC ; SELECT READ DATA ; SAVE ACCUMULATOR ; PUT DATA BYTE IN ACC ; LOAD HIGH NIBBLE ON DATA BUS ; ONE BIT AT A TIME USING... ; BIT MOVE OPERATOINS

74

MOV MOV MOV SETB CLR MOV MOV MOV MOV MOV MOV MOV MOV CLR SETB CLR NOP NOP POP RET

LCD_DB6, C C, ACC.7 LCD_DB7, C LCD_E LCD_E C, ACC.0 LCD_DB4, C C, ACC.1 LCD_DB5, C C, ACC.2 LCD_DB6, C C, ACC.3 LCD_DB7, C LCD_E LCD_E LCD_E ; PULSE THE ENABLE LINE ; SIMILARLY, LOAD LOW NIBBLE ; PULSE THE ENABLE LINE

ACC

;********************************************************************************************* *****

75

; SUB TAKES THE STRING IMMEDIATELY FOLLOWING THE CALL AND ; DISPLAYS ON THE LCD. STRING MUST BE TERMINATED WITH A ; NULL (0). ;********************************************************************************************* ***** LCD_MSG: CLR A ; CLEAR INDEX ; GET BYTE POINTED BY DPTR ; POINT TO THE NEXT BYTE LCD_MSG9 ; RETURN IF FOUND THE ZERO (END OF

MOVC A,@A+DPTR INC JZ STRINGZ) CJNE A,#01H,LCD_MSG1 MOV CALL JMP R4,A WRLCDCOM4 LCD_MSG DPTR

; CHECK IF IS A CLEAR COMMAND

;IF YES, RECEIVE IT AS COMMAND TO LCD ;GO GET NEXT BYTE FROM STRINGZ

LCD_MSG1: CJNE MOV CALL JMP A,#0FFH,FLL R4,A WRLCDDATA LCD_MSG ;CHECK FOR DISPLAYING FULL CHARACTER

FLL:

CJNE

A,#080H,$+3 JC LCD_MSG_DATA

; DATA OR ADDRESS? IF => 80H THEN IS ADDRESS. ; CARRY WILL BE SET IF A < 80H (DATA)

76

MOV CALL JMP

R4,A WRLCDCOM4 LCD_MSG ; CARRY NOT SET IF A=>80, IT IS ADDRESS ; GO GET NEXT BYTE FROM STRINGZ

LCD_MSG_DATA: MOV CALL JMP R4,A WRLCDDATA LCD_MSG ; IT WAS DATA, RECEIVE IT TO LCD ; GO GET NEXT BYTE FROM STRINGZ

LCD_MSG9: RET ; RETURN TO CALLER

;********************************************************************************************* ***** ;********************************************************************************************* ***** M_SND: MOV ACALL MOV ACALL RET ;--------------------------------------------------------------------------------------------------------------DIAL: DPTR,#SND SENDSTRING DPTR,#SND1 SENDSTRING

77

MOV ACALL RET

DPTR,#PHONENUM SENDSTRING

;--------------------------------------------------------------------------------------------------------------SENDSTRING: CLR A

MOVC A,@A+DPTR JZ ACALL INC SJMP GO: RET SEND DPTR SENDSTRING GO

STRING: CLR A

MOVC A,@A+DPTR JZ MOV CALL INC SJMP RET R4,A WRLCDDATA DPTR SENDSTRING ; IT WAS DATA, RECEIVE IT TO LCD GO

78

;--------------------------------------------------------------------------------------------------------------SEND: HERE: MOV JNB SBUF,A TI,HERE CLR RET ;--------------------------------------------------------------------------------------------------------------RCV: JNB MOV CLR RET ;--------------------------------------------------------------------------------------------------------------CLEAR_M: MOV ACALL CALL CALL MOV ACALL CALL CALL MOV ACALL CALL DPTR,#DEL1 SENDSTRING HALF_SEC HALF_SEC DPTR,#DEL2 SENDSTRING HALF_SEC HALF_SEC DPTR,#DEL3 SENDSTRING HALF_SEC RI, $ A, SBUF RI TI ;LOAD THE DATA ;STAY UNTIL LAST BIT SENT ;GET READY FOR NEXT CHARACTER

79

CALL MOV ACALL CALL CALL MOV ACALL CALL CALL

HALF_SEC DPTR,#DEL4 SENDSTRING HALF_SEC HALF_SEC DPTR,#DEL5 SENDSTRING HALF_SEC HALF_SEC

RET

;********************************************************************************************* ***** ;********************************************************************************************* ***** DISPLAY: MOV CALL RET DPTR,#MSAG1 LCD_MSG

MSAG1: DB 1H,80H,"SCADA for X'MER",0C0H,'T: V: C: ',00H

80

;-------------------------------------------------------------------------------------------------------------------------TEMPR: MOV CALL RET DPTR,#MSAG2 LCD_MSG

MSAG2: DB 80H,'OVER TEMPERATURE',00H

;-------------------------------------------------------------------------------------------------------------------------O_V: MOV CALL RET DPTR,#MSAG3 LCD_MSG

MSAG3: DB 80H,' OVER VOLTAGE ',00H

;-------------------------------------------------------------------------------------------------------------------------U_V: MOV CALL RET DPTR,#MSAG4 LCD_MSG

MSAG4:

81

DB

80H,' UNDER VOLTAGE ',00H

;-------------------------------------------------------------------------------------------------------------------------NOR: MOV CALL RET DPTR,#MSAG5 LCD_MSG

MSAG5: DB 80H," ",00H

;********************************************************************************************* ***** DELAYS: MOV D1: CALL DJNZ RET ;-------------------------------------------------------------------------------------------------------------------------DELAY1: MOV HDH: HD: MOV R6,#100 NOP NOP R7,#200 ;100MS DELAY R5,#10 DELAY1 R5,D1 ;1S DELAY

82

NOP DJNZ DJNZ RET ;-------------------------------------------------------------------------------------------------------------------------HALF_SEC: PUSH 00 PUSH PUSH MOV HAF_SEC1: HAF_SEC2: BACK: MOV MOV DJNZ 01 02 R6,HD R7,HDH

R2, #0AH R1, #64H R0, #0FFH R0, BACK DJNZ R1, HAF_SEC2

DJNZ POP

R2, HAF_SEC1 02 POP POP 01 00

RET

;-------------------------------------------------------------------------------------------------------------------------MDELAY: PUSH MOV ACC A,#0A6H

83

MD_OLP: INC NOP NOP NOP NOP NOP NOP NOP NOP JNZ NOP POP RET ACC MD_OLP A

;------------------------------------------------------------------------------------------------------------------------MADELAY: PUSH MOV ACC A,#036H

MAD_OLP: INC NOP A

84

NOP NOP NOP NOP NOP NOP NOP JNZ NOP POP RET ACC MAD_OLP

;--------------------------------------------------------------------------------------------------------DELAY_16MS: PUSH PUSH MOV D_LOOP1: D_LOOP2: MOV DJNZ R1, #255 R1, D_LOOP2 DJNZ POP POP RET R0, D_LOOP1 01 00 00 01 R0, #30

85

;--------------------------------------------------------------------------------------------------------DELAY: PUSH 07 PUSH MOV W2: W1: MOV DJNZ DJNZ POP POP RET ;--------------------------------------------------------------------------------------------------------; ASCII LOOK-UP TABLE 06 R7, #5H

R6, #00H R6, W1 R7, W2 06 07

;--------------------------------------------------------------------------------------------------------POWER: DB "SYSTEM IS READY...!", 1AH, 0

PHONENUM: DB 'ATD9731046147;', CR, LF, 0

SND: SND1:

DB DB

'AT+CMGF=1', CR, LF, 0 'AT+CMGS=', 22H, '7204143868', 22H, CR, LF, 0

PMP_ON: PMP_OFF:

DB DB

'WATER LEVEL LOW', 1AH, 0 'WATER LEVEL HIGH', 1AH, 0

86

VLV1_CL: VLV1_OP:

DB DB

'VALVE-1 OPEN', 1AH, 0 'VALVE-1 CLOSE', 1AH, 0

VLV2_CL: VLV2_OP:

DB DB

'VALVE-2 OPEN', 1AH, 0 'VALVE-2 CLOSE', 1AH, 0

RED:

DB

'AT+CMGR=1', CR, LF, 0

DEL1: DEL2: DEL3: DEL4: DEL5: DEL6: DEL7: DEL8: DEL9:

DB DB DB DB DB DB DB DB DB

'AT+CMGD=1', CR, LF, 0 'AT+CMGD=2', CR, LF, 0 'AT+CMGD=3', CR, LF, 0 'AT+CMGD=4', CR, LF, 0 'AT+CMGD=5', CR, LF, 0 'AT+CMGD=6', CR, LF, 0 'AT+CMGD=7', CR, LF, 0 'AT+CMGD=8', CR, LF, 0 'AT+CMGD=9', CR, LF, 0

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

Circuit Symbols
Circuit symbols are used in circuit diagrams which show how a circuit is connected together. The actual layout of the components is usually quite different from the circuit diagram. To build a circuit you need a different diagram showing the layout of the parts on strip board or printed circuit board.

Resistors Component Circuit Symbol Function of Component A resistor restricts the flow of current, Resistor for example to limit the current passing through an LED. A resistor is used with a capacitor in a timing circuit. This type of variable resistor with 2 contacts (a rheostat) is usually used to Variable Resistor (Rheostat) control current. Examples include: adjusting lamp brightness, adjusting motor speed, and adjusting the rate of flow of charge into a capacitor in a

106

timing circuit. This type of variable resistor with 3 contacts (a potentiometer) is usually Variable Resistor (Potentiometer) used to control voltage. It can be used like this as a transducer converting position (angle of the control spindle) to an electrical signal. This type of variable resistor (a preset) is operated with a small screwdriver or similar tool. It is designed to be set Variable Resistor (Preset) when the circuit is made and then left without further adjustment. Presets are cheaper than normal variable resistors so they are often used in projects to reduce the cost. Capacitors Component Circuit Symbol Function of Component A capacitor stores electric charge. A capacitor is used with a resistor in a Capacitor timing circuit. It can also be used as a filter, to block DC signals but pass AC signals.

107

A capacitor stores electric charge. This type must be connected the Capacitor, polarized correct way round. A capacitor is used with a resistor in a timing circuit. It can also be used as a filter, to block DC signals but pass AC signals. A variable capacitor is used in a radio tuner. This type of variable capacitor (a trimmer) is operated with a small Trimmer Capacitor screwdriver or similar tool. It is designed to be set when the circuit is made and then left without further adjustment. Diodes Component Circuit Symbol Function of Component A device which only allows current to flow in one direction. A transducer which converts electrical energy to light. A special diode which is used to maintain a fixed voltage across its

Variable Capacitor

Diode

LED Light Emitting Diode

Zener Diode

108

terminals.

Photodiode

A light-sensitive diode.

Transistors Component Circuit Symbol Function of Component A transistor amplifies current. It can be used with Transistor NPN other components to make an amplifier or switching circuit. A transistor amplifies current. It can be used with Transistor PNP other components to make an amplifier or switching circuit.

Pezos Transducer

A transducer which converts electrical energy to sound. An amplifier circuit with one input. Really

Amplifier (general symbol)

it is a block diagram symbol because it represents a circuit rather than just one component.

109

Earphone

A transducer which converts electrical energy to sound.

110

Books

Electronics projects September 2004 edition Principal of electronics By. V.K. Mehta, Electronics devices and circuits By. J.B. Gupta, Computer fundamental By. B. Ram

Web site

www.google.com www.efy.com 111

www.electronicslab.com www.electronicsproject.com

112

You might also like