Вы находитесь на странице: 1из 52

CHAPTER 1

INTRODUCTION
1.1 Electronics and Micrprocessor
Electronics is the science of how to control the electric energy, energy in which
the electrons have a fundamental role. Electronics deals with electrical circuits that
involve active electrical Components such as vacuum tubes, transistors, diodes and
integrated circuits, and associated passive electrical components and interconnection
technologies.
Commonly, electronic devices contain circuitry consisting primarily or exclusively of
active semiconductors supplemented with passive elements; such a circuit is described as
an electronic circuit.
The nonlinear behaviour of active components and their ability to control electron
flows makes amplification of weak signals possible, and electronics is widely used
in information processing, telecommunication, and signal processing. The ability of
electronic devices to act as switches makes digital information processing possible.
Interconnection technologies such as circuit boards, electronics packaging technology, and
other varied forms of communication infrastructure complete circuit functionality and
transform the mixed components into a regular working system.
Electronics is distinct from electrical and electro-mechanical science and technology, which
deal with the generation, distribution, switching, storage, and conversion of electrical energy
to and from other Energy forms using wires, motors, generators,
batteries, switches, relays, transformers, resistors, and other passive components.
This distinction started around 1906 with the invention by Lee De Forest of
the triode, which made electrical amplification of weak radio signals and audio signals
possible with a non-mechanical device. Until 1950 this field was called "radio technology"
because its principal application was the design and theory of radio transmitters, receivers,
and vacuum tubes.
Today, most electronic devices use semiconductor components to perform electron
control. The study of semiconductor devices and related technology is considered a branch of
solid-state physics, whereas the design and construction of electronic circuits to solve

practical problems come under electronics engineering. This article focuses on engineering
aspects of electronics.
A microprocessor is a computer processor that incorporates the functions of
a computer's central processing unit (CPU) on a single integrated circuit (IC), or at most a
few integrated circuits. The microprocessor is a multipurpose, programmable device that
accepts digital data as input, processes it according to instructions stored in its memory, and
provides results as output. It is an example of sequential digital logic, as it has internal
memory. Microprocessors operate on numbers and symbols represented in the binary
numeral system.
The integration of a whole CPU onto a single chip or on a few chips greatly reduced
the cost of processing power. The integrated circuit processor was produced in large numbers
by highly automated processes, so unit cost was low. Single-chip processors increase
reliability as there are many fewer electrical connections to fail. As microprocessor designs
get faster, the cost of manufacturing a chip (with smaller components built on a
semiconductor chip the same size) generally stays the same.
Before microprocessors, small computers had been implemented using racks of
circuit boards with many medium- and small-scale integrated circuits. Microprocessors
integrated this into one or a few large-scale ICs. Continued increases in microprocessor
capacity have since rendered other forms of computers almost completely obsolete
(see history of computing hardware), with one or more microprocessors used in everything
from

the

smallest embedded

systems and handheld

devices to

the

largest mainframes and supercomputers.


AIM OF THE PROJECT
The important consideration in the present field of Electronics and Electrical related
technologies are Automation, Power consumption and cost effectiveness. Automation is intended
to reduce manpower with the help of intelligent systems and Power saving is the main
consideration forever as the source of the power(Thermal, Hydro etc.,)are getting diminished due
to various reasons.

The idea of designing a new system for the streetlight that do not consume huge
amount of electricity and illuminate large areas with the highest intensity of light is
concerning each engineer working in this field. Providing street lighting is one of the most
important and expensive responsibilities of a city. Lighting can account for 1038% of the
total energy bill in typical cities worldwide [1].
Street lighting is a particularly critical concern for public authorities in developing
countries because of its strategic importance for economic and social stability. Inefficient
lighting wastes significant financial resources every year, and poor lighting creates unsafe
conditions. Energy efficient technologies and design mechanism can reduce cost of the street
lighting drastically. Manual control is prone to errors and leads to energy wastages and
manually dimming during mid night is impracticable. Also, dynamically tracking the light
level is manually impracticable. The current trend is the introduction of automation and
remote management solutions to control street lighting [2].
There are various numbers of control strategy and methods in controlling the street
light system such as design and implementation of CPLD based solar power saving system
for street lights and automatic traffic controller [1], design and fabrication of automatic street
light control system[3], automatic street light intensity control and road safety module using
embedded system [4], automatic street light control system [5], Intelligent Street Lighting
System Using Gsm [6], energy consumption saving solutions based on intelligent street
lighting control system [7] and A Novel Design of an Automatic Lighting Control System for
a Wireless Sensor Network with Increased Sensor Lifetime and Reduced Sensor Numbers[8].
In this project two kinds of sensors will be used which are light sensor and
photoelectric sensor. The light sensor will detect darkness to activate the ON/OFF switch, so
the streetlights will be ready to turn on and the photoelectric sensor will detect movement to
activate the streetlights. LDR, which varies according to the amount of light falling on its
surface, this gives an inductions for whether it is a day-night time, the photoelectric sensors
are placed on the side of the road, which can be controlled by microcontroller PIC16f877A.
The photoelectric will be activated only on the night time. If any object crosses the
photoelectric beam, a particular light will be automatically ON. By using this as a basic
principle, the intelligent system can be designed for the perfect usage of streetlights in any
place.
3

CHAPTER 2
CONTROLLER SELECTION
Block Diagram:

Fig: 2.1 Overall Block Diagram


Block Diagram Explanation:

In this project, we are going to switch off the street lights automatically as the
day starts. The duration of the day differs from season to season, accordingly our module
works based upon the light intensity so as to when to start or stop. For this we are using Light
Dependent Resistor (LDR) as the light sensor, which communicates with the required
information to the micro controller.
Here we are using micro controller, LDR, and relay. By using the LDR we can
operate the lights, i.e when the light is available then it will be in the OFF state and when it is
dark then the light will be in ON state, it means LDR is inversely proportional to light. When
4

