Professional Documents
Culture Documents
Dissertation submitted in partial fulfillment of the Academic requirements for the award of
Bachelor of Technology In Electronics and Communication Engineering By G.Sujitha sree (Roll no.08X81A0443) T.Santhosh (Roll no.08X81A0432) Y.Dinesh (Roll no.08X81A0407) Under the Guidance of Mr.CH.Rajendra Prasad Asst. Prof. Dept. of ECE
Department of Electronics & Communication Engineering Sri Sarada Institute of Science & Technology (Affiliated to Jawaharlal Nehru Technological University) Anantharam 2010-2011
Department of Electronics & Communication Engineering Sri Sarada Institute of Science & Technology
(Approved by AICTE, Recognized by Govt. of A.P. and Affiliated to J.N.T.U.H, Hyderabad.) Anantharam (V), Near Bibinagar, Bhongir (M), Nalgonda (Dist).
Certificate
This is to certify that the project work titled Time Opareted Electrical Applicance Controlling System For Industrial Application submitted by M.sujitha Sree, T.Santhosh, Y.Dinesh the students of Department of ECE, Sri Sarada institute of science and technology, JNTUH in partial fulfillment of the requirements for award of the degree of Bachelor of Technology is a record of the bonafide work carried out by them during the academic year 2010-2011.
Head of the Department Mr.CH.Rambabu Assistant Professor Dept. of ECE SSIST External Examiner
Declaration
This is to certify that the work reported in the present thesis titled Time Opareted Electrical Applicance Controlling System For Industrial Application is a record of work done by us in the Department of Electronics and communication Engineering (ECE), Sarada Institute of Science And Technology, JNTUH No part of the thesis is copied from books/Journals/Internet and wherever the portion is taken, the same has been duly referred in the text. The reported are based on the project work done entirely by us and not copied from any other source.
Acknowledgements
We are extremely thankful to our internal guide Mr. CH.Rajendra Prasad Asst. Prof. in ECE Department, Sri Sarada institute of science and technology, for his excellent guidance and constant encouragement throughout the project work. It was a pleasant and challenging experience to work under his supervision. Her constant monitoring and the valuable advices ensured the completion of this thesis. We thank to his for setting high standards and motivating us to do our best. We wish to express our sincere thanks to Mr. CH. Rajendra Prasad, Asst. Prof. for his valuable advices make confident that the completion of this Project work. We wish to express our gratitude to Mr. CH. Ram Babu, HOD of ECE, for permitting to do our project work at Department. We take this opportunity to acknowledge our college principal Prof. Ravindranath, with deep sense of gratitude for their support and encouragement. We express my heartfelt gratitude to my family members, who patiently cooperated and constantly supported for the successful completion. Last but not the least; we would like to thank friends and well wishers for their direct and indirect help.
3.
COMPONENT DESCRIPTION
3.1. AT89S52 3.2. DS1307 3.3. 74LS21 3.4. TRANSISTOR AS A SWITCH 3.5. SPDT RELAY 3.6. ISP PROGRAMMER 29 41 54 57 60 67
4.
70 71 92 94 95
5. 6. 7. 8.
List of figures 1. Fig 3.1-PIN CONFIGURATION 40-lead PDIP(AT89S52) 2. Fig 3.2- ARCHITECTURE of AT89S52 3. Fig 3.3-INTERNAL BLOCK DIAGRAM OF AT89S52 4. Fig 3.4-OSCILLATOR\ 5. Fig 3.5-PIN DESCRIPTION OF DS1307 6. Fig 3.6-CIRCUIT DESCRIPTION OF DS1307 7. Fig 3.7- BLOCK DIAGRAM OF DS1307 8. Fig 3.8-TIME KEEP DESCRIPTION OF DS1307 9. Fig 3.9-TWO WIRE CONFIGURATION OF DS1307 10. 11. 12. 13. 14. 15. 16.
Fig 3.10- DATA TRANSFER ON 2-WIRE SERIAL BUS 52 Fig 3.11- PIN DESCRIPTION OF 74LS21 55 Fig 3.12-CONNECTION OF 74LS21 55 Fig 3.13-TRANSISTOR CURVES 57
Fig 3.14-TRANSISTOR SWITCHING CIRCUIT 58 Fig 3.15-SPDT RELAY 63 Fig 3.16-ISP PROGRAMMER 66 66
33 34 39 40 41 43 44 48 50
67
ABSTRACT
It is well known that the electrical appliances are more useful in every day life. Industries are not small. It is very difficult to monitor overall industry with in short time, so if we are implementing one embedded product which will solve our problem. One more option is power wastage. In some cases industries devices are in ON state even though it is not required. That leads power wastage. To save the power if we are implementing one circuit that is more useful. There are different ways available to implement such type of applications. In that, one option is time based control.
To implement this application time is more important. For that we have to interface RTC to the microcontroller. In this application we are interfacing DS1307 (RTC) to get the real-time clock. To read the time from the DS1307 user has to develop I2C protocol logic in the microcontroller. After reading data from the RTC that data is applied on the LCD. But that is not our application now. To implement our exact requirement we have to select ON time and OFF time. For selecting the ON time and OFF time one more switch is placed. Once ON time and OFF time is selected whenever that time reaches electrical appliance is ON with the help of relay. And electrical appliance is OFF whenever it reaches to OFF time, so that we can save the power.
BLOCK DIAGRAM:
SEL INC
LCD
DEC
7 4 L S 2 1
AT89S52
SPDT RELAY
AC DEVICE
EXIT
DS1307 8
HARDWARE:
AT89S52 microcontroller 16X2 LCD 74LS21 DS1307 SPDT RELAY AC DEVICE
SOFTWARE:
KEIL C-Compiler PROGRAMMING IN EMBEDDED C
2.INTRODUCTION
2.1 EMBEDDED SYSTEMS
Embedded systems are electronic devices that incorporate microprocessors with in their implementations. The main purposes of the microprocessors are to simplify the system design and provide flexibility. Having a microprocessor in the device helps in removing the bugs, making modifications, or adding new features are only matter of rewriting the software that controls the device. Or in other words embedded computer 9
systems are electronic systems that include a microcomputer to perform a specific dedicated application. The computer is hidden inside these products. Embedded systems are ubiquitous. Every week millions of tiny computer chips come pouring out of factories finding their way into our everyday products. Embedded systems are self-contained programs that are embedded within a piece of hardware. Whereas a regular computer has many different applications and software that can be applied to various tasks, embedded systems are usually set to a specific task that cannot be altered without physically manipulating the circuitry. Another way to think of an embedded system is as a computer system that is created with optimal efficiency, thereby allowing it to complete specific functions as quickly as possible. Embedded systems designers usually have a significant grasp of hardware technologies. They use specific programming languages and software to develop embedded systems and manipulate the equipment. When searching online, companies offer embedded systems development kits and other embedded systems tools for use by engineers and businesses. Embedded systems technologies are usually fairly expensive due to the necessary development time and built in efficiencies, but they are also highly valued in specific industries. Smaller businesses may wish to hire a consultant to determine what sort of embedded systems will add value to their organization.
2.1.1 CHARACTERISTICS:
Two major areas of differences are cost and power consumption. Since many embedded systems are produced in tens of thousands to millions of units range, reducing cost is a major concern. Embedded systems often use a (relatively) slow processor and small memory size to minimize costs. The slowness is not just clock speed. The whole architecture of the computer is often intentionally simplified to lower costs. For example, embedded systems often use peripherals controlled by synchronous serial interfaces, which are ten to hundreds of times slower than comparable peripherals used in PCs. Programs on an embedded system 10
often run with real-time constraints with limited hardware resources: often there is no disk drive, operating system, keyboard or screen. A flash drive may replace rotating media, and a small keypad and LCD screen may be used instead of a PC's keyboard and screen. Firmware is the name for software that is embedded in hardware devices, e.g. in one or more ROM/Flash memory IC chips. Embedded systems are routinely expected to maintain 100% reliability while running continuously for long periods, sometimes measured in years. Firmware is usually developed and tested too much harsher requirements than is general-purpose software, which can usually be easily restarted if a problem occurs.
2.1.2 PLATFORM:
There are many different CPU architectures used in embedded designs. This in contrast to the desktop computer market which is limited to just a few competing architectures mainly the Intel/AMD x86 and the Apple/Motorola/IBM Power PCs which are used in the Apple Macintosh. One common configuration for embedded systems is the system on a chip, an application-specific integrated circuit, for which the CPU was purchased as intellectual property to add to the IC's design.
2.1.3 TOOLS:
Like a typical computer programmer, embedded system designers use compilers, assemblers and debuggers to develop an embedded system. Those software tools can come from several sources: Software companies that specialize in the embedded market Ported from the GNU software development tools. Sometimes, development tools for a personal computer can be used if the embedded processor is a close relative to a common PC processor. Embedded system designers also use a few software tools rarely used by typical computer programmers. Some designers keep a utility program to turn data files into code, so that they can include any kind of data in a program. Most designers also 11
have utility programs to add a checksum or CRC to a program, so it can check its program data before executing it.
2.1.5 DEBUGGING:
Debugging is usually performed with an in-circuit emulator, or some type of debugger that can interrupt the micro controllers internal microcode. The microcode interrupt lets the debugger operate in hardware in which only the CPU works. The CPUbased debugger can be used to test and debug the electronics of the computer from the viewpoint of the CPU. Developers should insist on debugging which shows the high-level language, with breakpoints and single stepping, because these features are widely available. Also, developers should write and use simple logging facilities to debug sequences of real-time events. PC or mainframe programmers first encountering this sort of programming often become confused about design priorities and acceptable methods. Mentoring, codereviews and ego less programming are recommended.
2.1.7START-UP:
All embedded systems have start-up code. Usually it disables interrupts, sets up the electronics, tests the computer (RAM, CPU and software), and then starts the application code. Many embedded systems recover from short-term power failures by restarting (without recent self-tests). Restart times under a tenth of a second are common.
12
Many designers have found one of more hardware plus softwarecontrolled LEDs useful to indicate errors during development (and in some instances, after product release, to produce troubleshooting diagnostics). A common scheme is to have the electronics turn off the LED(s) at reset, whereupon the software turns it on at the first opportunity, to prove that the hardware and start-up software have performed their job so far. After that, the software blinks the LED(s) or sets up light patterns during normal operation, to indicate program execution progress and/or errors. This serves to reassure most technicians/engineers and some users.
13
Complex functions like internal combustion controls are often handled with multidimensional tables. Instead of complex calculations, the code looks up the values. The software can interpolate between entries, to keep the tables small and cheap. One major disadvantage of this system is that it does not guarantee a time to respond to any particular hardware event. Careful coding can easily assure that nothing disables interrupts for long. Thus interrupt code can run at very precise timings. Another major weakness of this system is that it can become complex to add new features. Algorithms that take a long time to run must be carefully broken down so only a little piece gets done each time through the main loop. This system's strength is its simplicity, and on small pieces of software the loop is usually so fast that nobody cares that it is not predictable. Another advantage is that this system guarantees that the software will run. There is no mysterious operating system to blame for bad behavior.
2.1.9USER INTERFACES:
Interface designers at PARC, Apple Computer, Boeing and HP minimize the number of types of user actions. For example, use two buttons (the absolute minimum) to control a menu system (just to be clear, one button should be "next menu entry" the other button should be "select this menu entry"). A touch-screen or screen-edge buttons also minimize the types of user actions. Another basic trick is to minimize and simplify the type of output. Designs should consider using a status light for each interface plug, or failure condition, to tell what failed. A cheap variation is to have two light bars with a printed matrix of errors that they select- the user can glue on the labels for the language that she speaks. For example, Boeing's standard test interface is a button and some lights. When you press the button, all the lights turn on. When you release the button, the lights with failures stay on. The labels are in Basic English. Designers use colors. Red defines the users can get hurt- think of blood. Yellow defines something might be wrong. Green defines everything's OK.
14
Another essential trick is to make any modes absolutely clear on the user's display. If an interface has modes, they must be reversible in an obvious way. Most designers prefer the display to respond to the user. The display should change immediately after a user action. If the machine is going to do anything, it should start within 7 seconds, or give progress reports. One of the most successful general-purpose screen-based interfaces is the two menu buttons and a line of text in the user's native language. It's used in pagers, mediumpriced printers, network switches, and other medium-priced situations that require complex behavior from users. When there's text, there are languages. The default language should be the one most widely understood.
2.2 MICROCONTROLLERS
Microcontrollers as the name suggests are small controllers. They are like single chip computers that are often embedded into other systems to function as processing/controlling unit. For example the remote control you are using probably has microcontrollers inside that do decoding and other controlling functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where automation is needed. 15
Micro-controllers are useful to the extent that they communicate with other devices, such as sensors, motors, switches, keypads, displays, memory and even other micro-controllers. Many interface methods have been developed over the years to solve the complex problem of balancing circuit design criteria such as features, cost, size, weight, power consumption, reliability, availability, manufacturability. Many microcontroller designs typically mix multiple interfacing methods. In a very simplistic form, a micro-controller system can be viewed as a system that reads from (monitors) inputs, performs processing and writes to (controls) outputs. Embedded system means the processor is embedded into the required application. An embedded product uses a microprocessor or microcontroller to do one task only. In an embedded system, there is only one application software that is typically burned into ROM. Example: printer, keyboard, video game player Microprocessor - A single chip that contains the CPU or most of the computer Microcontroller - A single chip used to control other devices Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.
Designer can decide on the amount of ROM, RAM and I/O ports. expensive versatility general-purpose
Microcontroller:
CPU, RAM, ROM, I/O and timer are all on a single chip fix amount of on-chip ROM, RAM, I/O ports for applications in which cost, power and space are critical single-purpose
lightweight construction, its portability, and its ability to be produced in much larger screen sizes than are practical for the construction of cathode ray tube (CRT) display technology. Its low electrical power consumption enables it to be used in battery-powered electronic equipment. It is an electronically-modulated optical device made up of any number of pixels filled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produce images in color or monochrome. The earliest discovery leading to the development of LCD technology, the discovery of liquid crystals, dates from 1888. By 2008, worldwide sales of televisions with LCD screens had surpassed the sale of CRT units.
18
PIN DESCRIPTION:
PIN 1 2 3 4 5 6 7 8 9 10 11 12 13 14 SYMBOL VSS VCC VEE RS R/W EN DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 I/O ---I I I/O I/O I/O I/O I/O I/O I/O I/O I/O 19 DESCRIPTION Ground +5V power supply Power supply to control contrast RS=0 to select command register RS=1 to select data register R/W=0 for write R/W=1 for read Enable The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus
RS (REGISTER SELECT):
There are two important registers inside the LCD. When RS is low (0), the data is to be treated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data that is sent is a text data which should be displayed on the screen. For example, to display the letter "T" on the screen you would set RS high.
RW (READ/WRITE):
The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are write commands, so RW will almost be low.
EN (ENABLE):
The EN line is called "Enable". This control line is used to tell the LCD that you are sending it data. To send data to the LCD, your program should first set this line high (1) and then set the other two control lines and/or put data on the data bus. When the other lines are completely ready, bring EN low (0) again. The 1-0 transition tells the 44780 to take the data currently found on the other control lines and on the data bus and to treat it as a command.
There are also instruction command codes that can be sent to the LCD to clear the display or force the cursor to the home position or blink the cursor. We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive the information. The busy flag is D7 and can be read when R/W = 1 and RS=0, as follows: if R/W = 1, RS = 0. When D7=1 (busy flag = 1), the LCD is busy taking care of internal operations and will not accept any new information. When D7 = 0, the LCD is ready to receive new information. Note: it is recommended to check the flag before writing any data to LCD.
16x2 LCD
80 C0 20x1 LCD 80 20x2 LCD 80 C0 20x4 LCD 80 C0 94 D4 40x2 LCD 80 C0 NOTE: All data is in HEX.
81 C1 81 81 C1 81 C1 95 D5 81 C1
82 C2 82 82 C2 82 C2 96 D6 82 C2
83 C3 83 83 C3 83 C3 97 D7 83 C3
86 C6 93 93 D3 93 D3 A7 E7 A7 E7
through through
8F CF
2.3.4ADVANTAGES:
LCD interfacing with 8051 is a real-world application. In recent years the LCD is finding widespread use replacing LEDs (seven segment LEDs or other multi segment LEDs). This is due to following reasons: The declining prices of LCDs. The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters. An intelligent LCD displays two lines, 20 characters per line, which is interfaced to the 8051. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU to keep displaying the data. Ease of programming for characters and graphics.
Like a normal diode, the LED consists of a chip of semi-conducting material impregnated, or doped, with impurities to create a p-n junction. As in other diodes, current flows easily from the p-side, or anode, to the n-side, or cathode, but not in the reverse direction. Charge-carrierselectrons and holesflow into the junction from electrodes with different voltages. When an electron meets a hole, it falls into a lower energy level, and releases energy in the form of a photon.
23
The wavelength of the light emitted, and therefore its color, depends on the band gap energy of the materials forming the p-n junction. In silicon or germanium diodes, the electrons and holes recombine by a non-radiative transition which produces no optical emission, because these are indirect band gap materials. The materials used for the LED have a direct band gap with energies corresponding to near-infrared, visible or near-ultraviolet light. LED development began with infrared and red devices made with gallium arsenide. Advances in materials science have made possible the production of devices with ever-shorter wavelengths, producing light in a variety of colors. LEDs are usually built on an n-type substrate, with an electrode attached to the p-type layer deposited on its surface. P-type substrates, while less common, occur as well. Many commercial LEDs, especially GaN/InGaN, also use sapphire substrate. Most materials used for LED production have very high refractive indices. This means that much light will be reflected back in to the material at the material/air surface interface. Therefore Light extraction in LEDs is an important aspect of LED production, subject to much research and development. Solid state devices such as LEDs are subject to very limited wear and tear if operated at low currents and at low temperatures. Many of the LEDs produced in the
24
1970s and 1980s are still in service today. Typical lifetimes quoted are 25,000 to 100,000 hours but heat and current settings can extend or shorten this time significantly. Conventional LEDs are made from a variety of inorganic semiconductor materials; the following table shows the available colors with wavelength range and voltage drop. Color Infrared Red Orange Yellow Green Blue Violet Purple Ultraviolet White Wavelength (nm) > 760 610 < < 760 590 < < 610 570 < < 590 500 < < 570 450 < < 500 400 < < 450 multiple types < 400 Broad spectrum Voltage (V) V < 1.9 1.63 < V < 2.03 2.03 < V < 2.10 2.10 < V < 2.18 1.9 < V < 4.0 2.48 < V < 3.7 2.76 < V < 4.0 2.48 < V < 3.7 3.1 < V < 4.4 V = 3.5
25
The main advantage is efficiency. In conventional incandescent bulbs, the lightproduction process involves generating a lot of heat (the filament must be warmed). Unless you're using the lamp as a heater, because a huge portion of the available electricity isn't going toward producing visible light.
LEDs generate very little heat. A much higher percentage of the electrical power is going directly for generating light, which cuts down the electricity demands considerably.
LEDs offer advantages such as low cost and long service life. Moreover LEDs have very low power consumption and are easy to maintain.
them from their Websites. However, the size of code for these shareware versions is limited and we have to consider which assembler is suitable for our application.
(For example, \C166\EXAMPLES\HELLO\HELLO.UV2) assembles, and links the files in your project.
Create source files to add to the project. Select Project - Targets, Groups, and Files. Add/Files, select Source Select Project - Options and set the tool options. Note when you select the
Group1, and add the source files to the project. target device from the Device Database all-special options are set automatically. You only need to configure the memory map of your target hardware. Default memory model settings are optimal for most.
2.5.4APPLICATIONS:
Select Project - Rebuild all target files or Build target. 28
may enter G, main in the Output Window to execute to the main C function.
4) Crystal circuit 5) ISP circuit (for program dumping) 6) EA/VPP pin is connected to Vcc.
3.1.1 FEATURES:
Compatible with MCS-51 Products 8K Bytes of In-System Programmable (ISP) Flash Memory -Endurance: 1000 Write/Erase Cycles 4.0V to 5.5V Operating Range Fully Static Operation: 0 Hz to 33 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 Full Duplex UART Serial Channel
30
31
3.1.2 DESCRIPTION:
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and 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 in-system programmable Flash on a monolithic chip, the Atmel 89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, onchip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.[1]
32
fig. 3.1
33
3.1.4 ARCHITECTURE:
Fig.3.2
34
GND:
Ground.
Port 0:
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pull-ups are required during program verification.
Port 1:
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. 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 pull-ups 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.
35
Port Pin
P1.0 P1.1 P1.5 P1.6 P1.7
Alternate Functions
T2(external count to Timer/Counter 2), clock-out T2EX(Timer/Counter 2 capture/reload trigger and direction control) MOSI (used for In-System Programming) MISO(used for In-System Programming) SCK(used for In-System Programming)
Port 2:
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. 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 pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pullups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 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 bidirectional I/O port with internal pull-ups. 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 pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for Flash programming and verification. Port 3 also serves the functions of various special features of the AT89S52, as shown in the following table.
36
Port Pin
P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7
Alternate Functions
RXD (serial Input port) TXD (serial output port) INT0 bar (external Interrupt 0) INT1 bar (external Interrupt 1) T0 (timer 0 external Input) T1 (timer 1 external input) WR bar (external data memory write strobe) RD bar (external data memory read strobe)
RST:
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.
:
Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG bar) 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. 37
Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.
:
Program Store Enable (PSEN BAR) is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN BAR is activated twice each machine cycle, except that two PSEN BAR activations are skipped during each access to external data memory.
:
External Access Enable. EA BAR must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA BAR will be internally latched on reset. EA BAR should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming.
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL2:
Output from the inverting oscillator amplifier
38
INTERRUPT CONTROL
TIMER 1 TIMER 0
COUNTER INPUTS
OSC
P0 P1 P2 P3 Fig.3.3
Tx
Rx
shown in below Figure 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 flipflop, but minimum and maximum voltage high and low time specifications must be observed.[2]
Idle Mode:
In idle mode, the CPU puts itself to sleep while all the on-chip peripherals remain active. The mode is invoked by software. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset.
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. Exit from Power-down mode can be initiated either by a hardware reset or by an enabled external interrupt. Reset redefines the SFRs but does not change the on-chip RAM. The reset should not 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.[3]
Oscillator Connections:
40
41
Fig.3.5
42
3.2.4 DESCRIPTION:
The DS1307 Serial Real-Time Clock is a low-power; full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially via a 2-wire, bi-directional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power sense circuit that detects power failures and automatically switches to the battery supply.[1]
43
Fig.3.6
3.2.6 OPERATION:
The DS1307 operates as a slave device on the serial bus. Access is obtained by implementing a START condition and providing a device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STOP condition is executed. When VCC falls below 1.25 x VBAT the device terminates an access in progress and resets the device address counter. Inputs to the device will not be recognized at this time to prevent erroneous data from being written to the device from an out of tolerance system. When VCC falls below VBAT the device switches into a lowcurrent battery backup mode. Upon power-up, the device switches from battery to VCC when VCC is greater than VBAT + 0.2V and recognizes inputs when VCC is greater than 1.25 x VBAT. The above diagram shows the main elements of the serial RTC. 44
Fig.3.7
VBAT:
Battery input for any standard 3V lithium cell or other energy source. Battery voltage must be held between 2.0V and 3.5V for proper operation. The nominal write 45
protect trip point voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal. A lithium battery with 48mAhr or greater will back up the DS1307 for more than 10 years in the absence of power at 25C. UL recognized to ensure against reverse charging current when used in conjunction with a lithium battery.
X1, X2:
Connections for a standard 32.768 kHz quartz crystal. The internal oscillator circuitry is designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF.
CLOCK ACCURACY:
The accuracy of the clock is dependent upon the accuracy of the crystal and the accuracy of the match between the capacitive load of the oscillator circuit and the capacitive load for which the crystal was trimmed. Additional error will be added by crystal frequency drift caused by temperature shifts. External circuit noise coupled into the oscillator circuit may result in the clock running fast. 46
The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12- or 24-hour mode select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with logic high being PM. In the 24-hour mode, bit 5 is the second 10 hour bit (20- 23 hours). On a 2-wire START, the current time is transferred to a second set of registers. The time information is read from these secondary registers, while the clock may continue to run. This eliminates the need to reread the registers in case of an update of the main registers during a read.
.Fig.3.8
48
CONTROL REGISTER:
The DS1307 control register is used to control the operation of the SQW/OUT pin.
RS (Rate Select):
These bits control the frequency of the square wave output when the square wave output has been enabled. Table below lists the square wave frequencies that can be selected with the RS bits.
49
Fig.3.9
Data transfer may be initiated only when the bus is not busy.
50
During data transfer, the data line must remain stable whenever the clock line is HIGH. Changes in the data line while the clock line is high will be interpreted as control signals. Accordingly, the following bus conditions have been defined:
DATA VALID:
The state of the data line represents valid data when, after a START condition, the data line is stable for the duration of the HIGH period of the clock signal. The data on the line must be changed during the LOW period of the clock signal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and terminated with a STOP condition. The number of data bytes transferred between START and STOP conditions is not limited, and is determined by the master device. The information is transferred byte-wise and each receiver acknowledges with a ninth bit. Within the 2-wire bus specifications a regular mode (100 kHz clock rate) and a fast mode (400 kHz clock rate) are defined. The DS1307 operates in the regular mode (100 kHz) only.
ACKNOWLEDGE:
51
Each receiving device, when addressed, is obliged to generate acknowledge after the reception of each byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit. A device that acknowledges must pull down the SDA line during the acknowledge clock pulse in such a way that the SDA line is stable LOW during the HIGH period of the acknowledge related clock pulse. Of course, setup and hold times must be taken into account. A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that has been clocked out of the slave. In this case, the slave must leave the data line HIGH to enable the master to generate the STOP condition.
Fig.3.10
Depending upon the state of the R/W bit, two types of data transfer are possible:
52
54
3.3.1GENERAL DESCRIPTION:
This device contains two independent gates each of which performs the logic AND function.
55
Fig 3.12
[5]
H - High Logic Level L - Low Logic Level X - Either Low or High Logic Level
The transistor is the fundamental building block of modern electronic devices, and its presence is ubiquitous in modern electronic systems. Because a transistor's collector current is proportionally limited by its base current, it can be used as a sort of current-controlled switch. A relatively small flow of electrons sent through the base of the transistor has the ability to exert control over a much larger flow of electrons through the collector. When used as an AC signal amplifier, the transistors Base biasing voltage is applied so that it operates within its "Active" region and the linear part of the output characteristics curves are used. However, both the NPN & PNP type bipolar transistors can be made to operate as an "ON/OFF" type solid state switch for controlling high power devices such as motors, solenoids or lamps. If the circuit uses the Transistor as a Switch, then the biasing is arranged to operate in the output characteristics curves seen previously in the areas known as the "Saturation" and "Cut-off" regions as shown below.[6]
TRANSISTOR CURVES:
Fig 3.13
58
The shaded area at the bottom represents the "Cut-off" region. Here the operating conditions of the transistor are zero input base current (Ib), zero output collector current (Ic) and maximum collector voltage (Vce) which results in a large depletion layer and no current flows through the device. The transistor is switched "Fully-OFF". The lighter blue area to the left represents the "Saturation" region. Here the transistor will be biased so that the maximum amount of base current is applied, resulting in maximum collector current flow and minimum collector emitter voltage which results in the depletion layer being as small as possible and maximum current flows through the device. The transistor is switched "Fully-ON". Then we can summarize this as: Cut-off Region: Both junctions are Reverse-biased, Base current is zero or very Saturation Region: Both junctions are Forward-biased, Base current is high
small resulting in zero Collector current flowing, the device is switched fully "OFF". enough to give a Collector-Emitter voltage of 0v resulting in maximum Collector current flowing, the device is switched fully "ON".
Fig 3.14
59
An NPN Transistor as a switch being used to operate a relay is given above. With inductive loads such as relays or solenoids a flywheel diode is placed across the load to dissipate the back EMF generated by the inductive load when the transistor switches "OFF" and so protect the transistor from damage. If the load is of a very high current or voltage nature, such as motors, heaters etc, then the load current can be controlled via a suitable relay as shown. The circuit resembles that of the Common Emitter circuit we looked at in the previous tutorials. The difference this time is that to operate the transistor as a switch the transistor needs to be turned either fully "OFF" (Cut-off) or fully "ON" (Saturated). An ideal transistor switch would have an infinite resistance when turned "OFF" resulting in zero current flow and zero resistance when turned "ON", resulting in maximum current flow. In practice when turned "OFF", small leakage currents flow through the transistor and when fully "ON" the device has a low resistance value causing a small saturation voltage (Vce) across it. In both the Cut-off and Saturation regions the power dissipated by the transistor is at its minimum.[7] To make the Base current flow, the Base input terminal must be made more positive than the Emitter by increasing it above the 0.7 volts needed for a silicon device. By varying the Base-Emitter voltage Vbe, the Base current is altered and which in turn controls the amount of Collector current flowing through the transistor as previously discussed. When maximum Collector current flows the transistor is said to be saturated. The value of the Base resistor determines how much input voltage is required and corresponding Base current to switch the transistor fully "ON". Transistor switches are used for a wide variety of applications such as interfacing large current or high voltage devices like motors, relays or lamps to low voltage digital logic IC's or gates like AND Gates or OR Gates.[8]
60
61
PORT0 is open collector thats why we are using pull-up resistor which makes PORT0 as an I/O port. Reset circuit is used to reset the microcontroller. Crystal circuit is used for the microcontroller for timing pluses. In this project we are not using external memory thats why EA/VPP pin in the microcontroller is connected to Vcc that indicates internal memory is used for this application.
A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism, but other operating principles are also used. Relays find applications where it is necessary to control a circuit by a low-power signal, or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits, repeating the signal coming in from one circuit and retransmitting it to another. Relays found extensive use in telephone exchanges and early computers to perform logical operations. A type of relay that can handle the high power required to directly drive an electric motor is called a contactor. Solid-state relays control power circuits with no moving parts, instead using a semiconductor device triggered by light to perform switching. Relays with calibrated operating characteristics and sometimes multiple operating coils are used to protect electrical circuits from overload or faults; in modern electric power systems these functions are performed by digital instruments still called "protection relays".[9]
SPDT RELAY: (Single Pole Double Throw Relay) an electromagnetic switch, consist of a coil (terminals 85 & 86), 1 common terminal (30), 1 normally closed terminal (87a), and one normally open terminal (87).
62
When the coil of the relay is at rest (not energized), the common terminal (30) and the normally closed terminal (87a) have continuity. When the coil is energized, the common terminal (30) and the normally open terminal (87) have continuity. The diagram below first shows the relay at rest, with the coil not energized. The diagram below second shows the relay with the coil energized. As you can see the coil is an electromagnet that causes the arm that is always connected to the common (30) to pivot when energized whereby contact is broken from the normally closed terminal (87a) and made with the normally open terminal (87).
When energizing the coil of a relay, polarity of the coil does not matter unless there is a diode across the coil. If a diode is not present, you may attach positive voltage to either terminal of the coil and negative voltage to the other, otherwise you must connect positive to the side of the coil that the cathode side (side with stripe) of the diode is connected and negative to side of the coil that the anode side of the diode is connected.[10] Diodes are most often used across the coil to provide a path for current when the current path to the relay is interrupted (i.e. switched off, coil no longer energized). This allows the coil field to collapse without the voltage spike that would otherwise be generated. The diode protects switch or relay contacts and other circuits that may be sensitive to voltage spikes. Here's are some circuit diagrams for driving relays from a microcontroller. Make sure you're using a 5-volt relay (this refers to the coil, not the load circuit), and make sure that the relay has a high enough rating for the load that you're driving. 63
This circuit is necessary if you are using a relay with a coil that needs more power than the microcontroller can supply (this includes most miniature electromechanical relays) [11]
Fig 3.15
64
The primary advantage of this feature is that it allows manufacturers of electronic devices to integrate programming and testing into a single production phase, rather than requiring a separate programming stage prior to assembling the system. This may allow manufacturers to program the chips in their own system's production line instead of buying preprogrammed chips from a manufacturer or distributor, making it feasible to apply code or design changes in the middle of a production run.[12] ISP (In System Programming) will provide a simple and affordable home made solution to program and debug your microcontroller based project. Normally, the flash memory of an ATMEL microcontroller is programmed using a parallel interface, which consists of sending the data byte by byte (using 8 independent lines for the data, and another bunch of lines for the address, the control word and clock input). Many members of the Maxim 8051-based microcontroller family support insystem programming via a commonly available RS-232 serial interface. The serial interface consists of pins SCK, MOSI (input) and MISO (output) and the RST pin, which is normally used to reset the device. ISP is performed using only 4 lines, and literally, data is transferred through 2 lines only, as in a I2C interface, where data is shifted in bit by bit though MOSI line, with a clock cycle between each bit and the next (on the SCK line). MISO line is used for reading and for code verification; it is only used to output the code from the FLASH memory of the microcontroller. The RST pin is also used to enable the 3 pins (MOSI, MISO and SCK) to be used for ISP simply by setting RST to HIGH (5V), otherwise if RST is low (0V), program start running and those three pins, are used normally as P1.5, P1.6 and P1.7. After RST is set high, the Programming Enable instruction needs to be executed first before other operations can be executed. Before a reprogramming sequence can occur, a Chip Erase operation is required. The Chip Erase operation turns the content of every memory location in the Code array into FFH 65
Either an external system clock can be supplied at pin XTAL1 or a crystal needs to be connected across pins XTAL1 and XTAL2. The maximum serial clock (SCK) frequency should be less than 1/16 of the crystal frequency. With a 33 MHz oscillator clock, the maximum SCK frequency is 2 MHz.[13]
0 . 1 U F / 3 5 1V 0 0 K
GND
G N D V 1 2 1 2 1 2 1 2 9 2 8 2 7 1 6 1 5 1 4 1 3 1 2 1 1 C O N 3 5 2 4 1 3 0 2 1 0 9 8 7 6 5 4 G N D 1 1 2 3 4 5 6 7 8 9 G I O I O I O I O 0G A 1 1 2 2 3 3 4 4 N 7 V G O I O I 0 I O I 4 H C B 1 1 2 2 3 3 4 4 C C2 1 A1 B1 A1 B1 A1 B1 A1 B1 2 0 9 8 7 6 5 4 3 2 1 4 4 C C
A B A B A B A B D
1 3 5 7 9
2 4 6 8 1
G N D
Fig 3.16
Pin no 1 2 3
Direction
66
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
RTS CTS DSR GND CD ----STF S.CD S.CTS S.TXD TCK S.RXD RCK LL S.RTS DTR RL RI DSR XCK TI
Request to Send Clear to Send Data Set Ready System Ground Carrier Detect Reserved Reserved Select Transmit Channel Secondary Carrier Detect Secondary Clear to Send Secondary Transmit Data Transmission Signal Element Timing Secondary Receive Data Receiver Signal Element Timing Local Loop Control Secondary Request to Send Data terminal Ready Remote Loop Control Ring Indicator Data Signal Rate Selector Transmit Signal Element Timing Test Indicator
Fig 3.17
67
Fig 3.18
AT89S8252 microcontroller features an SPI port, through which on-chip Flash memory and EEPROM may be programmed. To program the microcontroller, RST is held high while commands, addresses and data are applied to the SPI port.
This programmer was designed in view of to be flexible, economical and easy to built, the programmer hardware uses the standard TTL series parts and no special components are used. The programmer is interfaced with the PC parallel port and there is no special requirement for the PC parallel port, so the older computers can also be used with this programmer.
SUPPORTED DEVICES:
The programmer software presently supports the following devices AT89C51 AT89S8252 AT89S51 AT89C51RC AT89C1051 AT89C55 UD87C51 AT89S53 AT89C52 AT89C4051 AT89S52 AT89C55WD
AT89C2051 D87C52
Note: For 20 pin devices a simple interface adapter is required. The ISP-3v0.zip file contains the main program and the I/O port driver for Windows 2000 & XP. Place all files in the same folder, for win-95/98 use the "ISPPgm3v0.exe"File, for win-2000 & XP use the "ISP-XP.bat" file. The main screen view of the program is shown in fig below.
69
Fig 3.9
Following are the main features of this software: Read and write the Intel Hex file Read signature, lock and fuse bits Clear and Fill memory buffer Verify with memory buffer Reload current Hex file Display buffer checksum Program selected lock bits & fuses Auto detection of hardware The memory buffer contains both the code data and the EEPROM data for the devices which have EEPROM memory. The EEPROM memory address in buffer is started after the code memory, so it is necessary the hex file should contains the EEPROM start address after the end of code memory last address. i.e., for 90S2313 the start address for EEPROM memory is 0 x 800.
70
4. SCHEMATIC DIAGRAM
71
R8 R7 R6 R5 R4 R3 R2 R1 C
V 1 2 3 4 5 6 7 8 9
C ( ( P P P ( ( ( R
C T T 1 1 1 M M S C 2 2 . . . O I S X 0 1 ) P 1 .V 0 ) 0 P. 0 . 0 . 0 . ) 0 P. ) 0 P. P 0 1. 0 . C 01 1 2 3 41 51 6. 7 V 4 0 3C 9 / 3. A 1 8 /3 A 7 /3 A 6 /3 A 5 / .3 A5 4 / .3 A6 3 7/ 3 A 2 / A C D D D D D D D D P O
9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 C 0 1 2 3 4 5 6 7 V G T 1 1 1 1 1 1 5 4 3 2 1 0 A B C D S S V C C R C C 5 I M K P P 0 O T P 0 P 0 P 0 . . . . 4 5 6 7 1 1 1 1 1 1 1 C
C R1 R2 R3 R4 R5 R6 R7 R8
F F R
F F
R O
R R
O M
O O
I S P ( 1 0 ) M I S P ( 2 ) M I S P ( 4 ) I S P ( 6 ) & R S
XP 2 P 3 P 4 P S IP S O P K )P T P
G N D
R E D D D D S N 4 5 6 7 ( L ( L ( L ( L ( L ( L C C C C C C D D D D D D ) ) ) ) ) ) P G P 0 0 N . 1 D . 3 4 . 7 K V C C 1 2 3 4 5 6 7 8 9
B G V V R R E D D D 0D 1D 2D 3D 4D N D C C E E S W N 0 1 2 3 4 5 6 7
V C C = 5 V 3 1 2 I N 4 0 0 7 R E L 5 4
L B
2 1
230V A C
N P
( 7
G N D
X T X T A A L L 2 1
1 0 1 1 ( R 1 2 ( T 2 1 N( I 1 3 1 4 ( I 1 5 ( T 1 6 ( T 1 7 ( W ( R 1 1 2 8 9 X X 0 G
)N N
T T N
3 1 X D ) E P A 3 / . V0 3 P 0 D )A PL E3 ./ 1P 2 R 9 T 0 ) P S .E 2 N 3 T 1 ) P 3 . 3 ) P 3 . 4 2 8 ) P P3 .2 5 . 7 /2 A 7 R ) PP 2 3 . . 66 /2 A 6 D ) PP 32 . . 75 /2 A 5 P 2 . 4 /2 A 4 A L 2 P 2 . 3 /2 A 3 A L 1 P 2 . 2 /2 A 2 P 2 . 1 2 / A1 D P 2 . 0 / A
1 ( 7 4 L S 2 1 N ) 1 ( 7 4 L S 2 1 N ) 1 ( 7 4 L S 2 1 N ) 1 ( 7 4 L S 2 1 N ) C D L A ( D ( D S S 1 1 3 3 0 0 7 7 ) )
. 1 1 K
5L E D + 6L E D -
I R
I T
9 8
G N D
G N D
G N D
8 9 S
1
5 2
9 8 7 6 5 4 3 2 1
R1 R2 R3 R4 R5 R6 R7 R8 C
0 K P U L L U P V B R + I D 4 G E R 1 E C T I F I E R P 2 2 . 7 . 6 1 2 3 1 2 3 4 L E D 3V BATT ER Y X X V G 1 2S B N Q V W C 8 C 7 / O 6 5 L A U 1 0 T K 1 3 0 3 K 0 o h m P P 2 2 m . 1 . 0 s 1 s 2 s 3 s 4 I N T P P 0 2 2 . 5 . 4 ( P 3 . 2 ) 4 5 6 7 C C
A 1 B 1 N C C 1 D 1 Y 1 G N D
V C C1 4 D 2 1 3 C 2 1 2 N C 1 1 B 2 1 0 A 2 9 Y 2 8
, A
.T CR A N S F O R M E R
G N D 2
1 0 0 0 u f / 3 5 3 V 3 p f 1 0 4 p f 3
( 9 V , 1
A M P )
32.768KHZ
2 1
7 8 0 5
V I N V O
R
U
E G
3 T
L VA C T C O
V 5 V
A ST C DS D
D
G N D
7
G N D
U G P N DP
( 5
G 1 3 5 7 9 V C C
V 3 2 4 6 8 1 P P R 0 P 1 1 S 1 . 6 . 7 T . 5 3 p f X 3 3 p f 1 1 . 0 X T T 5 A A 9 L L 2 1 2 S W IT C H M H z C
I S P
1 0
R
u f / 6 3 V
S T
G N D
8 . 2 K
I S
L
G N D
5. CODING
/**HEADER FILES**/ #include<reg52.h> #include<intrins.h> 72
/**LCD CONNECTIONS**/ #define LCD P0 /**VARIABLES DEFINITION**/ #define DELAY _nop_(); #define CLKHIGH clk=1; #define CLKLOW clk=0; #define DATAHIGH dat=1; #define DATALOW dat=0; /**RTC & EEPROM PIN CONNECTIONS**/ sbit clk=P2^1; sbit dat=P2^0; /** SWITCHES CONNECTIONS **/ sbit SEL = P2^7; sbit INC = P2^6; sbit DEC = P2^5; sbit EXIT = P2^4; /**DEVICE CONNECTION**/ sbit relay = P1^1; /**VARIABLES DECLARATION**/ bit busy,noack,busfault; unsigned char mask,newmin,oldmin; /** I2C FUNCTION DECLARATION **/ void stop(void); void address(unsigned char); 73
void send_byte(unsigned char); unsigned char receive_byte(unsigned char); void write_i2c(unsigned char,unsigned char,unsigned char); unsigned char read_i2c(unsigned char,unsigned char); /** TIME FUNCTIONS DECLARATION **/ void edit_hrs(unsigned char ,unsigned char,unsigned char); void edit_set(unsigned char ,unsigned char,unsigned char); void edit_week(unsigned char ,unsigned char,unsigned char); void edit_settings(void);
/**VARIABLES DEFINITION**/ bit flag = 0; //unsigned char buf[10]; unsigned char key_code; /**LCD FUNCTIONS DECLARATION**/ void init_lcd(void); void cmd_lcd(unsigned char); void data_lcd(unsigned char); void display_lcd(unsigned char *); /** DELAY FUNCTION DECLARATION **/ void delay_ms(int); /** DISPLAY & EDIT TIME FUNCTIONS DECLARATION **/ void time(void); void edit_time(void); /**VARIABLES DECLARATION**/ 74
unsigned char day[] = {31,28,31,30,31,30,31,31,30,31,30,31}; char code *week[] = {" ","SUN","MON","TUE","WED","THU","FRI","SAT"}; char code *menu[] = {" EDIT TIME "}; unsigned char alaram_flag=0; /********************************************************************/ void select_alaram(void); unsigned char select(unsigned char MIN,unsigned char MAX,unsigned char addr,unsigned char cmd); unsigned int u1on,u1off; sbit alaram=P3^2; void check(void); / ***********************************************************************/ /**EXTERNAL INTERRUPT0 SERVICE ROUTINE**/ void ext_int0(void) interrupt 0 { if(SEL == 0) key_code = 0x80; else if(INC == 0) key_code = 0x40; else if(DEC == 0) key_code = 0x20; //DECREMENT else if(EXIT == 0) key_code = 0x10; //EXIT while((P2 & 0xF0) != 0xF0); } /**EXTERNAL INTERRUPT1 SERVICE ROUTINE**/ 75 //INCREMENT //SELECT
void ext_int1(void)interrupt 2 { alaram_flag=1; } /**MAIN FUNCTION**/ void main() { relay=0; //DEVICE OFF init_lcd(); display_lcd("** TIME BASED **"); cmd_lcd(0XC0); display_lcd(" DEVICE CONTROL "); delay_ms(1000); cmd_lcd(0X01); //CLEAR SCREEN //LCD INITIALIZATION FUNCTION //DISPLAY STRING ON LCD
write_i2c(0xD0,0x00,0x00); //write 0 in sec location key_code = 0x00; IE = 0x85;//INTERRUPT REGISTER IT0=1; IT1=1; while(1) { flag=0; key_code = 0x00;
76
lable: time(); if(alaram_flag==1) { select_alaram(); key_code=0x00; alaram_flag=0; } if(key_code == 0x80) { do{ cmd_lcd(0x01); display_lcd(menu[0]); key_code = 0x00; while(key_code == 0x00); if(key_code==0x10) break; } while(key_code != 0x80); if(key_code==0x10) goto lable; else edit_time(); } check(); } } /**LCD INITIALIZATION FUNCTION**/ 77 //EDIT TIME CALLING
void init_lcd(void) { cmd_lcd(0x02); cmd_lcd(0x28); cmd_lcd(0x0C); cmd_lcd(0x06); cmd_lcd(0x01); } /**LCD COMMAND FUNCTION**/ void cmd_lcd(unsigned char var) { LCD = ((var & 0xF0) | 0x08); LCD = 0; LCD = ((var << 4) | 0x08); LCD = 0; delay_ms(2); } /**LCD DATA FUNCTION**/ void data_lcd(unsigned char var) { LCD = ((var & 0xF0) | 0x0a);//RS=1,EN=1 LCD = 0; LCD = ((var << 4) | 0x0a); LCD = 0; delay_ms(2); } /**LCD STRING FUNCTION**/ void display_lcd(char *str) 78 //RS=1,EN=1 //RS=0,EN=1 //RS=0,EN=1 //RETURN HOME //4-BIT MODE //DISPLAY ON CURSOR OFF //SHIFT CURSOR TO RIGHT //CLEAR THE SCREEN
{ while(*str) data_lcd(*str++); } /**MILLISECOND DELAY FUNCTION**/ void delay_ms(int cnt) { int i; while(cnt--) for(i=0;i<500;i++); } /**I2C STOP FUNCTION**/ void stop(void) { DATALOW CLKHIGH DELAY DATAHIGH DELAY busy=0; } /**I2C ADDRESS FUNCTION**/ void address(unsigned char sel_eeprom) { DATALOW DELAY CLKLOW DELAY 79 //ISSUING START CONDITION FOR I2C //ISSUING START CONDITION FOR I2C
send_byte(sel_eeprom); } /**I2C SEND BYTE FUNCTION**/ void send_byte(unsigned char c) { mask=0x80; do { if(c&mask) DATAHIGH else DATALOW CLKHIGH CLKLOW mask/=2; }while(mask>0); DATAHIGH CLKHIGH CLKLOW } /**I2C RECEIVE BYTE FUNCTION**/ unsigned char receive_byte(unsigned char c) { unsigned char temp=0; mask=0x80; do { CLKHIGH DELAY 80
if(dat==1) temp|=mask; CLKLOW DELAY mask/=2; }while(mask>0); if(c==1) DATAHIGH else DATALOW CLKHIGH DELAY CLKLOW DELAY DATAHIGH return temp; } /**I2C WRITE FUNCTION**/ void write_i2c(unsigned char sel_eeprom,unsigned char eeprom_addr,unsigned char c) { int i; address(sel_eeprom); send_byte(eeprom_addr); send_byte(c); stop(); for(i=0;i<1800;i++); } /**I2C READ FUNCTION**/ unsigned char read_i2c(unsigned char sel_eeprom,unsigned char eeprom_addr) 81
{ unsigned char c; address(sel_eeprom); send_byte(eeprom_addr); stop(); address(sel_eeprom+1); c=receive_byte(1); stop(); return c; } /**I2C TIME FUNCTION**/ void time(void) { unsigned char base_addr = 0x20,data1; unsigned char hour,date,month,year; unsigned int sec; unsigned char *s,*q; cmd_lcd(0x80); data1=(read_i2c(0xD0,0x02)); hour=data1; data1=((read_i2c(0xD0,0x02)/0x10) + 0x30); data_lcd(data1); data1=((read_i2c(0xD0,0x02) % 0x10) + 0x30); data_lcd(data1); data_lcd(':'); data1= read_i2c(0xD0,0x01); //MINUTES 82 //HOURS
newmin=data1; data1=((read_i2c(0xD0,0x01)/0x10) + 0x30); data_lcd(data1); data1=((read_i2c(0xD0,0x01) % 0x10) + 0x30); data_lcd(data1); data_lcd(':'); data1=read_i2c(0xD0,0x00); //SECONDS sec=data1; data1=((read_i2c(0xD0,0x00)/0x10) + 0x30); sec=data1; data_lcd(data1); data1=((read_i2c(0xD0,0x00) % 0x10) + 0x30); data_lcd(data1); display_lcd(" ");
//DAY
data_lcd(data1); data_lcd('/'); data1=read_i2c(0xD0,0x05); //MONTH month=data1; data1=((read_i2c(0xD0,0x05)/0x10) + 0x30); data_lcd(data1); data1=((read_i2c(0xD0,0x05) % 0x10) + 0x30); data_lcd(data1); data_lcd('/'); data1=read_i2c(0xD0,0x06); //YEAR year=data1; data1=((read_i2c(0xD0,0x06)/0x10) + 0x30); data_lcd(data1); data1=((read_i2c(0xD0,0x06) % 0x10) + 0x30); data_lcd(data1);
} /**TIME EDITING FUNCTION**/ void edit_time(void) { unsigned char var; cmd_lcd(0x01); display_lcd("EDIT HRS : "); edit_hrs(0,23,02);
84
cmd_lcd(0x01); display_lcd("EDIT MINS"); edit_hrs(0,59,01); cmd_lcd(0x01); display_lcd("EDIT WEEK"); edit_week(1,7,3); cmd_lcd(0x01); display_lcd("EDIT YEAR"); edit_hrs(0,99,6); var = read_i2c(0xD0,0x06); var = ((var / 0x10) * 10) + (var % 0x10); if((var % 4) == 0) day[1] = 29; else day[1] = 28; cmd_lcd(0x01); display_lcd("EDIT MONTH"); edit_hrs(1,12,5); cmd_lcd(0x01); display_lcd("EDIT DAY"); edit_hrs(1,31,4); key_code = 0x00; write_i2c(0xD0,0x00,0x00); cmd_lcd(0x01); 85
} /**EDIT HOURS FUNCTION**/ void edit_hrs(unsigned char MIN,unsigned char MAX,unsigned char addr) { int temp,val; val = read_i2c(0xD0,addr); temp = val; temp = (((val/0x10) * 0x0a) + val% 0x10); do{ cmd_lcd(0xC0); data_lcd((temp/10) + 0x30); data_lcd((temp%10) + 0x30); key_code = 0x00; while(key_code == 0x00); if(key_code == 0x40) { temp++; if(temp > MAX) temp = MIN; } else if(key_code == 0x20) { temp--; if(temp < MIN) temp = MAX; 86 //DECREMENT //INCREMENT
} else if(key_code == 0x10) { temp = val; flag=0; break; } }while(key_code != 0x80); temp = (((temp/10) * 0x10) + (temp%10)); write_i2c(0xD0,addr,temp); if(addr==0x02) { newmin=temp; oldmin=temp-1; } } /**EDIT WEEK FUNCTION**/ void edit_week(unsigned char MIN,unsigned char MAX,unsigned char addr) { int temp,val; val = read_i2c(0xD0,addr); temp = val; do{ cmd_lcd(0xC0); display_lcd(week[temp]); 87 //EXIT
//INCREMENT
if(temp > MAX) temp = MIN; cmd_lcd(0xc0); display_lcd(week[temp]); } else if(key_code == 0x20) { temp--; if(temp < MIN) temp = MAX; cmd_lcd(0xc0); display_lcd(week[temp]); } else if(key_code == 0x10) { temp = val; cmd_lcd(0xc0); display_lcd(week[temp]); break; } key_code = 0x00; while(key_code == 0x00); }while(key_code != 0x80); //EXIT //DECREMENT
88
write_i2c(0xD0,addr,temp); } /**SET THE ALARAM FUNCTION**/ void select_alaram(void) { unsigned int hour,min; cmd_lcd(0x01); display_lcd("set the alaram "); cmd_lcd(0xc0); key_code=0x00; while(key_code==0x00); if(key_code==0x80) { hour=0x00;min=0x00; cmd_lcd(0x01); display_lcd("Set On Time:"); cmd_lcd(0xc0); hour=select(0,23,02,0xc0); data_lcd(':'); min=select(0,59,01,0xc3); u1on=((hour<<8)|min); cmd_lcd(0x01); display_lcd("Set Off Time:"); cmd_lcd(0xc0); hour=select(0,23,02,0xc0); 89
data_lcd(':'); min=select(0 ,59,01,0xc3); u1off=((hour<<8)|min); } else ; } /**SELECT FUNCTION**/ unsigned char select(unsigned char MIN,unsigned char MAX,unsigned char addr,unsigned char cmd) { int temp,val; val = read_i2c(0xD0,addr); temp = val; temp = (((val/0x10) * 0x0a) + val% 0x10); do { cmd_lcd(cmd); data_lcd((temp/10) + 0x30); data_lcd((temp%10) + 0x30); key_code = 0x00; while(key_code == 0x00); if(key_code == 0x40) //INCREMENT { temp++; if(temp > MAX) temp = MIN; } 90
else if(key_code == 0x20) { temp--; if(temp <= MIN) temp = MAX; } else if(key_code == 0x10) { temp =val; flag=0; break; } }while(key_code != 0x80); return temp; } /**CHECKING FUNCTION**/ void check(void) { unsigned int val,k; static int x,y; unsigned int temp; val= read_i2c(0xD0,0x03);
//DECREMENT
//EXIT
//day
temp = (((val/0x10) * 0x0a) + val% 0x10); val=0x00; temp=0x00; val= read_i2c(0xD0,0x02); temp = (((val/0x10) * 0x0a) + val% 0x10); 91
temp=temp<<8; val=0x00; val= read_i2c(0xD0,0x01); val = (((val/0x10) * 0x0a) + val% 0x10); temp=(temp|val); if(temp==u1on) { IE=0x81; alaram=1; if(x==0) { relay=1; cmd_lcd(0x01); display_lcd("Alaram ON "); for(k=0;k<40000;k++); x=1; y=0; } } else if(temp==u1off) { IE=0x85; alaram=0; if(y==0) { relay=0; cmd_lcd(0x01); display_lcd("Alaram OFF "); for(k=0;k<40000;k++); 92
y=1; x=0; } } }
93
The main intension of this project is to design TIME BASED ELECTRICAL APPLIANCE CONTROLLING SYSTEM FOR INDUSTRIAL APPLICATIONS. In order to fulfill this application there are few steps that has been performed i.e. 1) Designing the power supply for the entire circuitry. 2) Selection of microcontroller that suits our application. 3) Selection of RTC. 4) Selection of LCD 5) Selection of AND gate. Complete studies of all the above points are useful to develop this project.
In this project whenever the power up the controller reads the time from RTC and
it can display on LCD. By default the contents of RTC will be zeros, so we can initialize the current time by using push button switches then the time can count. The switches are connected to AND gate the output of AND gate is connected to interrupt pin i.e. we are selecting the pressed switch based on interrupt mechanism. Whenever the switch is pressed which is connected to INT1 i.e. the output of this IC is low then interrupt will occur because of the output of this switch is connected to the microcont controller send the signal to DEVICE to on the particular circuit, after a specified time the controller will stop the signal to DEVICE to off the circuit. Here user has to select the ON time and OFF time from the external switches. Based on that timings the process will going on.
CONCLUSION
94
Power Saving Using Time Operated Electrical Appliance Controlling System For Industrial Applications is a reliable circuit that takes over the task of switch on/off the electrical devices with respect to time.
Time Operated Electrical Appliance Controlling System For Industrial Applications project replaces the Manual Switching. It is an automatically operated device once the time is programmed. Implementation of this application is easy , less time consuming , less cost effective and reliable.
7.FUTURE SCOPE
95
Emphasizing the need for power saving with the current power crisis scenario, our project Time Operated Electrical Appliance Controlling System For Industrial Application can help you save a considerable amount of power.
Apart from using this application in industries it can also used in home appliance to save power and to avoid a burden in humans lives.
Application of this system is already in use in electronics appliance like ovens, geysers ,etc.. Any device can be operated using Time Operated Electrical Appliance Controlling System For Industrial Application. This project will be useful to people in all walks of life. Advancement of this project can be to operate more than one device.
8.References
96
1.www.atmel.com 2.The 8051 microcontroller and embedded systems Muhammad ali mazidi and Janice gillispe mazidi 3.8051 Microcontroller Architecture, programming and application by-B Kenneth jayala 4.www.maxim-ic.com(Dallas semiconductor) 5. www.datasheetsanalog.com
6. Semiconductor Device Physics and Simulation. Springer. - Juin Jei Liou and Jiann S. Yuan (1998).
7.Essentials of electronic circuitry .-Alphonse J. Sistino (1996). 8.Transistors American heritaze dictionary Boston houghon Mifflin 9. Electronic Devices on Discrete Components for Industrial and Power Engineering -Vladimir Gurevich (2008). 10. Electrical Relays: Principles and Applications- Gurevich, Vladimir (2005) 11. Hand book for Digital ICs from Analogic Devices 12.www.atmel.com 13.www.diggi.com 14.www.homestuffworks.com
97