santuu
TRANSCRIPT
-
8/3/2019 santuu
1/97
TIME OPERATED ELECTRICAL APPLIANCE
CONTROLLING SYSTEM FOR INDUSTRIAL APPLICATION
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
1
-
8/3/2019 santuu
2/97
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 ofBachelor of Technology is a record of the bonafide work carried out by
them during the academic year 2010-2011.
Head of the Department Internal Guide
Mr.CH.Rambabu Mr.CH.Rajendra Prasad
Assistant Professor Assistant Professor
Dept. of ECE Dept. of ECE
SSIST SSIST
External Examiner
2
-
8/3/2019 santuu
3/97
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.
M.Sujitha sree (Roll no.08X81A0443)
T.Santhosh (Roll no.08X81A0432)
Y.Dinesh (Roll no.08X81A0407)
3
-
8/3/2019 santuu
4/97
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.
4
-
8/3/2019 santuu
5/97
TABLE OF CONTENTS
1. ABSTRACT 7
2. INTRODUCTION
2.1. EMBEDDED SYSTEMS 9
2.2 MICROCONTROLLERS 15
2.3. LCD 17
2.4. LED 24
2.5. KEIL-C COMPILER 26
3. COMPONENT DESCRIPTION
3.1. AT89S52 29
3.2. DS1307 41
3.3. 74LS21 54
3.4. TRANSISTOR AS A SWITCH 57
3.5. SPDT RELAY 60
3.6. ISP PROGRAMMER 67
4. SCHEMATIC DIAGRAM 70
5. CODING 71
6. Result and Discussion 92
7. Future Scope 94
8. References 95
5
-
8/3/2019 santuu
6/97
List of figures
1. Fig 3.1-PIN CONFIGURATION 40-lead PDIP(AT89S52) 33
2. Fig 3.2-ARCHITECTUREof AT89S52 34
3. Fig 3.3-INTERNAL BLOCK DIAGRAM OF AT89S52 39
4. Fig 3.4-OSCILLATOR\ 40
5. Fig 3.5-PIN DESCRIPTION OF DS1307 41
6. Fig 3.6-CIRCUIT DESCRIPTION OF DS1307 43
7. Fig 3.7- BLOCK DIAGRAM OF DS1307 44
8. Fig 3.8-TIME KEEP DESCRIPTION OF DS1307 48
9. Fig 3.9-TWO WIRE CONFIGURATION OF DS1307 50
10. Fig 3.10-DATA TRANSFER ON 2-WIRE SERIAL BUS52
11. Fig 3.11- PIN DESCRIPTION OF 74LS2155
12. Fig 3.12-CONNECTION OF 74LS2155
13. Fig 3.13-TRANSISTOR CURVES57
14. Fig 3.14-TRANSISTOR SWITCHING CIRCUIT58
15. Fig 3.15-SPDT RELAY63
16. Fig 3.16-ISP PROGRAMMER66
17.Fig 3.17 ISP BLOCK DIAGRAM 66
6
-
8/3/2019 santuu
7/97
18.Fig 3.18 ISP PIN CONNECTION 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.
7
-
8/3/2019 santuu
8/97
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:
8
AT89S52
LCD
DS1307
7
4
L
S2
1
SEL
INC
DEC
EXIT
SPDT
RELAY
AC
DEVICE
-
8/3/2019 santuu
9/97
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
TIME
SELECT
SWITCH
-
8/3/2019 santuu
10/97
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
-
8/3/2019 santuu
11/97
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
-
8/3/2019 santuu
12/97
have utility programs to add a checksum or CRC to a program, so it can check its
program data before executing it.
2.1.4 OPERATING SYSTEM:
They often have no operating system, or a specialized embedded operating system
(often a real-time operating system), or the programmer is assigned to port one of these to
the new system.
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 CPU-based 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, code-reviews and ego less programming are recommended.
2.1.6DESIGN OF EMBEDDED SYSTEMS:
The electronics usually uses either a microprocessor or a microcontroller. Some
large or old systems use general-purpose mainframes computers or minicomputers.
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
-
8/3/2019 santuu
13/97
Many designers have found one of more hardware plus software-
controlled 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.
2.1.8THE CONTROL LOOP:
In this design, the software has a loop. The loop calls subroutines. Each
subroutine manages a part of the hardware or software. Interrupts generally set flags, or
update counters that are read by the rest of the software. A simple API disables and
enables interrupts. Done right, it handles nested calls in nested subroutines, and restores
the preceding interrupt state in the outermost enable. This is one of the simplest methods
of creating an exocrine.
Typically, there's some sort of subroutine in the loop to manage a list of software
timers, using a periodic real time interrupt. When a timer expires, an associated
subroutine is run, or flag is set. Any expected hardware event should be backed-up with asoftware timer. Hardware events fail about once in a trillion times.
State machines may be implemented with a function-pointer per state-
machine (in C++, C or assembly, anyway). A change of state stores a different function
into the pointer. The function pointer is executed every time the loop runs.
Many designers recommend reading each IO device once per loop, and storing the
result so the logic acts on consistent values. Many designers prefer to design their state
machines to check only one or two things per state. Usually this is a hardware event, and
a software timer. Designers recommend that hierarchical state machines should run the
lower-level state machines before the higher, so the higher run with accurate information.
13
-
8/3/2019 santuu
14/97
Complex functions like internal combustion controls are often handled with multi-
dimensional 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 torespond 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 alsominimize 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
-
8/3/2019 santuu
15/97
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, medium-
priced 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
-
8/3/2019 santuu
16/97
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.
2.2.1MICROPROCESSOR VS MICROCONTROLLER:
Microprocessor:
CPU is stand-alone, RAM, ROM, I/O, timer are separate
16
-
8/3/2019 santuu
17/97
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
2.3 LIQUID CRYSTAL DISPLAY
A liquid crystal display (LCD) is a thin, flat panel used for electronically
displaying information such as text, images, and moving pictures. Its uses include
monitors for computers, televisions, instrument panels, and other devices ranging from
aircraft cockpit displays, to every-day consumer devices such as video players, gaming
devices, clocks, watches, calculators, and telephones. Among its major features are its
17
-
8/3/2019 santuu
18/97
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.
2.3.1 PIN DESCRIPTION:
18
-
8/3/2019 santuu
19/97
PIN DESCRIPTION:
PIN SYMBOL I/O DESCRIPTION
1 VSS -- Ground
2 VCC -- +5V power supply
3 VEE -- Power supply to control contrast
4 RS I RS=0 to select command register
RS=1 to select data register
5 R/W I R/W=0 for write
R/W=1 for read
6 EN I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
19
-
8/3/2019 santuu
20/97
VCC, VSS and VEE:
While VCC and VSS provide +5V and ground respectively, VEE is used for
controlling LCD contrast.
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.
D0-D7 (DATA LINES):
The 8-bit data pins, D0-D7 are used to send information to the LCD or
read the content of the LCDs internal registers.
To display letters and numbers, we send ASCII codes for the letters A-Z,
a-z and numbers 0-9 to these pins while making RS=1.
20
-
8/3/2019 santuu
21/97
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.
2.3.2LCD COMMAND CODES:
CODE (HEX) COMMAND TO LCD INSTRUCTION REGISTER
0X01 CLEAR DISPLAY SCREEN
0X02 RETURN HOME
0X04 DECREMENT CURSOR(SHIFT CURSOR TO LEFT)
0X06 INCREMENT CURSOR(SHIFT CURSOR TO RIGHT)
0X05 SHIFT DISPLAY RIGHT
0X07 SHIFT DISPLAY LEFT
0X08 DISPLAY OFF,CURSOR OFF
0X0A DISPLAY OFF,CURSOR ON
0X0C DISPLAY ON,CURSOR OFF0X0E DISPLAY ON CURSOR BLINKING
0X0F DISPLAY ON CURSOR BLINKING
0X10 SHIFT CURSOR POSITION TO LEFT
0X14 SHIFT CURSOR POSITION TO RIGHT
0X18 SHIFT THE ENTIRE DISPLAY TO THE LEFT
0X1C SHIFT THE ENTIRE DISPLAY TO THE RIGHT
0X80 FORCE CURSOR TO BEGINNING OF 1ST LINE
0XC0 FORCE CURSOR TO BEGINNING OF 2ND LINE
0X38
0X30
0X280X20
8-BIT INTERFACE, 2 LINES, 5*7 PIXELS
8-BIT INTERFACE, 1 LINE, 5*7 PIXELS
4-BIT INTERFACE, 2 LINES, 5*7 PIXELS4-BIT INTERFACE, 1 LINE, 5*7 PIXELS
2.3.3CURSOR ADDRESSES FOR LCDS:
21
-
8/3/2019 santuu
22/97
16x2 LCD 80 81 82 83 84 85 86 through 8FC0 C1 C2 C3 C4 C5 C6 through CF
20x1 LCD 80 81 82 83 through 93
20x2 LCD 80 81 82 83 through 93
C0 C1 C2 C3 through D320x4 LCD 80 81 82 83 through 93
C0 C1 C2 C3 through D3
94 95 96 97 through A7D4 D5 D6 D7 through E7
40x2 LCD 80 81 82 83 through A7C0 C1 C2 C3 through E7
NOTE: All data is in HEX.
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.
2.4 LIGHT EMITTING DIODE
A light-emitting diode (LED) is a semiconductor diode that emits
incoherent narrow spectrum light when electrically biased in the forward direction of the
pn-junction, as in the common LED circuit. This effect is a form of electroluminescence.
22
-
8/3/2019 santuu
23/97
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
http://en.wikipedia.org/wiki/Diodehttp://en.wikipedia.org/wiki/Doping_(semiconductor)http://en.wikipedia.org/wiki/P-n_junctionhttp://en.wikipedia.org/wiki/Anodehttp://en.wikipedia.org/wiki/Cathodehttp://en.wikipedia.org/wiki/Electronhttp://en.wikipedia.org/wiki/Electron_holehttp://en.wikipedia.org/wiki/Electrodehttp://en.wikipedia.org/wiki/Energy_levelhttp://en.wikipedia.org/wiki/Energyhttp://en.wikipedia.org/wiki/Photonhttp://en.wikipedia.org/wiki/Diodehttp://en.wikipedia.org/wiki/Doping_(semiconductor)http://en.wikipedia.org/wiki/P-n_junctionhttp://en.wikipedia.org/wiki/Anodehttp://en.wikipedia.org/wiki/Cathodehttp://en.wikipedia.org/wiki/Electronhttp://en.wikipedia.org/wiki/Electron_holehttp://en.wikipedia.org/wiki/Electrodehttp://en.wikipedia.org/wiki/Energy_levelhttp://en.wikipedia.org/wiki/Energyhttp://en.wikipedia.org/wiki/Photon -
8/3/2019 santuu
24/97
The wavelength of the light emitted, and therefore its color, depends on
theband gap energy of the materials forming the p-n junction. In silicon orgermanium
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
http://en.wikipedia.org/wiki/Wavelengthhttp://en.wikipedia.org/wiki/Band_gaphttp://en.wikipedia.org/wiki/Siliconhttp://en.wikipedia.org/wiki/Germaniumhttp://en.wikipedia.org/wiki/Indirect_band_gaphttp://en.wikipedia.org/wiki/Direct_band_gaphttp://en.wikipedia.org/wiki/Gallium_arsenidehttp://en.wikipedia.org/wiki/Gallium_arsenidehttp://en.wikipedia.org/wiki/Materials_sciencehttp://en.wikipedia.org/wiki/Sapphirehttp://en.wikipedia.org/wiki/Refractive_indexhttp://en.wikipedia.org/wiki/Light_extraction_in_LEDshttp://en.wikipedia.org/wiki/Wear_and_tearhttp://en.wikipedia.org/wiki/Wavelengthhttp://en.wikipedia.org/wiki/Band_gaphttp://en.wikipedia.org/wiki/Siliconhttp://en.wikipedia.org/wiki/Germaniumhttp://en.wikipedia.org/wiki/Indirect_band_gaphttp://en.wikipedia.org/wiki/Direct_band_gaphttp://en.wikipedia.org/wiki/Gallium_arsenidehttp://en.wikipedia.org/wiki/Gallium_arsenidehttp://en.wikipedia.org/wiki/Materials_sciencehttp://en.wikipedia.org/wiki/Sapphirehttp://en.wikipedia.org/wiki/Refractive_indexhttp://en.wikipedia.org/wiki/Light_extraction_in_LEDshttp://en.wikipedia.org/wiki/Wear_and_tear -
8/3/2019 santuu
25/97
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 Wavelength (nm) Voltage (V)
Infrared > 760 V < 1.9
Red 610 < < 760 1.63 < V < 2.03
Orange 590 < < 610 2.03 < V < 2.10
Yellow 570 < < 590 2.10 < V < 2.18
Green 500 < < 570 1.9 < V < 4.0
Blue 450 < < 500 2.48 < V < 3.7
Violet 400 < < 450 2.76 < V < 4.0
Purple multiple types 2.48 < V < 3.7
Ultraviolet < 400 3.1 < V < 4.4
White Broad spectrum V = 3.5
2.4.1 ADVANTAGES OF LEDS:
LEDs have many advantages over other technologies like lasers. As compared to
laser diodes or IR sources
LEDs are conventional incandescent lamps. For one thing, they don't have a
filament that will burn out, so they last much longer. Additionally, their small
plastic bulb makes them a lot more durable. They also fit more easily into modern
electronic circuits.
25
http://en.wikipedia.org/wiki/Semiconductor_materialshttp://en.wikipedia.org/wiki/Semiconductor_materialshttp://en.wikipedia.org/wiki/Wavelengthhttp://en.wikipedia.org/wiki/Delta_(letter)http://en.wikipedia.org/wiki/Semiconductor_materialshttp://en.wikipedia.org/wiki/Semiconductor_materialshttp://en.wikipedia.org/wiki/Wavelengthhttp://en.wikipedia.org/wiki/Delta_(letter) -
8/3/2019 santuu
26/97
The main advantage is efficiency. In conventional incandescent bulbs, the light-
production 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.
2.4.2 DISADVANTAGES OF LEDS:
LEDs performance largely depends on the ambient temperature of the operating
environment.
LEDs must be supplied with the correct current.
LEDs do not approximate a "point source" of light, so cannot be used in
applications needing a highly collimated beam.
But the disadvantages are quite negligible as the negative properties of LEDs do not
apply and the advantages far exceed the limitations.
\
2.5 KIEL SOFTWARE
Many companies provide the 8051 assembler, some of them provide
shareware version of their product on the Web, Kiel is one of them. We can download
26
-
8/3/2019 santuu
27/97
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.
2.5.1 KIEL U VISION2:
This is an IDE (Integrated Development Environment) that helps you
write, compile, and debug embedded programs. It encapsulates the following
components:
A project manager
A make facility
Tool configuration
Editor
A powerful debugger
To get start here are some several example programs
2.5.2 BUILDING AN APPLICATION IN UVISION2:
To build (compile, assemble, and link) an application in uVision2, you must:
Select ProjectOpen Project
(For example, \C166\EXAMPLES\HELLO\HELLO.UV2)
Select Project - Rebuild all target files or Build target. UVision2 compiles,
assembles, and links the files in your project.
2.5.3 CREATING YOUR OWN APPLICATION IN UVISION2:
To create a new project in uVision2, you must:
Select Project - New Project.
Select a directory and enter the name of the project file.
Select Project - Select Device and select an 8051, 251, or C16x/ST10
device from the Device
Database
27
-
8/3/2019 santuu
28/97
Create source files to add to the project.
Select Project - Targets, Groups, and Files. Add/Files, select Source
Group1, and add the source files to the project.
Select Project - Options and set the tool options. Note when you select the
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
-
8/3/2019 santuu
29/97
2.5.5 DEBUGGING AN APPLICATION IN UVISION2:
To debug an application created using uVision2, you must:
Select Debug - Start/Stop Debug Session.
Use the Step toolbar buttons to single-step through your program. You
may enter G, main in the Output Window to execute to the main C function.
Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step
3.COMPONENT DESCRIPTION
3.1AT89S52
SELECTION OF MICROCONTROLLER:
As we know that there so many types of micro controller families that are
available in the market.
Those are
1) 8051 Family
2) AVR microcontroller Family
3) PIC microcontroller Family
04) ARM Family
Basic 8051 family is enough for our application; hence we are not concentrating
on higher end controller families.
In order to fulfill our application basic that is AT89C51 controller is enough. But
still we selected AT89S52 controller because of inbuilt ISP (in system programmer)
option.There are minimum six requirements for proper operation of microcontroller.
Those are:
1) power supply section
2) pull-ups for ports (it is must for PORT0)
3) Reset circuit
29
-
8/3/2019 santuu
30/97
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
-
8/3/2019 santuu
31/97
31
-
8/3/2019 santuu
32/97
-
8/3/2019 santuu
33/97
3.1.3PIN CONFIGURATION 40-lead PDIP:
fig. 3.1
33
-
8/3/2019 santuu
34/97
3.1.4 ARCHITECTURE:
Fig.3.2
34
-
8/3/2019 santuu
35/97
3.1.5PIN DESCRIPTION:
VCC: Supply voltage.
GND: Ground.
Port 0:
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each
pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as
high-impedance inputs.
Port 0 can also be configured to be the multiplexed low-order address/data
bus during accesses to external program and data memory. In this mode, P0 has internal
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 pull-
ups.
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
-
8/3/2019 santuu
36/97
Port Pin Alternate Functions
P1.0 T2(external count to Timer/Counter 2), clock-out
P1.1 T2EX(Timer/Counter 2 capture/reload trigger and direction control)
P1.5 MOSI (used for In-System Programming)
P1.6 MISO(used for In-System Programming)
P1.7 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 pull-ups.
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
-
8/3/2019 santuu
37/97
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
Port Pin Alternate FunctionsP3.0 RXD (serial Input port)
P3.1 TXD (serial output port)
P3.2 INT0 bar (external Interrupt 0)
P3.3 INT1 bar (external Interrupt 1)P3.4 T0 (timer 0 external Input)
P3.5 T1 (timer 1 external input)
P3.6 WR bar (external data memory write strobe)
P3.7 RD bar (external data memory read strobe)
-
8/3/2019 santuu
38/97
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
-
8/3/2019 santuu
39/97
3.1.6 BLOCK DIAGRAM:
Fig.3.3
3.1.7 Oscillator Characteristics:
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier that can be configured for use as an on-chip oscillator, as shown in Figure.
Either a quartz crystal or ceramic resonator may be used. To drive the device from an
external clock source, XTAL2 should be left unconnected while XTAL1 is driven, as
39
INTERRUPTCONTROL
ON-CHIP
ROM FORPROGRAM
CODE
ON-CHIPRAM
TIMER/COUNTER
TIMER 1
TIMER 0
OSC
BUSCONTROL
4 I/OPORTS
SERIALPORT
CPU
EXTERNALINTERRUPTS
COUNTERINPUTS
P0 P1 P2 P3 Tx Rx
-
8/3/2019 santuu
40/97
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 flip-
flop, 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
-
8/3/2019 santuu
41/97
Fig.3.4
C1, C2 = 30 pF 10 pF for Crystals
= 40 pF 10 pF for Ceramic Resonators
3.2 DS1307
3.2.1 FEATURES OF DS1307:
Real-time clock (RTC) counts seconds, minutes, hours, date of the month, month,
day of the week, and year with leap-year compensation valid up to 2100.
56-byte, battery-backed, nonvolatile (NV) RAM for data storage.
Two-wire serial interface.
Programmable square wave output signal.
Automatic power-fail detect and switch circuitry.
Consumes less than 500nA in battery backup mode with oscillator running.
Optional industrial temperature range: 40C to +85C
Available in 8-pin DIP or SOIC.
Underwriters Laboratory (UL) recognized.
3.2.2 PIN ASSIGNMENT:
41
-
8/3/2019 santuu
42/97
Fig.3.5
3.2.3 PIN DESCRIPTION:
VCC : Primary Power SupplyX1, X 2 : 32.768 kHz Crystal Connection
VBAT : +3V Battery Input
GND : Ground
SDA : Serial Data
SCL : Serial Clock
SQW/OUT : Square Wave/Output Driver
42
-
8/3/2019 santuu
43/97
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
-
8/3/2019 santuu
44/97
3.2.5 TYPICAL OPERATING CIRCUIT:
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 low-
current 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
-
8/3/2019 santuu
45/97
3.2.7 DS1307 BLOCK DIAGRAM:
Fig.3.7
SIGNAL DESCRIPTIONS:
VCC, GND:
DC power is provided to the device on these pins. VCC is the +5V input.
When 5V is applied within normal limits, the device is fully accessible and data can be
written and read. When a 3V battery is connected to the device and VCC is below 1.25 x
VBAT, reads and writes are inhibited. However, the timekeeping function continues
unaffected by the lower input voltage. As VCC falls below VBAT the RAM and
timekeeper are switched over to the external power supply (nominal 3.0V DC) at VBAT.
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
-
8/3/2019 santuu
46/97
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.
SCL (Serial Clock Input):
SCL is used to synchronize data movement on the serial interface.
SDA (Serial Data Input/Output):
SDA is the input/output pin for the 2-wire serial interface. The SDA pin is
open drain which requires an external pull up resistor.
SQW/OUT (Square Wave/Output Driver):
When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of
four square wave frequencies (1Hz, 4 kHz, 8 kHz, 32 kHz). The SQW/OUT pin is open
drain and requires an external pull-up resistor. SQW/OUT will operate with either Vcc or
Vbat applied.
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
-
8/3/2019 santuu
47/97
RTC AND RAM ADDRESS MAP:
The address map for the RTC and RAM registers of the DS1307 isshown below. The RTC registers are located in address locations 00h to 07h. The RAM
registers are located in address locations 08h to 3Fh. During a multi-byte access, when
the address pointer reaches 3Fh, the end of RAM space, it wraps around to location 0 the
beginning of the clock.
CLOCK AND CALENDAR:
The time and calendar information is obtained by reading the appropriate
register bytes.
The RTC registers are illustrated in the below figure. The time and calendar
are set or initialized by writing the appropriate register bytes. The contents of the time
and calendar registers are in the BCD format. Bit 7 of register 0 is the clock halt (CH) bit.
When this bit is set to a 1, the oscillator is disabled. When cleared to a 0, the oscillator is
enabled.
47
-
8/3/2019 santuu
48/97
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.
DS1307 TIMEKEEPER REGISTERS:
.Fig.3.8
48
-
8/3/2019 santuu
49/97
CONTROL REGISTER:
The DS1307 control register is used to control the operation of the SQW/OUT
pin.
OUT (Output control):
This bit controls the output level of the SQW/OUT pin when the square wave
output is disabled. If SQWE = 0, the logic level on the SQW/OUT pin is 1 if OUT = 1
and is 0 if OUT = 0.
SQWE (Square Wave Enable):
This bit, when set to logic 1, will enable the oscillator output. The frequency of
the square wave output depends upon the value of the RS0 and RS1 bits. With the square
wave output set to 1Hz, the clock registers update on the falling edge of the square wave.
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.
SQUAREWAVE OUTPUT FREQUENCY:
49
-
8/3/2019 santuu
50/97
2-WIRE SERIAL DATA BUS:
The DS1307 supports a bi-directional, 2-wire bus and data transmission
protocol. A device that sends data onto the bus is defined as a transmitter and a device
receiving data as a receiver. The device that controls the message is called a master. The
devices that are controlled by the master are referred to as slaves. The bus must be
controlled by a master device that generates the serial clock (SCL), controls the bus
access, and generates the START and STOP conditions. The DS1307 operates as a slave
on the 2-wire bus. A typical bus configuration using this 2-wire protocol is show in
Figure below.
TYPICAL 2-WIRE BUS CONFIGURATION:
Fig.3.9
Data transfer may be initiated only when the bus is not busy.
50
-
8/3/2019 santuu
51/97
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:
BUS NOT BUSY:
Both data and clock lines remain HIGH.
START DATA TRANSFER:
A change in the state of the data line, from HIGH to LOW, while the clock is
HIGH, defines a START condition.
STOP DATA TRANSFER: A change in the state of the data line, from LOW to HIGH, while the clock line
is HIGH, defines the STOP condition.
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
-
8/3/2019 santuu
52/97
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.
DATA TRANSFER ON 2-WIRE SERIAL BUS:
Fig.3.10Depending upon the state of the R/Wbit, two types of data transfer are possible:
52
-
8/3/2019 santuu
53/97
Data transfer from a master transmitter to a slave receiver:
The first byte transmitted by the master is the slave address. Next follows a
number of data bytes. The slave returns an acknowledge bit after each received byte. Data
is transferred with the most significant bit (MSB) first.
Data transfer from a slave transmitter to a master receiver:
The first byte (the slave address) is transmitted by the master. The slave then
returns an acknowledge bit. This is followed by the slave transmitting a number of data
bytes. The master returns an acknowledge bit after all received bytes other than the last
byte. At the end of the last received byte, a not acknowledge is returned. The master
device generates all of the serial clock pulses and the START and STOP conditions. A
transfer is ended with a STOP condition or with a repeated START condition. Since a
repeated START condition is also the beginning of the next serial transfer, the bus will
not be released. Data is transferred with the most significant bit (MSB) first.
The DS1307 may operate in the following two modes:
Slave receiver mode (DS1307 write mode):
Serial data and clock are received through SDA and SCL. After each byte is
received an acknowledge bit is transmitted. START and STOP conditions are recognized
as the beginning and end of a serial transfer. Address recognition is performed by
hardware after reception of the slave address and *direction bit. The address byte is the
first byte received after the start condition is generated by the master. The address byte
contains the 7 bit DS1307 address, which is 1101000, followed by the *direction bit
(R/W) which, for a write, is a 0. After receiving and decoding the address byte the device
outputs an acknowledge on the SDA line. After the DS1307 acknowledges the slave
address + write bit, the master transmits a register address to the DS1307. This will set
the register pointer on the DS1307. The master will then begin transmitting each byte of
data with the DS1307 acknowledging each byte received. The master will generate a stop
condition to terminate the data write.
53
-
8/3/2019 santuu
54/97
DATA WRITE SLAVE RECEIVER MODE:
Slave transmitter mode (DS1307 read mode):
The first byte is received and handled as in the slave receiver mode. However,
in this mode, the *direction bit will indicate that the transfer direction is reversed. Serial
data is transmitted on SDA by the DS1307 while the serial clock is input on SCL.
START and STOP conditions are recognized as the beginning and end of a serial transfer
.The address byte is the first byte received after the start condition is generated by the
master. The address byte contains the 7-bit DS1307 address, which is 1101000, followed
by the *direction bit (R/W) which, for a read, is a 1. After receiving and decoding the
address byte the device inputs an acknowledge on the SDA line. The DS1307 then begins
to transmit data starting with the register address pointed to by the register pointer. If the
register pointer is not written to before the initiation of a read mode the first address that
is read is the last one stored in the register pointer. The DS1307 must receive a not
acknowledge to end a read.[4]
DATA READ SLAVE TRANSMITTER MODE:
54
-
8/3/2019 santuu
55/97
SELECTION OF AND GATE:In this application we are using interrupt mechanism to find which switch is
pressed. In this project I am using four switches to select the particular cell phone to
charging. The four switches are connected to the AND gate. The output of AND gate isconnected to the interrupt pin of controller. In this application I am using 74LS21 IC it
has two AND gates, each gate has four inputs and one output
3.3 74LS21(DUAL 4-INPUT AND GATE
3.3.1GENERAL DESCRIPTION:
This device contains two independent gates each of which performs the logic
AND function.
3.3.2 PIN DESCRIPTION:
55
-
8/3/2019 santuu
56/97
Fig 3.11
3.3.3 CONNECTION DIAGRAM:
Fig 3.12
3.3.4 FUNCTION TABLE:
56
-
8/3/2019 santuu
57/97
[5]
H - High Logic Level
L - Low Logic Level
X - Either Low or High Logic Level
3.3.5 OPERATING CODITIONS:
3.4 TRANSISTOR AS A SWITCH
57
-
8/3/2019 santuu
58/97
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]
TRANSISTORCURVES:
Fig 3.13
58
-
8/3/2019 santuu
59/97
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
small resulting in zero Collector current flowing, the device is switched fully "OFF". Saturation Region: Both junctions are Forward-biased, Base current is high
enough to give a Collector-Emitter voltage of 0v resulting in maximum Collector
current flowing, the device is switched fully "ON".
3.4.1 TRANSISTOR SWITCHING CIRCUIT:
Fig 3.14
59
-
8/3/2019 santuu
60/97
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
-
8/3/2019 santuu
61/97
3.5 SPDT RELAY
POWER SUPPLY SECTION:
In-order to work with any components basic requirement is power supply. In this
section there is a requirement one voltage level i.e. 5V DC power supply.
Now the aim is to design the power supply section which converts 230V AC in to
5V DC. Since 230V AC is too high to reduce it to directly 5V DC, therefore we need a
step-down transformer that reduces the line voltage to certain voltage that will help us to
convert it in to a 5V DC. Considering the efficiency factor of the bridge rectifier, we
came to a conclusion to choose a transformer, whose secondary voltage is 3 to 4 V higher
than the required voltage i.e. 5V. For this application 0-9V transformers is used, since it
is easily available in the market.
The output of the transformer is 9V AC; it feed to rectifier that converts AC to
pulsating DC. As we all know that there are 3 kind of rectifiers that is
1) half wave
2) Full wave and
3) Bridge rectifier
Here we short listed to use Bridge rectifier, because half wave rectifier has we
less in efficiency. Even though the efficiency of full wave and bridge rectifier are the
same, since there is no requirement for any negative voltage for our application, we gone
with bridge rectifier.
Since the output voltage of the rectifier is pulsating DC, in order to convert it into
pure DC we use a high value (1000UF/1500UF) of capacitor in parallel that acts as a
filter. The most easy way to regulate this voltage is by using a 7805 voltage regulator,
whose output voltage is constant 5V DC irrespective of any fluctuation in line voltage.
61
-
8/3/2019 santuu
62/97
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 re-
transmitting 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
http://en.wikipedia.org/wiki/Electrichttp://en.wikipedia.org/wiki/Switchhttp://en.wikipedia.org/wiki/Contactorhttp://en.wikipedia.org/wiki/Electrichttp://en.wikipedia.org/wiki/Switchhttp://en.wikipedia.org/wiki/Contactor -
8/3/2019 santuu
63/97
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
http://www.the12volt.com/diodes/diodes.asphttp://www.the12volt.com/diodes/diodes.asphttp://www.the12volt.com/diodes/diodes.asphttp://www.the12volt.com/diodes/diodes.asp -
8/3/2019 santuu
64/97
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
3.6 ISP PROGRAMMER
In-System Programming (abbreviated ISP) is the ability of someprogrammable
logic devices, microcontrollers, and other programmable electronic chips to be
programmed while installed in a complete system, rather than requiring the chip to be
programmed prior to installing it into the system. Otherwise, In-system programming
means that the program and/or data memory can be modified without disassembling the
embedded system to physically replace memory.
64
http://en.wikipedia.org/wiki/Programmable_logic_devicehttp://en.wikipedia.org/wiki/Programmable_logic_devicehttp://en.wikipedia.org/wiki/Microcontrollerhttp://www.maxim-ic.com/glossary/definitions.mvp/term/Embedded%20System/gpk/991http://en.wikipedia.org/wiki/Programmable_logic_devicehttp://en.wikipedia.org/wiki/Programmable_logic_devicehttp://en.wikipedia.org/wiki/Microcontrollerhttp://www.maxim-ic.com/glossary/definitions.mvp/term/Embedded%20System/gpk/991 -
8/3/2019 santuu
65/97
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 in-
system 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 M OSI line,
with a clock cycle between each bit and the next (on the SCKline). 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
http://www.maxim-ic.com/glossary/definitions.mvp/term/RS-232/gpk/993http://www.maxim-ic.com/glossary/definitions.mvp/term/Serial%20Interface/gpk/992http://www.maxim-ic.com/glossary/definitions.mvp/term/RS-232/gpk/993http://www.maxim-ic.com/glossary/definitions.mvp/term/Serial%20Interface/gpk/992 -
8/3/2019 santuu
66/97
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]
G N D
I 4 A
G N
O 4 B
G N D
1 2
3 4
5 6
7 8
9 1 0
C O N N E C T O R D B 2 5
1 3
2 5
1 2
2 4
1 1
2 3
1 0
2 2
9
2 1
8
2 0
7
1 9
6
1 8
5
1 7
4
1 6
3
1 5
2
1 4
1
G N D
I 4 B
G A
1 0 0 K
G B
G
N
D
I 2 B
0 . 1 U F / 3 5 V
O 1 A
I 1 A
7 4 H C 2 4 4
2 0
1 9
1 8
1 7
1 6
1 5
1 4
1 3
1 2
1 1
1
2
3
4
5
6
7
8
9
1 0
O 2 A
V C
I 1 B
O 1 B
O 4 A
I 2 A
V C C
O 2 B
0 3 A
I 3 A
I 3 B
O 3 B
Fig 3.16
DB-25 Male pin description:
Pin no Name Direction Pin Description
1
2
GND
TXD
Shield Ground
Transmit Data
3 RXD Receive Data
66
-
8/3/2019 santuu
67/97
-
8/3/2019 santuu
68/97
EXAMPLE: CONNECTING THE PROGRAMMER TO AN AT89S52
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.
ATMEL ISP FLASH PROGRAMMER:
This is the software that will take the HEX file generated by whatever
compiler you are using, and send it - with respect to the very specific ISP transfer
protocol - to the microcontroller.
68
-
8/3/2019 santuu
69/97
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 AT89S51 AT89C1051 UD87C51 AT89C52 AT89S52
AT89C2051 D87C52 AT89C55 AT89S53 AT89C4051 AT89C55WD
AT89S8252 AT89C51RC
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 "ISP-
Pgm3v0.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
-
8/3/2019 santuu
70/97
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
-
8/3/2019 santuu
71/97
4. SCHEMATIC DIAGRAM
71
-
8/3/2019 santuu
72/97
- +
B R I D G E R E C T I F I E R
1
4
3
2
P 1 . 1
S C L ( D S 1 3 0 7 )
s 1
D 6 ( L C D )
D 4 ( L C D )
X T A L 1
7 8 0 5 R E G U L A T O R1 3
V I N V O U T
s 2
1 K
G N D
N
V C C
1 1 . 0 5 9 2 M H z
A T 8 9 S 5 2
2 0
1 8
1 7
2 93 0
1 9
3 29
1 01 11 21 31 41 51 6
4 03 93 83 73 63 53 43 3
2 82 72 62 52 42 32 22 1
12345678
3 1
G N D
X T A L 2
( R D ) P 3 . 7
P S E N
A L E / P R O G
X T A L 1
P 0 . 7 / A D 7R S T
( R X D ) P 3 . 0( T X D ) P 3 . 1
( I N T 0 ) P 3 . 2( I N T 1 ) P 3 . 3( T 0 ) P 3 . 4( T 1 ) P 3 . 5( W R ) P 3 . 6
V C CP 0 . 0 / A D 0P 0 . 1 / A D 1P 0 . 2 / A D 2P 0 . 3 / A D 3P 0 . 4 / A D 4P 0 . 5 / A D 5P 0 . 6 / A D 6
P 2 . 7 / A 1 5P 2 . 6 / A 1 4P 2 . 5 / A 1 3P 2 . 4 / A 1 2P 2 . 3 / A 1 1P 2 . 2 / A 1 0
P 2 . 1 / A 9P 2 . 0 / A 8
( T 2 ) P 1 . 0( T 2 E X ) P 1 . 1P 1 . 2P 1 . 3P 1 . 4( M O S I ) P 1 . 5( M I S O ) P 1 . 6( S C K ) P 1 . 7
E A / V P P
P 2 . 7
P O W E R S U P P L Y ( 5 V D C )
V C C
3 3 0 o h m
D 7 ( L C D )
P 0 . 6
S D A ( D S 1 3 0 7 )
V C CR S ( L C D )
Y 1 ( 7 4 L S 2 1 N )
G N D
V C C
2
P 0 . 3
A 1
B 1
N C
C 1
D 1
Y 1
G N D Y 2
A 2
B 2
N C
C 2
D 2
V C C
7 4 L S 2 1 N
1
2
4
3
5
6
7 8
9
1 0
1 1
1 2
1 3
1 4
2
3
0
V
A
C
P 2 . 5
L E D
A 1 ( 7 4 L S 2 1 N )
V C C
12
8 . 2 K
( 9 V , 1 A M P )
V C C = 5 V
P 1 . 7
P
2 3 0 V , A . C
12
F R O M I S P ( 2 )
A T 8 9 S 5 2 I S P
P 2 . 4
P 0 . 4
F R O M I S P ( 1 0 )
G N D
B U L B
B 1 ( 7 4 L S 2 1 N )
R
8
R
7
R
6
R
5
R
4
R
3
R
2
R
1C
1 0 K P U L L U P
9 8 7 6 5 4 3 2 1
3 3 0 o h m
P 0 . 5
G N D
V C C
D 1 ( 7 4 L S 2 1 N )
V C C
R E L A Y C I R C U I T
3 3 p f
P 1 . 5
P 2 . 6
P 2 . 0
G N D
1 0 4 p f
G N D
D S 1 3 0 7
7
5
1
2
63
8
4
S Q W / O U T
S D A
X 1
X 2
S C LV B A T
V C C
G N D
V C C
R E S E T
1 0 K2 2 0 o h m
I
1 0 0 0 u f / 3 5 V
P 0 . 1
I N T 0 ( P 3 . 2 )
P
D 5 ( L C D )
F R O M I S P ( 6 ) & R S T
L C D
V C C = 5 V
3 3 p f
s 3
A T 8 9 S 5 2 C R Y S T A L
R E L A Y S P D T
35
412
G N D
1 23 45 67 89 1 0
1 0 u f / 6 3 VC
G N D
C 1 ( 7 4 L S 2 1 N )
G N DX T A L 1
R E L A Y
3
2
.
7
6
8
K
H
Z
3
V
B
A
T
T
E
R
Y
T R I M P O T
5 K
E N ( L C D )
F R O M I S P ( 4 )
G N DV C CV E ER SR WE ND 0
D 3
D 2
D 4D 5D 6D 7
D 1
L E D +
L E D -
123456789
1 01 11 21 31 41 51 6
R
8
R
7
R
6
R
5
R
4
R
1
R
2
R
3C
1 0 K P U L L U P
123456789
X T A L 2
B C 1 0 9
P 1 . 6
G N D
V C C = 5 V
3 3 p f
s 4
R S TS
G N D
4 . 7 K
R S T
V C C
I N 4 0 0 7
P 2 . 1
G N D
G N D
S
W
IT
C
H
R
8
R
7
R
6
R
5
R
4
R
1
R
2
R
3C
1 0 K P U L L U P
1 2 3 4 5 6 7 8 9
P 0 . 7
T R A N S F O R M E R
X T A L 2
1 0 K
V C C
G N D
5. CODING
/**HEADER FILES**/
#include
#include
72
-
8/3/2019 santuu
73/97
/**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
-
8/3/2019 santuu
74/97
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 D