the light falls on the LDR it sends the commands to the micro controller that it should be in
the OFF state then it switch offs the light, all these commands are sent to the controller then
according to that the devices operate. We use a relay to act as an ON OFF switch, the load is
connected to these relays.
HARDWARE DESCRIPTION
The block diagram of the system is as shown in the fig. The system basically
consists of a
1.
2.
3.
4.

Micro controller,
LDR
RELAY
Power supply,

LDR
LDRs or Light Dependent Resistors are very useful especially in light/dark sensor
circuits. Normally the resistance of an LDR is very high, sometimes as high as 1000 000
ohms, but when they are illuminated with light resistance drops dramatically.

The animation opposite shows that when the torch is turned on, the resistance of the LDR
falls, allowing current to pass through

This is an example of a light sensor circuit :


When the light level is low the resistance of the LDR is high. This prevents current from
flowing to the base of the transistors. Consequently the LED does not light.
However, when light shines onto the LDR its resistance falls and current flows into the base
of the first transistor and then the second transistor. The LED lights.
The preset resistor can be turned up or down to increase or decrease resistance, in this way it
can make the circuit more or less sensitive.

RELAY
Description
A relay is an electrical switch that opens and closes under the control of another electrical
circuit. In the original form, the switch is operated by an electromagnet to open or close one
or many sets of contacts. It was invented by Joseph Henry in 1835. Because a relay is able to
control an output circuit of higher power than the input circuit, it can be considered to be, in a
broad sense, a form of an electrical amplifier.
Operation
When a current flows through the coil, the resulting magnetic field attracts an armature that is
mechanically linked to a moving contact. The movement either makes or breaks a connection
with a fixed contact. When the current to the coil is switched off, the armature is returned by
a force approximately half as strong as the magnetic force to its relaxed position. Usually this
is a spring, but gravity is also used commonly in industrial motor starters. Most relays are
manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a
high voltage or high current application, this is to reduce arcing.

If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the
energy from the collapsing magnetic field at deactivation, which would otherwise generate a
spike of voltage and might cause damage to circuit components. Some automotive relays
already include that diode inside the relay case. Alternatively a contact protection network,
consisting of a capacitor and resistor in series, may absorb the surge. If the coil is designed to
be energized with AC, a small copper ring can be crimped to the end of the solenoid. This
"shading ring" creates a small out-of-phase current, which increases the minimum pull on the
armature during the AC cycle.
By analogy with the functions of the original electromagnetic device, a solid-state relay is
made with a thyristor or other solid-state switching device. To achieve electrical isolation an
opto coupler can be used which is a light-emitting diode (LED) coupled with a photo
transistor.
Since relays are switches, the terminology applied to switches is also applied to relays. A
relay will switch one or more poles, each of whose contacts can be thrown by energizing the
coil in one of three ways:

Normally-open (NO) contacts connect the circuit when the relay is activated; the
circuit is disconnected when the relay is inactive. It is also called a Form A contact or
"make" contact.

Normally-closed (NC) contacts disconnect the circuit when the relay is activated; the
circuit is connected when the relay is inactive. It is also called a Form B contact or
"break" contact.

Change-over, or double-throw, contacts control two circuits: one normally-open


contact and one normally-closed contact with a common terminal. It is also called a
Form C contact or "transfer" contact. If this type of contact utilizes a "make before
break"

functionality, then it is called a Form D contact.

The animated picture shows a working relay with its coil and switch contacts. You
can see a lever on the left being attracted by magnetism when the coil is switched on. This
lever moves the switch contacts.

The relay's switch connections are usually label led COM, NC and NO:

COM = Common, always connect to this, it is the moving part of the switch.

NC = Normally Closed, COM is connected to this when the relay coil is off.

NO = Normally Open, COM is connected to this when the relay coil is on.

Connect to COM and NO if you want the switched circuit to be on when the relay
coil is on.

Connect to COM and NC if you want the switched circuit to be on when the relay
coil is off.

CHAPTER 3
REGULATED POWER SUPPLY
1. Power Supply:
This unit will supply the various voltage requirements of each unit.
The power supplying unit consists of a transformer, a rectifier, a filter and a regulator.
The transformer gives a 230V AC supply.
The rectifier is used to convert this AC supply to an equivalent DC source.
The rectifier used here is a Bridge rectifier.
In power supplies, capacitors are used to smooth (filter) the pulsating DC
output after rectification so that a nearly constant DC voltage is supplied.
The resistors and inductors can be combined with the capacitors to form
filter networks.
The voltage regulator is used to keep voltages within the prescribed range
that can be tolerated by the electrical equipment using that voltage.

Transformer
Voltage Regulator

CIRCUIT DIAGRAM:

Bridge Rectifier

Capacitor Filter

OUTPUT WAVEFORMS:

10

DESCRIPTION
A variable regulated power supply, also called a variable bench power supply, is one
where you can continuously adjust the output voltage to your requirements. Varying the
output of the power supply is the recommended way to test a project after having double
checked parts placement against circuit drawings and the parts placement guide. This type of
regulation is ideal for having a simple variable bench power supply. Actually this is quite
important because one of the first projects a hobbyist should undertake is the construction of
a variable regulated power supply. While a dedicated supply is quite handy e.g. 5V or 12V,
it's much handier to have a variable supply on hand, especially for testing.
The LM7805 is simple to use. You simply connect the positive lead of your
unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the
negative lead to the Common pin and then when you turn on the power, you get a 5 volt
supply from the Output pin.
CIRCUIT FEATURES
Brief description of operation: Gives out well regulated +5V output, output current
capability of 100 mA

Circuit protection: Built-in overheating protection shuts down output when

regulator IC gets too hot

Circuit complexity: Very simple and easy to build


11

Circuit performance: Very stable +5V output voltage, reliable operation

Availability of components: Easy to get, uses only very common basic

components

Design testing: Based on datasheet example circuit, I have used this circuit

successfully as part of many electronics projects

Applications: Part of electronics devices, small laboratory power supply

Power supply voltage: Unregulated DC 8-18V power supply

Power supply current: Needed output current + 5 mA

Component costs: Few dollars for the electronics components + the input

transformer cost
BLOCK DIAGRAM

12

CIRCUIT DIAGRAM

BASIC POWER SUPPLY CIRCUIT


Above is the circuit of a basic unregulated dc power supply. A bridge rectifier D1 to
D4 rectifies the ac from the transformer secondary, which may also be a block rectifier such
as WO4 or even four individual diodes such as 1N4004 types. (See later re rectifier ratings).
The principal advantage of a bridge rectifier is you do not need a centre
tap on the secondary of the transformer. A further but significant advantage is that the ripple
frequency at the output is twice the line frequency (i.e. 50 Hz or 60 Hz) and makes filtering
somewhat easier.
As a design example consider we wanted a small unregulated bench
supply for our projects. Here we will go for a voltage of about 12 - 13V at a maximum output
current (IL) of 500ma (0.5A). Maximum ripple will be 2.5% and load regulation is 5%.
Now the RMS secondary voltage (primary is whatever is consistent with
your area) for our power transformer T1 must be our desired output Vo PLUS the voltage
drops across D2 and D4 ( 2 * 0.7V) divided by 1.414.
This means that Vsec = [13V + 1.4V] / 1.414 which equals about 10.2V. Depending on the
VA rating of your transformer, the secondary voltage will vary considerably in accordance
13

with the applied load. The secondary voltage on a transformer advertised as say 20VA will be
much greater if the secondary is only lightly loaded.
If we accept the 2.5% ripple as adequate for our purposes then at 13V this
becomes 13 * 0.025 = 0.325 Vrms. The peak to peak value is 2.828 times this value. Vrip =
0.325V X 2.828 = 0.92 V and this value is required to calculate the value of C1. Also
required for this calculation is the time interval for charging pulses. If you are on a 60Hz
system it it 1/ (2 * 60 ) = 0.008333 which is 8.33 milliseconds. For a 50Hz system it is 0.01
sec or 10 milliseconds.
Remember the tolerance of the type of capacitor used here is very loose. The
important thing to be aware of is the voltage rating should be at least 13V X 1.414 or 18.33.
Here you would use at least the standard 25V or higher (absolutely not 16V).With our
rectifier diodes or bridge they should have a PIV rating of 2.828 times the Vsec or at least
29V. Don't search for this rating because it doesn't exist. Use the next highest standard or
even higher. The current rating should be at least twice the load current maximum i.e. 2 X
0.5A or 1A. A good type to use would be 1N4004, 1N4006 or 1N4008 types.
These are rated 1 Amp at 400PIV, 600PIV and 1000PIV respectively. Always be
on the lookout for the higher voltage ones when they are on special.
TRANSFORMER RATING
In our example above we were taking 0.5A out of the Vsec of 10V. The VA
required is 10 X 0.5A = 5VA. This is a small PCB mount transformer available in Australia
and probably elsewhere.
This would be an absolute minimum and if you anticipated drawing the maximum
current all the time then go to a higher VA rating.
The two capacitors in the primary side are small value types and if you don't know
precisely and I mean precisely what you are doing then OMIT them. Their loss won't cause
you heartache or terrible problems.

14

THEY MUST BE HIGH VOLTAGE TYPES RATED FOR A.C USE


The fuse F1 must be able to carry the primary current but blow under excessive
current, in this case we use the formula from the diagram. Here N = 240V / 10V or perhaps
120V / 10V. The fuse calculates in the first instance to [ 2 X 0.5A ] / [240 / 10] or .04A or 40
ma. In the second case .08A or 80 ma. The difficulty here is to find suitable fuses of that low
a current and voltage rating. In practice you use the closest you can get (often 100 ma ). Don't
take that too literal and use 1A or 5A fuses.
CONSTRUCTION
The whole project MUST be enclosed in a suitable box. The main switch
(preferably double pole) must be rated at 240V or 120V at the current rating. All exposed
parts within the box MUST be fully insulated, preferably with heat shrink tubing.

15

CHAPTER 4
EMBEDDED SYSTEMS
PIC 16F877 is one of the most advanced microcontroller from Microchip. This controller
is widely used for experimental and modern applications because of its low price, wide range
of applications, high quality, and ease of availability. It is ideal for applications such as
machine control applications, measurement devices, study purpose, and so on. The PIC
16F877 features all the components which modern microcontrollers normally have. The
figure of a PIC16F877 chip is shown below.

4.1 FEATURES OF PIC16F877


The PIC16FXX series has more advanced and developed features when compared to
its previous series. The important features of PIC16F877 series is given below.

GENERAL FEATURES
High performance RISC CPU.
ONLY 35 simple word instructions.
All single cycle instructions except for program branches which are two cycles.
Operating speed: clock input (200MHz), instruction cycle (200nS).
Up to 3688bit of RAM (data memory), 2568 of EEPROM (data memory), 8k14
of flash memory.
Pin out compatible to PIC 16C74B, PIC 16C76, PIC 16C77.
Eight level deep hardware stack.
16

Interrupt capability (up to 14 sources).


Different types of addressing modes (direct, Indirect, relative addressing modes).
Power on Reset (POR).
Power-Up Timer (PWRT) and oscillator start-up timer.
Low power- high speed CMOS flash/EEPROM.
Fully static design.
Wide operating voltage range (2.0 5.56)volts.
High sink/source current (25mA).
Commercial, industrial and extended temperature ranges.

Low power consumption (<0.6mA typical @3v-4MHz, 20A typical @3v-32MHz


and <1 A typical standby).

KEY FEATURES
Maximum operating frequency is 20MHz.
Flash program memory (14 bit words), 8KB.
Data memory (bytes) is 368.
EEPROM data memory (bytes) is 256.
5 input/output ports.
3 timers.
2 CCP modules.
2 serial communication ports (MSSP, USART).
PSP parallel communication port
10bit A/D module (8 channels)

17

4.2 PIN DIAGRAM

18

INPUT/OUTPUT PORTS
PIC16F877 has 5 basic input/output ports. They are usually denoted by PORT A (R A),
PORT B (RB), PORT C (RC), PORT D (RD), and PORT E (RE). These ports are used for
input/ output interfacing. In this controller, PORT A is only 6 bits wide (RA-0 to RA-7),
PORT B , PORT C,PORT D are only 8 bits wide (RB-0 to RB-7,RC-0 to RC-7,RD-0
to RD-7), PORT E has only 3 bit wide (RE-0 to RE-7).
All these ports are bi-directional. The direction of the port is controlled by using
TRIS(X) registers (TRIS A used to set the direction of PORT-A, TRIS B used to set the
direction for PORT-B, etc.). Setting a TRIS(X) bit 1 will set the corresponding PORT(X) bit
as input. Clearing a TRIS(X) bit 0 will set the corresponding PORT(X) bit as output.
(If we want to set PORT A as an input, just set TRIS(A) bit to logical 1 and want to set
PORT B as an output, just set the PORT B bits to logical 0.)
Analog input port (AN0 TO AN7) : these ports are used for interfacing analog inputs.
TX and RX: These are the USART transmission and reception ports.
SCK: these pins are used for giving synchronous serial clock input.
SCL: these pins act as an output for both SPI and I2C modes.
19

DT: these are synchronous data terminals.


CK: synchronous clock input.
SD0: SPI data output (SPI Mode).
SD1: SPI Data input (SPI mode).
SDA: data input/output in I2C Mode.
CCP1 and CCP2: these are capture/compare/PWM modules.
OSC1: oscillator input/external clock.
OSC2: oscillator output/clock out.
MCLR: master clear pin (Active low reset).
Vpp: programming voltage input.
THV: High voltage test mode controlling.
Vref (+/-): reference voltage.
SS: Slave select for the synchronous serial port.
T0CK1: clock input to TIMER 0.
T1OSO: Timer 1 oscillator output.
T1OS1: Timer 1 oscillator input.
T1CK1: clock input to Timer 1.
PGD: Serial programming data.
PGC: serial programming clock.
PGM: Low Voltage Programming input.
INT: external interrupt.
RD: Read control for parallel slave port.

20

CS: Select control for parallel slave.


PSP0 to PSP7: Parallel slave port.
VDD: positive supply for logic and input pins.
VSS: Ground reference for logic and input/output pins.

4.3 ARCHITECTURE OF PIC16F877

21

PIC 16F877 is a 40-pin 8-Bit CMOS FLASH Microcontroller from Microchip. The core
architecture is high-performance RISC CPU with only 35 single word1 instructions. Since it
follows the RISC architecture, all single cycle instructions take only one instruction cycle
except for program branches which take two cycles. 16F877 comes with 3 operating speeds
with 4, 8, or 20 MHz clock input. Since each instruction cycle takes four operating clock
cycles, each instruction takes 0.2 s when 20MHz oscillator is used. It has two types of
internal memories: program memory and data memory. Program memory is provided by 8K
words (or 8K*14 bits) of FLASH Memory, and data memory has two sources. One type of
data memory is a 368-byte RAM (random access memory) and the other is 256-byte
EEPROM (Electrically erasable programmable ROM). The core feature includes interrupt
capability up to 14 sources, power saving SLEEP mode, and (ICSP) capability. The
sink/source current, whichsingle 5V In-Circuit Serial Programming indicates a driving
power from I/O port, is high with 25mA. Power consumption is less than 2 mA in 5V
operating condition. The peripheral features include: (a) 3 time blocks: Timer0 for 8-bit
timer/counter; Timer1 for 16-bit timer/counter; and Timer2: 8-bit timer/counter with 8-bit
22

period register, prescaler and postscaler. (b) Two Capture, Compare, PWM modules for
capturing, comparing 16-bit, and PWM generation with 10-bit resolution. (c) 10-bit multichannel (max 8)Analog-to-Digital converter module. (Master Mode) and I2(d) Synchronous
Serial Port (SSP) with SPI (Master/Slave)C2 (e) Universal Synchronous Asynchronous
Receiver Transmitter (USART/SCI) with 9-bit address detection (f) Parallel Slave Port (PSP)
8-bits wide, with external RD, WR and CS controls (g) I/O ports. The key feature of 16F877
is summarized below: FLASH Program Memory (14-bit word) 8K Words Data Memory
(RAM) 368 Bytes Data Memory (EEPROM) 256 Bytes Interrupts 14 I/O Ports Ports A, B, C,
D, E Timers 3 Capture/Compare/PWM Modules 2 Serial Communications MSSP, USART 1 .

4.3.1 MEMORY ORGANIZATION OF PIC16F877


The memory of a PIC 16F877 chip is divided into 3 sections. They are
1.Program memory
2.Data memory and
3.Data EEPROM

Program memory
Program memory contains the programs that are written by the user. The program
counter (PC) executes these stored commands one by one. Usually PIC16F877 devices
have a 13 bit wide program counter that is capable of addressing 8K14 bit program
memory space. This memory is primarily used for storing the programs that are written
(burned) to be used by the PIC. These devices also have 8K*14 bits of flash memory that
can be electrically erasable /reprogrammed. Each time we write a new program to the
controller, we must delete the old one at that time.

23

Data Memory
The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the Special Function Registers. Bits RP1 (Status<6>) and RP0
(Status<5>) are the bank select bits. Each bank extends up to 7Fh (128 bytes). The lower
locations of each bank are reserved for the Special Function Registers. Above the Special
Function Registers are General Purpose Registers, implemented as static RAM. All
implemented banks contain Special Function Registers. Some frequently used Special
Function Registers from one bank may be mirrored in another bank for code reduction and
quicker access.

2.1.1 GENERAL PURPOSE REGISTER


FILE
The register file can be accessed either directly, orin directly, through the File Select Register
(FSR).

24

Data EEPROM and FLASH


The data EEPROM and Flash program memory is readable and writable during normal
operation (over the full VDD range). This memory is not directly mapped in the register file
space. Instead, it is indirectly addressed through the Special Function Registers. There are six
SFRs used to read and write this memory:
EECON1
EECON2
EEDATA
EEDATH
EEADR
25

EEADRH
The EEPROM data memory allows single-byte read and writes. The Flash program
memory allows single-word reads and four-word block writes. Program memory write
operations automatically perform an erase-before write on blocks of four words. A byte write
in data EEPROM memory automatically erases the location and writes the new data (erasebefore-write). The write time is controlled by an on-chip timer. The write/erase voltages are
generated by an on-chip charge pump, rated to operate over the voltage range of the device
for byte or word operations.

4.4 I/O PORTS


Some pins for these I/O ports are multiplexed with an alternate function for the peripheral
features on the device. In general, when a peripheral is enabled, that pin may not be used as a
general purpose I/O pin.

4.4.1 PORTA and the TRISA Register

PORTA is a 6-bit wide, bidirectional port. The corresponding data direction register is
TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e., put
the corresponding output driver in a High-Impedance mode). Clearing a TRISA bit (= 0) will
make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the
selected pin). Reading the PORTA register reads the status of the pins, whereas writing to it
will write to the port latch. All write operations are read-modify-write operations. Therefore,
26

a write to a port implies that the port pins are read, the value is modified and then written to
the port data latch. Pin RA4 is multiplexed with the Timer0 module clock input to become
the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open-drain
output.
All other PORTA pins have TTL input levels and full CMOS output drivers. Other
PORTA pins are multiplexed with analog inputs and the analog VREF input for both the A/D
converters and the comparators. The operation of each pin is selected by clearing/setting the
appropriate control bits in the ADCON1 and/or CMCON registers.
The TRISA register controls the direction of the port pins even when they are being used as
analog inputs. The user must ensure the bits in the TRISA register are maintained set when
using them as analog inputs.

4.4.2 PORTB and the TRISB Register

PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is
TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put
the corresponding output driver in a High-Impedance mode). Clearing a TRISB bit (= 0) will
make the corresponding PORTB pin an output (i.e., put the contents of the output latch on the
selected pin). Three pins of PORTB are multiplexed with the In-Circuit Debugger and LowVoltage Programming function: RB3/PGM, RB6/PGC and RB7/PGD.
Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on all
the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up
is automatically turned off when the port pin is configured as an output. The pull-ups are
disabled on a Power-on Reset.

27

Four of the PORTB pins, RB7:RB4, have an interrupton- change feature. Only pins
configured as inputs can cause this interrupt to occur (i.e., any RB7:RB4 pin configured as an
output is excluded from the interrupton- change comparison). The input pins (of RB7:RB4)
are compared with the old value latched on the last read of PORTB. The mismatch outputs
of RB7:RB4 are ORed together to generate the RB port change interrupt with flag bit RBIF
(INTCON<0>).

4.4.3 PORTC and the TRISC Register

PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is
TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put
the corresponding output driver in a High-Impedance mode). Clearing a TRISC bit (= 0) will
make the corresponding PORTC pin an output (i.e., put the contents of the output latch on the
selected pin).
PORTC is multiplexed with several peripheral functions. PORTC pins have Schmitt
Trigger input buffers. When the I2C module is enabled, the PORTC<4:3> pins can be
configured with normal I2C levels, or with SM Bus levels, by using the CKE bit
(SSPSTAT<6>). When enabling peripheral functions, care should be taken in defining TRIS
bits for each PORTC pin. Some peripherals override the TRIS bit to make a pin an output,
while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit
override is in effect while the peripheral is enabled, read-modify write instructions (BSF,
BCF, XORWF) with TRISC as the destination, should be avoided. The user should refer to
the corresponding peripheral section for the correct TRIS bit settings.
28

4.4.4 PORTD and TRISD Registers

PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually
configurable as an input or output. PORTD can be configured as an 8-bit wide
microprocessor port (Parallel Slave Port) by setting control bit, PSPMODE (TRISE<4>). In
this mode, the input buffers are TTL.

4.4.5 PORTE and TRISE Register


PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are
individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers.
The PORTE pins become the I/O control inputs for the microprocessor port when bit
PSPMODE (TRISE<4>) is set. In this mode, the user must make certain that the
TRISE<2:0> bits are set and that the pins are configured as digital inputs. Also, ensure that
ADCON1 is configured for digital I/O. In this mode, the input buffers are TTL.

29

Register 4-1 shows the TRISE register which also controls the Parallel Slave Port
operation. PORTE pins are multiplexed with analog inputs. When selected for analog input,
these pins will read as 0s. TRISE controls the direction of the RE pins, even when they are
being used as analog inputs. The user must make sure to keep the pins configured as inputs
when using them as analog inputs.

4.4.6 Parallel Slave Port


The Parallel Slave Port (PSP) is not implemented on the PIC16F873A or PIC16F876A.
PORTD operates as an 8-bit wide Parallel Slave Port, or microprocessor port, when control
bit PSPMODE (TRISE<4>) is set. In Slave mode, it is asynchronously readable and writable
by the external world through RD control input pin, RE0/RD/AN5, and WR control input
pin, RE1/WR/AN6.
The PSP can directly interface to an 8-bit microprocessor data bus. The external
microprocessor can read or write the PORTD latch as an 8-bit latch. Setting bit PSPMODE
enables port pin RE0/RD/AN5 to be the RD input, RE1/WR/AN6 to be the WR input and
RE2/CS/AN7 to be the CS (Chip Select) input. For this functionality, the corresponding data
direction bits of the TRISE register (TRISE<2:0>) must be configured as inputs (set). The
A/D port configuration bits, PCFG3:PCFG0 (ADCON1<3:0>), must be set to configure pins
RE2:RE0 as digital I/O.
There are actually two 8-bit latches: one for data output and one for data input. The user
writes 8-bit data to the PORTD data latch and reads data from the port pin latch (note that
they have the same address). In this mode, the TRISD register is ignored since the external
device is controlling the direction of data flow.

30

A write to the PSP occurs when both the CS and WR lines are first detected low. When
either the CS or WR lines become high (level triggered), the Input Buffer Full (IBF) status
flag bit (TRISE<7>) is set on the Q4 clock cycle, following the next Q2 cycle, to signal the
write is complete . The interrupt flag bit, PSPIF (PIR1<7>), is also set on the same Q4 clock
cycle.
IBF can only be cleared by reading the PORTD input latch. The Input Buffer Overflow
(IBOV) status flag bit (TRISE<5>) is set if a second write to the PSP is attempted when the
previous byte has not been read out of the buffer. A read from the PSP occurs when both the
CS and RD lines are first detected low. The Output Buffer Full (OBF) status flag bit
(TRISE<6>) is cleared immediately indicating that the PORTD latch is waiting to be read by
the external bus. When either the CS or RD pin becomes high (level triggered), the interrupt
flag bit PSPIF is set on the Q4 clock cycle, following the next Q2 cycle, indicating that the
read is complete. OBF remains low until data is written to PORTD by the user firmware.
When not in PSP mode, the IBF and OBF bits are held clear. However, if flag bit IBOV
was previously set, it must be cleared in firmware. An interrupt is generated and latched into
flag bit PSPIF when a read or write operation is completed. PSPIF must be cleared by the
user in firmware and the interrupt can be disabled by clearing the interrupt enable bit PSPIE
(PIE1<7>).

31

PARALLEL SLAVE PORT WRITE WAVEFORM

4.4.7 SPECIAL FEATURES OF THE

CPU

All PIC16F87XA devices have a host of features intended to maximize system reliability,
minimize cost through elimination of external components, provide power saving operating
modes and offer code protection. These are:
Oscillator Selection
Reset
- Power-on Reset (POR)
- Power-up Timer (PWRT)
- Oscillator Start-up Timer (OST)
- Brown-out Reset (BOR)
Interrupts
Watchdog Timer (WDT)
Sleep
Code Protection
ID Locations
In-Circuit Serial Programming
Low-Voltage In-Circuit Serial Programming
In-Circuit Debugger
PIC16F87XA devices have a Watchdog Timer which can be shut-off only through
configuration bits. It runs off its own RC oscillator for added reliability. There are two
timers that offer necessary delays on power-up. One is the Oscillator Start-up Timer (OST),
intended to keep the chip in Reset until the crystal oscillator is stable. The other is the Powerup Timer (PWRT), which provides a fixed delay of 72 ms (nominal) on power-up only. It is
designed to keep the part in Reset while the power supply stabilizes. With these two timers
on-chip, most applications need no external Reset circuitry. Sleep mode is designed to offer a
very low current power-down mode. The user can wake-up from Sleep through external
32

Reset, Watchdog Timer wake-up or through an interrupt. Several oscillator options are also
made available to allow the part to fit the application. The RC oscillator option saves system
cost while the LP crystal option saves power. A set of configuration bits is used to select
various options.

Configuration Bits
The configuration bits can be programmed (read as 0), or left un programmed (read as
1) to select various device configurations. The erased or un programmed value of the
Configuration Word register is 3FFFh. These bits are mapped in program memory location
2007h. It is important to note that address 2007h is beyond the user program memory space
which can be accessed only during programming.

bit 13 CP: Flash Program Memory Code Protection bit 1 = Code protection off 0 = All
program memory code-protected
bit 12 Unimplemented: Read as 1
bit 11 DEBUG: In-Circuit Debugger Mode bit
1 = In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
0 = In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
bit 10-9 WRT1:WRT0 Flash Program Memory Write Enable bits
For PIC16F876A/877A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
01 = 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
00 = 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
For PIC16F873A/874A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 0FFFh may be written to by EECON control
01 = 0000h to 03FFh write-protected; 0400h to 0FFFh may be written to by EECON control
00 = 0000h to 07FFh write-protected; 0800h to 0FFFh may be written to by EECON control
bit 8 CPD: Data EEPROM Memory Code Protection bit
1 = Data EEPROM code protection off
0 = Data EEPROM code-protected
bit 7 LVP: Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
1 = RB3/PGM pin has PGM function; low-voltage programming enabled
0 = RB3 is digital I/O, HV on MCLR must be used for programming
bit 6 BOREN: Brown-out Reset Enable bit
1 = BOR enabled
0 = BOR disabled
bit 5-4 Unimplemented: Read as 1
bit 3 PWRTEN: Power-up Timer Enable bit
1 = PWRT disabled
0 = PWRT enabled
bit 2 WDTEN: Watchdog Timer Enable bit
1 = WDT enabled
33

0 = WDT disabled
bit 1-0 FOSC1:FOSC0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator

4.4.8 Oscillator Configurations


OSCILLATOR TYPES
The PIC16F87XA can be operated in four different oscillator modes. The user can program
two configuration bits (FOSC1 and FOSC0) to select one of these four modes:
LP Low-Power Crystal
XT Crystal/Resonator
HS High-Speed Crystal/Resonator
RC Resistor/Capacitor

4.8.1 CRYSTAL OSCILLATOR/CERAMIC RESONATORS

In XT, LP or HS modes, a crystal or ceramic resonator is connected to the OSC1/CLKI and


OSC2/CLKO pins to establish oscillation (Figure 14-1). The PIC16F87XA oscillator design
requires the use of a parallel cut crystal. Use of a series cut crystal may give a frequency out
of the crystal manufacturers specifications. When in XT, LP or HS modes, the device can
have an external clock source to drive the OSC1/CLKI pin

4.9 Reset
The PIC16F87XA differentiates between various kinds of Reset:
Power-on Reset (POR)
MCLR Reset during normal operation
MCLR Reset during Sleep
WDT Reset (during normal operation)
WDT Wake-up (during Sleep)
Brown-out Reset (BOR)

34

Some registers are not affected in any Reset condition. Their status is unknown on POR
and unchanged in any other Reset. Most other registers are reset to a Reset state on Poweron Reset (POR), on the MCLR and WDT Reset, on MCLR Reset during Sleep and Brownout
Reset (BOR). They are not affected by a WDT wake-up which is viewed as the resumption of
normal operation. The TO and PD bits are set or cleared differently in different Reset
situations as indicated in These bits are used in software to determine the nature of the Reset.

MCLR
PIC16F87XA devices have a noise filter in the MCLR Reset path. The filter will detect
and ignore small pulses. It should be noted that a WDT Reset does not drive MCLR pin low.
The behavior of the ESD protection on the MCLR pin differs from previous devices of
this family. Voltages applied to the pin that exceed its specification can result in both Resets
and current consumption outside of device specification during the Reset event. For this
reason, Microchip recommends that the MCLR pin no longer be tied directly to VDD.

Power-on Reset (POR)


A Power-on Reset pulse is generated on-chip when VDD rise is detected (in the range of
1.2V-1.7V). To take advantage of the POR, tie the MCLR pin to VDD through an RC
network When the device starts normal operation (exits the Reset condition), device
operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation.
If these conditions are not met, the device must be held in Reset until the operating
conditions are met. Brown-out Reset may be used to meet the start-up conditions.

Power-up Timer (PWRT)


The Power-up Timer provides a fixed 72 ms nominal time-out on power-up only from the
POR. The Power up Timer operates on an internal RC oscillator. The chip is kept in Reset as
long as the PWRT is active. The PWRTs time delay allows VDD to rise to an acceptable
level. A configuration bit is provided to enable or disable the PWRT. The power-up time
delay will vary from chip to chip due to VDD, temperature and process variation.

Oscillator Start-up Timer (OST)


The Oscillator Start-up Timer (OST) provides a delay of 1024 oscillator cycles (from
OSC1 input) after the PWRT delay is over (if PWRT is enabled). This helps to ensure that the
crystal oscillator or resonator has started and stabilized. The OST time-out is invoked only
for XT, LP and HS modes and only on Power-on Reset or wake-up from Sleep.

Brown-out Reset (BOR)


The configuration bit, BODEN, can enable or disable the Brown-out Reset circuit. Once
the brown-out occurs, the device will remain in Brown-out Reset until VDD rises above
35

VBOR. The Power-up Timer then keeps the device in Reset for TPWRT (parameter #33,
about 72 mS). If VDD should fall below VBOR during TPWRT, the Brown-out Reset
process will restart when VDD rises above VBOR with the Power-up Timer Reset. The
Power-up Timer is always enabled when the Brown-out Reset circuit is enabled, regardless of
the state of the PWRT configuration bit.

Watchdog Timer (WDT)


The Watchdog Timer is a free running, on-chip RC oscillator which does not require any
external components. This RC oscillator is separate from the RC oscillator of the
OSC1/CLKI pin. That means that the WDT will run even if the clock on the OSC1/CLKI and
OSC2/CLKO pins of the device has been stopped, for example, by execution of a SLEEP
instruction. During normal operation, a WDT time-out generates a device Reset (Watchdog
Timer Reset). If the device is in Sleep mode, a WDT time-out causes the device to wake-up
and continue with normal operation (Watchdog Timer Wake-up). The TO bit in the Status
register will be cleared upon a Watchdog Timer time-out.
FUNCTIONAL BLOCK DIAGRAM OF MICROCONTROLLER

Functional block diagram of micro controller


36

CHAPTER-5
SOFTWARE STUDY
5.1 EMBEDDED C
Embedded C is a set of language extensions for the C Programming language by the C
Standards committee to address commonality issues that exist between C extensions for
different embedded systems. Historically, embedded C programming requires nonstandard
extensions to the C language in order to support exotic features such as fixed-point
arithmetic, multiple distinct memory banks, and basic I/O operations.
In 2008, the C Standards Committee extended the C language to address these issues by
providing a common standard for all implementations to adhere to. It includes a number of
features not available in normal C, such as, fixed-point arithmetic, named address spaces, and
basic I/O hardware addressing.
Embedded C uses most of the syntax and semantics of standard C, e.g., main() function,
variable definition, data type declaration, conditional statements (if, switch, case), loops
(while, for), functions, arrays and strings, structures and union, bit operations, macros.

5.2 C IN EMBEDDED SYSTEM


The C programming language is perhaps the most popular programming language for
programming embedded systems. (Earlier Embedded Systems/Embedded Systems
Introduction#Which Programming Languages Will This Book Use? we mentioned other
popular programming languages).
Most C programmers are spoiled because they program in environments where not only
is there a standard library implementation, but there are frequently a number of other libraries
available for use. The cold fact is, that in embedded systems, there rarely are many of the
libraries that programmers have grown used to, but occasionally an embedded system might
not have a complete standard library, if there is a standard library at all. Few embedded
systems have capability for dynamic linking, so if standard library functions are to be
available at all, they often need to be directly linked into the executable. Oftentimes, because
of space concerns, it is not possible to link in an entire library file, and programmers are
often forced to "brew their own" standard c library implementations if they want to use them
at all. While some libraries are bulky and not well suited for use on microcontrollers, many
development systems still include the standard libraries which are the most common for C
programmers.
C remains a very popular language for micro-controller developers due to the code
efficiency and reduced overhead and development time. C offers low-level control and is
considered more readable than assembly. Many free C compilers are available for a wide
variety of development platforms. The compilers are part of an IDEs with ICD support,
breakpoints, single-stepping and an assembly window. The performance of C compilers has
improved considerably in recent years, and they are claimed to be more or less as good as
assembly, depending on who you ask. Most tools now offer options for customizing the
compiler optimization. Additionally, using C increases portability, since C code can be
compiled for different types of processors.
37

5.2.1 DIFFERENCE BETWEEN C AND EMBEDDED C


Though C and embedded C appear different and are used in different contexts, they
have more similarities than the differences. Most of the constructs are same; the difference
lies in their applications.
C is used for desktop computers, while embedded C is for microcontroller based
applications. Accordingly, C has the luxury to use resources of a desktop PC like memory,
OS, etc. While programming on desktop systems, we need not bother about memory.
However, embedded C has to use with the limited resources (RAM, ROM, I/Os) on an
embedded processor. Thus, program code must fit into the available program memory. If
code exceeds the limit, the system is likely to crash.
Compilers for C (ANSI C) typically generate OS dependant executables. Embedded
C requires
compilers
to
create
files
to
be
downloaded
to
the
microcontrollers/microprocessors where it needs to run. Embedded compilers give access to
all resources which is not provided in compilers for desktop computer applications.
Embedded systems often have the real-time constraints, which is usually not there with
desktop computer applications.
Embedded systems often do not have a console, which is available in case of desktop
applications.
So, what basically is different while programming with embedded C is the mindset; for
embedded applications, we need to optimally use the resources, make the program code
efficient, and satisfy real time constraints, if any. All this is done using the basic constructs,
syntaxes, and function libraries of C.

5.2.2 SOFTWARE USED IN THE PROJECT


MPLAB is a free integrated development environment for the development of embedded
applications on PIC and ds
PIC microcontrollers, and is developed by Microchip
Technology.
MPLAB X is the latest edition of MPLAB, and is developed on the Net
Beans platform. MPLAB and MPLAB X support project management, code editing,
debugging and programming of Microchip 8-bit, 16-bit and 32-bit PIC microcontrollers.
MPLAB is designed to work with MPLAB-certified devices such as the MPLAB ICD
3 and MPLAB REAL ICE, for programming and debugging PIC microcontrollers using
a personal computer. PIC Kit programmers are also supported by MPLAB.

38

STEP:1

39

STEP:3&4

40

STEP:6-8

41

STEP:9

42

STEP:10-12

43

STEP:13-14

44

STEP:15-17

45

STEP:18-19

46

STEP:20-22

47

STEP:23

48

STEP:24

49

CHAPTER 6
CONCLUSION
This paper elaborates the design and construction of automatic street control system
circuit. Circuit works properly to turn street lamp ON/OFF. After designing the circuit which
controls the light of the street as illustrated in the previous sections. LDR sensor and the
photoelectric sensors are the two main conditions in working the circuit. If the two conditions
have been satisfied the circuit will do the desired work according to specific program. Each
sensor controls the turning ON or OFF the lighting column. The street lights has been
successfully controlled by microcontroller. With commands from the controller the lights will
be ON in the places of the movement when it's dark. Further more the drawback of the street
light system using timer controller has been overcome, where the system depends on
photoelectric sensor. Finally this control circuit can be used in a long roadways between the
cities.
FUTURE ENHANCEMENT
Wireless is the buzz of communication industry today. The field of
wireless communication is growing leaps and bounds day by day. There have been many
advancements taking place in the semiconductor industry leading to more and more
advancements in wireless technology.
The main aim of the project is to save the power, by using effectively we can save
more power, as we know that there is shortage of power nowadays in every where mostly in
villages etc. So to overcome that we can provide street lights automatically with the
centralized intelligent systems. So in future we can design many more advanced technologies
to save power.

50

CHAPTER 7
REFERENCES
[1] D. A. Devi and A. Kumar, Design and Implementation of CPLD based Solar Power
Saving System for Street Lights and Automatic Traffic Controller, International Journal of
Scientific and Research Publications, Vol. 2, Issue11, November 2012.
[2] J. Mohelnikova, Electric Energy Savings and Light Guides, Energy& Environment, 3rd
IASME/WSEAS International Conference on, Cambridge, UK, February 2008, pp.470-474.
[3] M. A. Wazed, N. Nafis, M. T. Islam and A. S. M. Sayem, Design and Fabrication of
Automatic Street Light Control System, Engineering e-Transaction, Vol. 5, No. 1, June 2010,
pp 27-34.
[4] R. Priyasree, R. Kauser, E. Vinitha and N. Gangatharan, Automatic Street Light Intensity
Control and Road Safety Module Using Embedded System, International Conference on
Computing and Control Engineering, April 2012.
[5] K. S. Sudhakar, A. A. Anil, K. C. Ashok and S. S. Bhaskar, Automatic Street Light
Control System, International Journal of Emerging Technology and Advanced Engineering,
Vol. 3, May 2013, PP. 188-189.
[6] K.Y. Rajput, G. Khatav, M. Pujari, P. Yadav, Intelligent Street Lighting System Using
Gsm, International Journal of Engineering Science Invention, Vol2, Issue 3, March 2013, PP.
60- 69.
[7] M. Popa, C. Cepic, Energy Consumption Saving Solutions Based on Intelligent Street
Lighting Control System. U.P.B. Sci. Bull., Vol. 73, April 2011, PP. 297-308.
[8] R. Mohamaddoust, A. T. Haghighat, M. J. M. Sharif and N. Capanni, A Novel Design of
an Automatic Lighting Control System for a Wireless Sensor Network with Increased Sensor
Lifetime and Reduced Sensor Numbers, Sensors, Vol. 11, PP. 8933-8952.
[9] L. Jasio, T. Wilmshurst, D. Ibrahim, J. Morton, M. Bates, J. Smith D. Smith and C.
Hellebuyck, PIC Microcontrollers: know it all, Publishing Elsevier Science, 2008.
[10] W. Bolton. Instrumentation and Control Systems, Elsevier Science & Technology
Books, August 2004. [11] PIC16F87XA Data Sheet. 2003 Microchip Technology.

51

52

Вам также может понравиться