automatic headlight dimmer & automatic keyless entry

43
AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY A PROJECT REPORT Submitted by LAKSHMI NARAYANAN.G In partial fulfilment for the award of the degree Of BACHELOR OF TECHNOLOGY IN ELECTRONICS AND COMMUNICATION ENGINEERING COCHIN UNIVERSITY OF SCIENCE & TECHNOLOGYKOCHI-682022 JUNE, 2012

Upload: lngbabie19

Post on 27-Oct-2014

889 views

Category:

Documents


28 download

DESCRIPTION

*Automatic headlight dimmer uses a sensor which detects light coming from an opposite vehicle, and the circuit works using a relay to change the headlight from high beam to low beam. When the light from the opposite vehicle fades out, the circuit switches the headlight back to high beam mode. *Automatic key-less entry system ensures that the vehicle remains locked in the absence of the driver and unlocks itself when the driver comes near the door. It uses IR communication technique, embedded on drivers wrist watch.

TRANSCRIPT

Page 1: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

AUTOMATIC HEADLIGHT DIMMER

&

AUTOMATIC KEYLESS ENTRY

A PROJECT REPORT

Submitted by

LAKSHMI NARAYANAN.G

In partial fulfilment for the award of the degree

Of

BACHELOR OF TECHNOLOGY

IN

ELECTRONICS AND COMMUNICATION ENGINEERING

COCHIN UNIVERSITY OF SCIENCE & TECHNOLOGYKOCHI-682022

JUNE, 2012

Page 2: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

SCHOOL OF ENGINEERING

COCHIN UNIVERSITY OF SCIENCE &

TECHNOLOGY, KOCHI-682022

BONAFIDE CERTIFICATE

Certified that this project report “AUTOMATIC HEADLIGHT DIMMER

& AUTOMATIC KEYLESS ENTRY ” is the bonafide work of

“LAKSHMI NARAYANAN.G” who carried out the project work under my

supervision.

DR.GOPIKA KUMARI DR.REKHA K JAMES DR.BABITHA ROSELIND JOSE

HOD Associate Professor Assistant Professor

Division of Electronics Division of Electronics Division of Electronics

SOE, CUSAT SOE, CUSAT SOE, CUSAT

Page 3: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

ACKNOWLEDGEMENT

We are greatly indebted to God for his blessings and for helping us in the

successful completion of this project. We also express our sincere gratitude to

Dr.Gopika Kumari, Head of the Department of Electronics and Communication

engineering and to Dr Babitha Roselind Jose, Associate prof. of ECE,

Dr. Rekha James, and Miss Sumitha C, project guides, for providing us with

adequate facilities and means by which we were able to complete this project .

We express immense pleasure and gratitude to all the teachers and lab staff

of the department of Electronics and communication, CUSAT and our friends

Amjed Mohammed K A, Athul V Raj, Akhil Anand K A, S.O.E and Mohan sir

for their extended support and co-operation during our entire project work.

- Project Team

Page 4: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 1

1. ABSTRACT

Improvement of transportation facilities is considered as a

direct measure of the development of a nation. On that count India

has shown tremendous growth in the past decade or so. With an

increase in the no. of vehicles on road, unwanted incidents

including road accidents and auto thefts have become more

common. As a part of our mini project we have tried to develop

certain measures to reduce the above mentioned mishaps.

A majority of road accidents occur during night traffic. The

main reason behind night time accidents is the vision difficulty due

to the dazzling effect caused by high beam headlights of vehicles

coming in the opposite direction. The difficulty can be avoided by

proper dimming of headlights. Most cars on road these days use a

manual technique for dimming the headlights. But due to laziness

and carelessness, drivers seldom use the dimming switch. And

accidents happen.

Our mini project involves developing an automatic

headlight dimmer. It uses a sensor which detects light coming from

Page 5: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 2

an opposite vehicle, and the circuit works using a relay to change the

headlight from high beam to low beam. When the light from the

opposite vehicle fades out, the circuit switches the headlight back to

high beam mode.

The second part of our mini project deals with the issue of

Auto Thefts. We developed an automatic keyless entry system which

ensures that the vehicle remains locked in the absence of the driver

and unlocks itself when the drivers comes near the door .The main

advantage of this system is that it works automatically without the

driver having to bother about pressing any switch for locking or

unlocking. The driver carries a gadget which acts as the transmitter

section .The receiver part of the system is en cooperated within the

car. When the two modules are within a particular range and the car

engine is off, the car gets unlocked. In all other scenarios the car

remains in locked state.

Page 6: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 3

TABLE OF CONTENTS

No Title Page No

1. ABSTRACT 1

2. LIST OF FIGURES 5

3. HEAD LIGHT DIMMER 6

3.1 Sensor 8

3.2 Signal Amplifier 9

3.3 Relay Unit 9

3.4 Power Supply 10

3.5 Head Light Unit 10

3.6 LED Display 10

4. AUTOMATIC KEYLESS ENTRY 12

4.1 Receiver Unit 13

4.1.1 PIC 16F872 14

4.1.2 Oscillator 16

4.1.3 IR Receiver 16

4.1.4 LEDs and Push buttons 18

4.1.5 Voltage Regulator 18

4.2 Transmitter Unit 19

4.2.1 IR Transmitter 19

4.2.2 555 Timer 20

4.2.3 Power Supply 21

Page 7: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 4

5. PRINTED CIRCUIT BOARD 22

6. PCB LAYOUT 27

6.1 Automatic Head Light Dimmer 27

6.2 Automatic Keyless Entry 27

7. PROGRAM 28

8. DATASHEETS 30

9. REFERENCES 41

Page 8: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 5

2. LIST OF FIGURES

Title Page no

Automatic Headlight Dimmer-schematic diagram 7

Phototransistor 8

Keyless Entry schematic 13

PIC16f872 block diagram 15

IR receiver block diagram 16

IR receiver pin diagram 17

Voltage regulator 18

IR transmitter 19

555 timer 20

Headlight layout 27

Keyless Entry layout 27

Page 9: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 6

3. AUTOMATIC HEADLIGHT DIMMER

INTRODUCTION

The number of vehicles on our roads is burgeoning day by day. This in turn

forced almost all the vehicle manufactures to think about extra safety instruments and

electronic controls to attach with these products to ensure safety in all road conditions

through mass flow traffic. If asked, one should always mention that night driving is

very cumbersome due to the dazzling light problems and the frequent dimming of

headlights by manual means that often causes fatigue to the driver particularly at the

time of peak traffic. So naturally to get rid of this perennial problem, an automatic

mechanism has to come up to dim the headlamp automatically whenever required.

Simply, an automatic dipper is a unit, which can automatically judge when the

headlight beam needs to be lowered, and which dip the headlamp from High beam to

a dipped beam.

A problem may arise during city drives, that frequent detection of light may

cause flicker in the Headlight & this may cause trouble. This could be overcome by

limiting the action of DIMMER circuit only for HIGH beam & as city drive needs

only Low beam, the problem no longer exists. Another possible problem is detection

of Street lights. This could be solved by keeping sensor in such a way that,

possibility of detecting Street lights is minimal.

Page 10: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 7

CIRCUIT DIAGRAM:

The circuit is based on a photo transistor (Q2) for sensing the approaching

vehicles and transistor Q1 (BC177) for switching the relays for controlling the

headlight. When the light from the opposite vehicle falls on Q2 , it‟s collector current

increases and turns ON Q1.The relay will be activated and the head light will be

dimmed. When the vehicle pass over the reverse will happen.

The battery B1 can be the 12V car battery itself.

Adjust POT‟s R1,R2 and R4 to obtain optimum performance.

The Q1 can be any general purpose PNP photo transistor. It should be

mounted in front of the car so that the light from opposite vehicle easily falls

on it.

Relay contact A goes to high beam circuit , B to low beam circuit and C is

the common point.

Carefully understand the wiring of your car before attempting to install the

circuit. Wrong connections could easily bring trouble to your cars wiring.

Page 11: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 8

3.1 SENSOR

Phototransistor

The sensor used in the circuit is a phototransistor of pnp configuration by the

name KKT12R. When a ray of light falls at the base of the transistor,

correspondingly a small voltage is developed across the collector emitter terminals.

This functions as the key to the switching of the relays .

In the headlight dimmer circuit, the phototransistor is arranged in such a way

that its base is kept open and its collector emitter terminals are reverse biased.

Page 12: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 9

3.2 SIGNAL AMPLIFIER

The BC 177 transistor works as the signal amplifier in this circuit .It works in

such a way that its emitter is connected to the +ve terminal of a 12 volt supply .Its

collector is connected to the first relay. The base of the BC 177 is connected to the

collector of the phototransistor.

When the phototransistor detects light, a small voltage is developed at its

collector .This voltage is reaches the base of the signal amplifying transistor BC 177

and turns it on. As a result a comparatively larger voltage in the range of 12 volts is

developed across the emitter collector junction of the BC 177, used in the circuit.

Thus a small voltage is amplified into a larger voltage signal using this transistor.

This larger voltage is used to drive the relays in the circuit

3.3 RELAY UNIT

The relay unit in the circuit is for the automatic switching between the two

headlight modes, DIM and BRIGHT. The relay unit used comprises of 2 individual

identical relays. The first relay is used to drive the second one. The relays used in the

circuit are TGHJMKL.

The first relay is turned on when the signal from the amplifying transistor is

present at its input point. When tuned on it switches in such a way that the second

relay is turned on and it becomes a part of the working circuit.

In its OFF mode output of the second relay will be connected to the Headlight

circuit such that the headlight is in HIGH BEAM mode. When the second relay is

turned on by the first one, switching takes place and now its output will be connected

to the Headlight circuit such that the headlight is in LOW BEAM mode. When the

second relay is turned off by the first one in the absence of the signal from the

phototransistor, the circuit switches back to HIGH BEAM mode

Page 13: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 10

3.4 POWER SUPPLY

The Entire Project needs power for its operation. However, from the study of

this project it comes to know that we are supposed to design 12v dc power supply.

Since our project is to be implemented in a car, the battery of the car itself

can be used to draw power for the automatic headlight dimmer as well. Necessary

circuit should be implemented, so that the voltage be stepped downed to the

necessary 12V.

3.5 HEAD LIGHT UNIT

The headlight system used in our project is a small replica of the actual car

headlight system. It is an arrangement consisting of two similar 12V bulbs so

arranged so that one points to a farther point on the road, the HIGH BEAM bulb, and

other points at a nearer point on the road, the LOW BEAM bulb. The low beam bulb

is kept at an inclination with reference to the high beam bulb.

3.6 LED DISPLAY

An LED display is en cooperated on the PCB itself for a simpler

demonstration of the switching between the high beam and low beam circuits. A pair

of 3.2V green LEDs is used in the circuit. The 3.2 V necessary for the LEDs is

obtained by stepping down the 12V available from the source using resistance

circuits.

Page 14: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 11

CONCLUSION

The automatic headlight dimmer is a very simple circuit. It can be

implemented at a very low cost. But at present, the system is seen to be used in only

high end cars. If the government asks the car manufactures to make the automatic

headlight dimmer a mandatory component in all cars developed, a majority of night

time accidents can be avoided .

When implemented in cars the sensor should be placed at a location where the

light from opposite vehicles can be easily sensed. It will be appropriate if we use

multiple sensors. A sensor on top of the front glass and one at the bottom of the front

guard bumper will be enough.

Page 15: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 12

4. AUTOMATIC KEYLESS ENTRY

INTRODUCTION

Automatic keyless entry refers to the system in which the locking and

unlocking of the car can be implemented without using any manual keys or even

switches. A model of this phenomenon is the second part of our mini project.

It works using the principle of Infra Red Communication. The system

consists of two units, a transmitter unit and a receiver unit. The transmitter section is

a small gadget which will be in the hands of the driver, preferably embedded in his

watch. The receiver unit will be inside the car itself .

The simple process implemented is that the car will be in unlocked state

when its engine is off and the driver with his transmitting gadget is within the range

of communication. In all other cases the car will be left locked.

When the driver comes near the car, ie, within the IR communication range,

the IR transmitter sends a code which is received by the IR receiver and is decoded

inside the PIC .If the code matches with the one stored in the PIC the car gets

unlocked. The car gets back to locked state if and when the engine starts. The car

will also automatically get locked, if the driver with the transmitting gadget goes

beyond the vicinity of communication.

Page 16: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 13

KEYLESS ENTRY- SCHEMATIC

4.1 RECEIVER UNIT

The receiver section will be installed inside the car .It is the main component

of the automatic keyless entry containing the brain of the system, the PIC

microcontroller.

Besides the PIC, other major components inside the receiver unit are an IR

Receiver, an oscillator, a Voltage regulator, a Relay Unit, Push buttons and LEDs.

Page 17: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 14

4.1.1 PIC 16F872

The major heart of this project is the PIC16F872 microcontroller. The

PIC16F872 provides the following standard features: 4K bytes of flash, 368x8 bytes

of RAM, 22 I/O lines, Watchdog timer, two 8-bit, one 16-bit timer/counter, on-chip

oscillator, and clock circuitry. In addition, the PIC16F872 is designed with static

logic for operation down to zero frequency and supports software selectable power

saving modes.

The other features are:

Only 35 single word instructions to learn

Operating speed: DC - 20 MHz clock input

DC - 200 ns instruction cycle

Up to 256 x 8 bytes of EEPROM Data Memory

Interrupt capability (up to 14 sources)

Eight level deep hardware stack

Direct, indirect and relative addressing modes

Power-on Reset (POR)

Power-up Timer (PWRT) and

Oscillator Start-up Timer (OST)

Page 18: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 15

Page 19: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 16

4.1.2 OSCILLATOR

The oscillator used in the circuit is a 4 MHz crystal. It is used to provide the

necessary clock pulses for the PIC microcontroller. It decides the working speed of

the microcontroller.

4.1.3 IR RECEIVER

It is an active low device which means it gives low output when it receives

the Infrared rays.

The IR receiver used is of the TSOP17 series .They are miniaturized

receivers for infrared remote control systems. PIN diode and preamplifier are

assembled on lead frame, the epoxy package is designed as IR filter. The

demodulated output signal can directly be decoded by a microprocessor, here in our

case the PIC 16F72. TSOP17 is the standard IR remote control receiver series,

supporting all major transmission codes.

Page 20: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 17

IR RECEIVER PIN DIAGRAM

Features

Photo detector and preamplifier in one package

Internal filter for PCM frequency

Improved shielding against electrical field disturbance

TTL and CMOS compatibility

Output active low

Low power consumption

High immunity against ambient light

Continuous data transmission possible (up to 2400 bps)

Suitable burst length. 10 cycles/burst

Page 21: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 18

4.1.4 LEDs & PUSH BUTTONS

On the PCB two pairs of LEDs are used for demonstration and indication

purposes. The first pair consists of a blue one and a red one. The pair indicates the

activation of the system. When the keyless entry system is activated the red LED

will be glowing and when the system is off the blue one will be glowing.

The necessity of the system to go into non working state arises when the driver

is inside the car. In the real scenario the deactivation switch is placed under the

driver‟s seat, so that when he is seated the system will turn itself off. We have

implemented a push button switch to demonstrate the same.

The second pair indicates the state of the lock. It consists of a blue LED and a

green one. In locked state the blue one will be glowing and in the unlocked state the

green one will be glowing. The switching between the 2 states can be easily

understood by the change in the LED glowing.

4.1.5 VOLTAGE REGULATOR

The voltage regulator used in the system is a 7805 IC. It is a member of 78xx

series of fixed linear voltage regulator ICs. The voltage source in the circuit may

have fluctuations and would not give the fixed voltage output. The voltage regulator

IC maintains the output voltage at a constant value. The xx in 78xx indicates the

fixed output voltage it is designed to provide. 7805 provides +5V regulated power

supply. Capacitors of suitable values are connected at input and output pins

depending upon the respective voltage levels.

Page 22: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 19

4.2 TRANSMITTER

The transmitter section in the automatic keyless entry is a small gadget that

the driver carries around with him. The preferable scenario is that the transmitter unit

is embedded on the wrist watch of the driver or something similar.

The main component of the unit is an IR transmitter which keeps on sending

an IR code at a particular frequency expecting the receiver to decode it. When the

gadget comes near the car.ie, when the transmitter and receiver are within their

communication range, the code will be sensed and decoded by the receiver.

The major components of the transmitting unit beside the IR transmitter are a

555 timer and a power source.

4.2.1 IR TRANSMITTER

The IR transmitter used in the system is EVERLIGHT‟S Infrared Emitting

Diode (IR333-A) .It is a high intensity diode, moulded in a blue transparent plastic

package. The device is spectrally matched with phototransistor, photodiode and

infrared receiver module

Features

High reliability

High radiant intensity

Peak wavelength λp=940nm

2.54mm Lead spacing

Low forward voltage

Pb free

The product itself will remain within RoHS compliant version.

Page 23: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 20

Applications

Free air transmission system

IR remote control units with high power requirement

Smoke detector

Infrared applied system

4.2.2 555 TIMER

The 555 timer IC is an integrated circuit (chip) used in a variety of timer,

pulse generation, and oscillator applications. The 555 can be used to provide time

delays, as an oscillator, and as a flip-flop element. Derivatives provide up to four

timing circuits in one package.

Introduced in 1972 by Signetics, the 555 is still in widespread use, thanks to

its ease of use, low price, and good stability. It is now made by many companies in

the original bipolar and also in low-power CMOS types. As of 2003, it was

estimated that 1 billion units are manufactured every year.

The 555 timer is used in its astable multivibrator mode in our circuit. That

mode is also called free running mode. In this mode the 555 can operate as an

oscillator. Its uses include LED and lamp flashers, pulse generation, logic clocks,

tone generation, security alarms, pulse position modulation and so on.

Page 24: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 21

4.2.3 POWER SUPPLY

Power supply used for the transmitter is a 9V battery .It provides the

necessary power for 555 timer and the transistorIn the receiver unit, also a 9V

battery is used as power source for the PIC and other components.

CONCLUSION

Automatic keyless entry is a system which is developed with the objective of

improving the security features of a car. The system ensures that the car remains

locked in the absence of the driver even if he had forgot to manually lock the car. It

may come very helpful to careless people, old people and people in a hurry.

The system also ensures that the car gets unlocked automatically without the

driver having to scramble for the key in his pocket. It will come useful in cases when

the driver may be carrying something in both his hands. Also if the system is en

cooperated on the driver‟s wrist watch the chances of him losing the key will be

minimised.

Since a microcontroller is used in the system, the scope of improvement is

very high. Simply by altering the program, we could bring many more additional

security features. For example, the use of separate random keys each time for

communication will ensure that hacking of the lock system can be avoided.

Also if Radio Frequency communication is used in place of Infra Red

communication, better accuracy can be obtained. But if RF is used, steps should be

taken to minimise the range of communication (by using shields on top off

transmitter) for ideal implementation.

Page 25: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 22

5. PRINTED CIRCUIT BOARD

A printed circuit board, or PCB, is used to mechanically support and electrically

connect electronic components using conductive pathways, tracks or signal traces

etched from copper sheets laminated onto a non-conductive substrate. It is also

referred to as printed wiring board (PWB) or etched wiring board.

A PCB populated with electronic components is a printed circuit

assembly (PCA), also known as a printed circuit board assembly or PCB

Assembly (PCBA). Printed circuit boards are used in virtually all but the simplest

commercially produced electronic devices.

Alternatives to PCBs include wire wrap and point-to-point construction.

PCBs are often less expensive and more reliable than these alternatives, though they

require more layout effort and higher initial cost. PCBs are much cheaper and faster

for high-volume production since production and soldering of PCBs can be done by

automated equipment. Much of the electronics industry's PCB design, assembly, and

quality control needs are set by standards that are published by the IPC organization.

PCB Fabrication

A printed circuit board, or PCB, is used to mechanically support and

electrically connect electronic components using conductive pathways, or traces,

etched from copper sheets laminated onto a non-conductive substrate. Alternative

names are printed wiring board (PWB), and etched wiring board. A PCB populated

with electronic components is a printed circuit assembly (PCA), also known as a

printed circuit board assembly (PCBA).

PCB‟s are rugged, inexpensive, and can be highly reliable. They require

much more layout effort and higher initial cost than either wire-wrapped or point-to-

point constructed circuits, but are much cheaper, faster, and consistent in high

volume production. Conducting layers are typically made of thin copper foil.

Insulating materials has wider scale, phenolic paper, glass fiber and different plastics

are commonly used.

Page 26: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 23

Patterning (etching)

The vast majority of printed circuit boards are made by bonding a layer of

copper over the entire substrate, sometimes on both sides, (creating a “blank PCB”)

and then removing unwanted copper after applying a temporary mask (e.g. by

etching), leaving only the desired copper traces. A few PCB‟s are made by adding

traces to the bare substrate (or a substrate with a very thin layer of copper) usually by

a complex process of multiple electroplating steps.

Drilling

Holes, or vias, through a PCB are typically drilled with tiny drill bits made of

solid tungsten carbide. The drilling is performed by automated drilling machines

with placement controlled by a drill tape or drill file. These computer generated files

are also called numerically controlled drill (NCD) files or “Excellon files”. The drill

file describes the location and size of each drilled hole.

When very small vias are required, drilling with mechanical bits is costly

because of high rates of wear and breakage. In this case, the vias may be evaporated

by lasers. Laser drilled vias typically have an inferior surface finish inside the hole.

These holes are called microvias.

It is also possible with controlled-depth drilling, laser drilling, or by pre-

drilling the individual sheets of the PCB before lamination, to produce holes that

connect only some of the copper layers, rather than passing through the entire board.

These holes are called blind vias when they connect an internal copper layer to an

outer layer, or buried vias when they connect two or more internal copper layers and

no outer layers.

The walls of the holes, for boards with two or more layers are plated with

copper to form plated-through holes that electrically connect the conducting layers of

the PCB. For multi-layer boards, those with four layers or more, drilling typically

produces a smear comprised of the bonding agent in the laminate system. Before the

holes can be plated through, this smear must be removed by a chemical de-smear

process, or by plasma etch.

Page 27: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 24

Exposed conductor plating and coating

The places to which components will be mounted are typically plated, because

bare copper oxidized quickly, and therefore is not readily soldered. Traditionally,

any exposed copper was plated with the solder. This solder was a tin-lead alloy.

However, new solder compounds are

now used to achieve compliance with the RoHS directive in the European Union,

which restricts the use of lead. Other plating‟s used are OSP (organic surface

protectant), immersion silver, immersion tin, electro less nickel with immersion gold

plating (ENIG), and direct gold. Edge connectors placed along one edge of some

boards are often gold plated.

PCB design

To make a PCB, we must convert our corresponding pattern of desired copper

foil trace that will compose the finished board. These are basically two ways of

achieving this. Working from a manually drawn schematic, we can use a pencil and

paper to figure out a set of interconnection parts that does the job. We can convert

our hand drawn schematic to a connection „net list‟. Then use a CAD program to

figure the trace routing, producing a set of precision machine drain photo plots

directly. In this project, we use OrCAD for PCB design and layout.

CAD circuit based drawing

This method had many advantages including automatic net list extraction,

painless documentation, the ability to check for design and layout rule errors, the

ability to make changes relatively easy and the ability to produce complex multiplier

boards with precise alignment of pads and traces. It is the method of the choice for

nearly all complex and high density PCB production.

Page 28: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 25

Schematic capture

We begin by capturing our schematic directly into the graphic workstation.

We can draw and edit diagrams using standard electronics symbols from library. The

wiring can be moved around, signals can be named and the IC part numbers can be

given etc. A good CAD system assists us by looking the IC‟s and assigning pin

numbers.

Checking and simulation

The output from the schematic capture consists of a set of drawing and a net

list that is simply a list of every signal telling every node where it is connected to.

We can ask the system to simulate the digital circuit operation. But we must provide

it with test vectors that describe the machine state and we must describe the function

of each chip in our circuit that is not already described in this library.

Placement and routing

The next step is the component placement and routing. One of the greatest

advantages is that if the schematic is correct, then the final PCB will also be correct.

A good CAD system can flag design route errors as we make them so that we can

use it if the parts are too close together etc. Once the parts have been placed, the

wiring must be routed.

The current system provides auto routing the software and find connection

paths taking care not to violate design rules that specify not only the line widths and

clearness but also parameters such as the maximum number of „vias‟.

Photo and plot drill

If all has gone well, the last stages of the process consists of producing a

machine readable board description. For this, we need two things- a tape that tells

how to draw a precision plot of the artwork and a drill tape that tells each hole size

and its precise position.

Page 29: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 26

General Flow Chart In PCB Manufacturing

PCB ARTWORK (COREL DRAW)

PCB ARTWORK ON TRACING SHEET

SCREEN PRINTING (POLY BLUE)

PCB ARTWORK ON COPPER PLATE USING PAINT

ETCHING (FERRIC CHLORIDE)

REMOVAL OF PAINT FROM COPPER PLATE BY SCRUBBING

DRYING

DRILLING (0.9mm BIT) AND CLEANING

Page 30: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 27

6. PCB LAYOUT

6.1 AUTOMATIC HEADLIGHT DIMMER

6.2 AUTOMATIC KEYLESS ENTRY

Page 31: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 28

7. PROGRAM

#define Led_1 PORTC.F6

#define Led_2 PORTC.F5

#define RELAY PORTC.F4

#define In_1 PORTC.F1

#define Sw_1 PORTB.F6

#define Sw_2 PORTB.F7

unsigned int i=0,j=0,k=0,l=0;

void Init_Port(void)

{

TRISC.F4 = 0;

TRISC.F5 = 0;

TRISC.F6 = 0;

TRISC.F1 = 1;

TRISB.F6 = 1;

TRISB.F7 = 1;

ADCON0 = 0X00;

ADCON1 = 0X07;

Led_1 = 0;

Led_2 = 0;

RELAY = 0;

}

void main(void)

{

Init_Port();

Led_1 = 1;

Page 32: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 29

while(1)

{

if((i == 0)&&(In_1 == 0))

{

i = 5;

Led_1 = 0;

Led_2 = 1;

RELAY = 1;

}

if((i == 7)&&(Sw_2 == 1))

{

i = 9;

Led_1 = 0;

Led_2 = 1;

}

if((i == 9)&&(Sw_2 == 0))

{

i = 0;

Led_1 = 1;

Led_2 = 0;

RELAY = 0;

}

}

}

Page 33: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

1999 Microchip Technology Inc. Preliminary DS30221A-page 1

Devices Included in this Data Sheet:

Microcontroller Core Features:• High-performance RISC CPU• Only 35 single word instructions to learn• All single cycle instructions except for program

branches which are two cycle• Operating speed: DC - 20 MHz clock input

DC - 200 ns instruction cycle• 2K x 14 words of FLASH Program Memory

128 x 8 bytes of Data Memory (RAM)64 x 8 bytes of EEPROM Data Memory

• Pinout compatible to the PIC16C72A• Interrupt capability (up to 10 sources)• Eight level deep hardware stack• Direct, indirect and relative addressing modes• Power-on Reset (POR)• Power-up Timer (PWRT) and Oscillator Start-up

Timer (OST) • Watchdog Timer (WDT) with its own on-chip RC

oscillator for reliable operation• Programmable code-protection• Power saving SLEEP mode• Selectable oscillator options• Low-power, high-speed CMOS FLASH/EEPROM

technology• Fully static design• In-Circuit Serial Programming (ICSP) via two

pins• Single 5V In-Circuit Serial Programming capability• In-Circuit Debugging via two pins• Processor read/write access to program memory• Wide operating voltage range: 2.0V to 5.5V• High Sink/Source Current: 25 mA• Commercial and Industrial temperature ranges• Low-power consumption:

- < 2 mA typical @ 5V, 4 MHz- 20 µA typical @ 3V, 32 kHz- < 1 µA typical standby current

Pin Diagram

Peripheral Features:• Timer0: 8-bit timer/counter with 8-bit prescaler• Timer1: 16-bit timer/counter with prescaler,

can be incremented during sleep via externalcrystal/clock

• Timer2: 8-bit timer/counter with 8-bit periodregister, prescaler and postscaler

• One Capture, Compare, PWM module- Capture is 16-bit, max. resolution is 12.5 ns- Compare is 16-bit, max. resolution is 200 ns- PWM max. resolution is 10-bit

• 10-bit multi-channel Analog-to-Digital converter• Synchronous Serial Port (SSP) with SPI (Master

Mode) and I2C (Master/Slave)• Brown-out detection circuitry for Brown-out Reset

(BOR)

• PIC16F872

PIC

16F8

72

1011

23456

1

87

9

121314 15

1617181920

232425262728

2221

MCLR/VPP/THVRA0/AN0RA1/AN1

RA2/AN2/VREF-RA3/AN3/VREF+

RA4/T0CKIRA5/AN4/SS

VSS

OSC1/CLKINOSC2/CLKOUT

RC0/T1OSO/T1CKIRC1/T1OSIRC2/CCP1

RC3/SCK/SCL

RB7/PGDRB6/PGCRB5RB4RB3/PGMRB2RB1RB0/INTVDD

VSS

RC7RC6RC5/SDORC4/SDI/SDA

DIP, SOIC, SSOP

PIC16F87228-Pin, 8-Bit CMOS FLASH Microcontroller

Page 34: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 2 Preliminary 1999 Microchip Technology Inc.

Key FeaturesPICmicro™ Mid-Range Reference Manual

(DS33023)PIC16F872

Operating Frequency DC - 20 MHz

Resets (and Delays) POR, BOR(PWRT, OST)

FLASH Program Memory(14-bit words)

2K

Data Memory (bytes) 128

EEPROM Data Memory 64

Interrupts 10

I/O Ports Ports A,B,C

Timers 3

Capture/Compare/PWM module 1

Serial Communications MSSP

10-bit Analog-to-Digital Module 5 input channels

Instruction Set 35 Instructions

Page 35: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 6 Preliminary 1999 Microchip Technology Inc.

TABLE 1-1: PIC16F872 PINOUT DESCRIPTION

Pin Name DIPPin#

SOICPin#

I/O/PType

BufferType Description

OSC1/CLKIN 9 9 I ST/CMOS(3) Oscillator crystal input/external clock source input.

OSC2/CLKOUT 10 10 O — Oscillator crystal output. Connects to crystal or resonator in crystal oscillator mode. In RC mode, the OSC2 pin outputs CLKOUT,which has 1/4 the frequency of OSC1 and denotes the instruction cycle rate.

MCLR/VPP/THV 1 1 I/P ST Master clear (reset) input or programming voltage input or high voltage test mode control. This pin is an active low reset to the device.

PORTA is a bi-directional I/O port.

RA0/AN0 2 2 I/O TTL RA0 can also be analog input0.

RA1/AN1 3 3 I/O TTL RA1 can also be analog input1.

RA2/AN2/VREF- 4 4 I/O TTL RA2 can also be analog input2 or negative analog referencevoltage.

RA3/AN3/VREF+ 5 5 I/O TTL RA3 can also be analog input3 or positive analog referencevoltage.

RA4/T0CKI 6 6 I/O ST RA4 can also be the clock input to the Timer0 module. Outputis open drain type.

RA5/SS/AN4 7 7 I/O TTL RA5 can also be analog input4 or the slave select for thesynchronous serial port.

PORTB is a bi-directional I/O port. PORTB can be softwareprogrammed for internal weak pull-up on all inputs.

RB0/INT 21 21 I/O TTL/ST(1) RB0 can also be the external interrupt pin.

RB1 22 22 I/O TTL

RB2 23 23 I/O TTL

RB3/PGM 24 24 I/O TTL/ST(1) RB3 can also be the low voltage programming input.

RB4 25 25 I/O TTL Interrupt on change pin.

RB5 26 26 I/O TTL Interrupt on change pin.

RB6/PGC 27 27 I/O TTL/ST(2) Interrupt on change pin or In-Circuit Debugger pin. Serialprogramming clock.

RB7/PGD 28 28 I/O TTL/ST(2) Interrupt on change pin or In-Circuit Debugger pin. Serialprogramming data.

PORTC is a bi-directional I/O port.

RC0/T1OSO/T1CKI 11 11 I/O ST RC0 can also be the Timer1 oscillator output or Timer1 clockinput.

RC1/T1OSI 12 12 I/O ST RC1 can also be the Timer1 oscillator input.

RC2/CCP1 13 13 I/O ST RC2 can also be the Capture1 input/Compare1 output/PWM1output.

RC3/SCK/SCL 14 14 I/O ST RC3 can also be the synchronous serial clock input/output forboth SPI and I2C modes.

RC4/SDI/SDA 15 15 I/O ST RC4 can also be the SPI Data In (SPI mode) ordata I/O (I2C mode).

RC5/SDO 16 16 I/O ST RC5 can also be the SPI Data Out (SPI mode).

RC6 17 17 I/O ST

RC7 18 18 I/O ST

VSS 8, 19 8, 19 P — Ground reference for logic and I/O pins.

VDD 20 20 P — Positive supply for logic and I/O pins.

Legend: I = input O = output I/O = input/output P = power— = Not used TTL = TTL input ST = Schmitt Trigger input

Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt or LVP.2: This buffer is a Schmitt Trigger input when used in serial programming mode.3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

Page 36: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

1999 Microchip Technology Inc. Preliminary DS30221A-page 7

PIC16F872

2.0 MEMORY ORGANIZATIONThere are three memory blocks in each of thesePICmicro® MCUs. The Program Memory and DataMemory have separate buses, so that concurrentaccess can occur, and is detailed in this section. TheEEPROM data memory block is detailed inSection 4.0.

Additional information on device memory may be foundin the PICmicro Mid-Range Reference Manual,(DS33023).

2.1 Program Memory Organization

The PIC16F872 devices have a 13-bit program countercapable of addressing an 8K x 14 program memoryspace. The PIC16F872 device has 2K x 14 words ofFLASH program memory. Accessing a location abovethe physically implemented address will cause a wrap-around.

The reset vector is at 0000h and the interrupt vector isat 0004h.

FIGURE 2-1: PIC16F872 PROGRAMMEMORY MAP AND STACK

2.2 Data Memory Organization

The data memory is partitioned into multiple bankswhich contain the General Purpose Registers and theSpecial Function Registers. Bits RP1(STATUS<6>)and RP0 (STATUS<5>) are the bank select bits.

Each bank extends up to 7Fh (128 bytes). The lowerlocations of each bank are reserved for the SpecialFunction Registers. Above the Special Function Regis-ters are General Purpose Registers, implemented asstatic RAM. All implemented banks contain SpecialFunction Registers. Some “high use” Special FunctionRegisters from one bank may be mirrored in anotherbank for code reduction and quicker access.

2.2.1 GENERAL PURPOSE REGISTER FILE

The register file can be accessed either directly, or indi-rectly through the File Select Register FSR.PC<12:0>

13

0000h

0004h

0005h

Stack Level 1

Stack Level 8

Reset Vector

Interrupt Vector

On-Chip

CALL, RETURNRETFIE, RETLW

1FFFh

Stack Level 2

ProgramMemory

Page 0

07FFh

0800h

RP<1:0> Bank00 0

01 1

10 2

11 3

Note: EEPROM Data Memory description can befound in Section 4.0 of this Data Sheet

Page 37: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 8 Preliminary 1999 Microchip Technology Inc.

FIGURE 2-2: PIC16F872 REGISTER FILE MAP

Indirect addr.(*)

TMR0PCL

STATUSFSR

PORTAPORTBPORTC

PCLATHINTCON

PIR1

TMR1LTMR1HT1CONTMR2

T2CONSSPBUFSSPCONCCPR1LCCPR1H

CCP1CON

OPTION_REGPCL

STATUSFSR

TRISATRISBTRISC

PCLATHINTCON

PIE1

PCON

PR2SSPADDSSPSTAT

00h01h02h03h04h05h06h07h08h09h0Ah0Bh0Ch0Dh0Eh0Fh10h11h12h13h14h15h16h17h18h19h1Ah1Bh1Ch1Dh1Eh1Fh

80h81h82h83h84h85h86h87h88h89h8Ah8Bh8Ch8Dh8Eh8Fh90h91h92h93h94h95h96h97h98h99h9Ah9Bh9Ch9Dh9Eh9Fh

20h A0h

7Fh FFhBank 0 Bank 1

FileAddress

Indirect addr.(*) Indirect addr.(*)

PCLSTATUS

FSR

PCLATHINTCON

PCLSTATUS

FSR

PCLATHINTCON

100h101h102h103h104h105h106h107h108h109h10Ah10Bh

180h181h182h183h184h185h186h187h188h189h18Ah18Bh

17Fh 1FFhBank 2 Bank 3

Indirect addr.(*)

ADRESL

TMR0 OPTION_REG

PIR2 PIE2

ADRESHADCON0 ADCON1

GeneralPurposeRegister

GeneralPurposeRegister

1EFh1F0h

accessesA0h - BFh

16Fh170haccesses

70h-7Fh

TRISBPORTB

96 Bytes

32 Bytes

SSPCON2

10Ch10Dh10Eh10Fh110h

18Ch18Dh18Eh18Fh190h

EEDATAEEADR

EECON1EECON2

EEDATHEEADRH

Reserved(1)

Reserved(1)

Unimplemented data memory locations, read as ’0’. * Not a physical register.

Note 1: These registers are reserved; maintain these registers clear.

120h 1A0h

accesses70h-7Fh

accesses70h-7Fh

accesses20h-7Fh

C0h

EFhF0h

1C0h1BFhBFh

Page 38: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

1999 Microchip Technology Inc. Preliminary DS30221A-page 9

PIC16F872

2.2.2 SPECIAL FUNCTION REGISTERS

The Special Function Registers are registers used bythe CPU and peripheral modules for controlling thedesired operation of the device. These registers areimplemented as static RAM. A list of these registers isgiven in Table 2-1.

The Special Function Registers can be classified intotwo sets: core (CPU) and peripheral. Those registersassociated with the core functions are described indetail in this section. Those related to the operation ofthe peripheral features are described in detail in theperipheral feature section.

TABLE 2-1: SPECIAL FUNCTION REGISTER SUMMARY

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on:

POR,BOR

Value onall other resets

(2)

Bank 0

00h(3) INDF Addressing this location uses contents of FSR to address data memory (not a physical register) 0000 0000 0000 0000

01h TMR0 Timer0 module’s register xxxx xxxx uuuu uuuu

02h(3) PCL Program Counter's (PC) Least Significant Byte 0000 0000 0000 0000

03h(3) STATUS IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu

04h(3) FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu

05h PORTA — — PORTA Data Latch when written: PORTA pins when read --0x 0000 --0u 0000

06h PORTB PORTB Data Latch when written: PORTB pins when read xxxx xxxx uuuu uuuu

07h PORTC PORTC Data Latch when written: PORTC pins when read xxxx xxxx uuuu uuuu

08h — Unimplemented — —

09h — Unimplemented — —

0Ah(1,3) PCLATH — — — Write Buffer for the upper 5 bits of the Program Counter ---0 0000 ---0 0000

0Bh(3) INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u

0Ch PIR1 (4) ADIF (4) (4) SSPIF CCP1IF TMR2IF TMR1IF r0rr 0000 r0rr 0000

0Dh PIR2 — (4) — EEIF BCLIF — — (4) -r-0 0--r -r-0 0--r

0Eh TMR1L Holding register for the Least Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu

0Fh TMR1H Holding register for the Most Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu

10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu

11h TMR2 Timer2 module’s register 0000 0000 0000 0000

12h T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000

13h SSPBUF Synchronous Serial Port Receive Buffer/Transmit Register xxxx xxxx uuuu uuuu

14h SSPCON WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0 0000 0000 0000 0000

15h CCPR1L Capture/Compare/PWM Register1 (LSB) xxxx xxxx uuuu uuuu

16h CCPR1H Capture/Compare/PWM Register1 (MSB) xxxx xxxx uuuu uuuu

17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000

18h — Unimplemented — —

19h — Unimplemented — —

1Ah — Unimplemented — —

1Bh — Unimplemented — —

1Ch — Unimplemented — —

1Dh — Unimplemented — —

1Eh ADRESH A/D Result Register High Byte xxxx xxxx uuuu uuuu

1Fh ADCON0 ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON 0000 00-0 0000 00-0

Legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented read as ’0’, r = reserved.Shaded locations are unimplemented, read as ‘0’.

Note 1: The upper byte of the program counter is not directly accessible. PCLATH is a holding register for the PC<12:8> whose contents are transferred to the upper byte of the program counter.

2: Other (non power-up) resets include external reset through MCLR and Watchdog Timer Reset.3: These registers can be addressed from any bank.4: These bits are reserved; always maintain these bits clear.

Page 39: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

1999 Microchip Technology Inc. Preliminary DS30221A-page 85

PIC16F872

10.0 ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

The Analog-to-Digital (A/D) Converter module has fiveinputs.

The analog input charges a sample and hold capacitor.The output of the sample and hold capacitor is theinput into the converter. The converter then generatesa digital result of this analog level via successiveapproximation. The A/D conversion of the analog inputsignal results in a corresponding 10-bit digital number.The A/D module has high and low voltage referenceinput that is software selectable to some combinationof VDD, VSS, RA2 or RA3.

The A/D converter has a unique feature of being ableto operate while the device is in SLEEP mode. Tooperate in SLEEP, the A/D clock must be derived fromthe A/D’s internal RC oscillator.

The A/D module has four registers. These registersare:

• A/D Result High Register (ADRESH)• A/D Result Low Register (ADRESL)• A/D Control Register0 (ADCON0)• A/D Control Register1 (ADCON1)

The ADCON0 register, shown in Register 10-1, con-trols the operation of the A/D module. The ADCON1register, shown in Register 10-2, configures the func-tions of the port pins. The port pins can be configuredas analog inputs (RA3 can also be the voltage refer-ence) or as digital I/O.

Additional information on using the A/D module can befound in the PICmicro™ Mid-Range MCU Family Ref-erence Manual (DS33023).

REGISTER 10-1: ADCON0 REGISTER (ADDRESS: 1Fh)

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0

ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON R = Readable bitW = Writable bitU = Unimplemented bit,

read as ‘0’- n = Value at POR reset

bit7 bit0

bit 7-6: ADCS<1:0>: A/D Conversion Clock Select bits00 = FOSC/201 = FOSC/810 = FOSC/3211 = FRC (clock derived from an RC oscillation)

bit 5-3: CHS<2:0>: Analog Channel Select bits000 = channel 0, (RA0/AN0)001 = channel 1, (RA1/AN1)010 = channel 2, (RA2/AN2)011 = channel 3, (RA3/AN3)100 = channel 4, (RA5/AN4)

bit 2: GO/DONE: A/D Conversion Status bitIf ADON = 11 = A/D conversion in progress (setting this bit starts the A/D conversion)0 = A/D conversion not in progress (this bit is automatically cleared by hardware when the A/D conversionis complete)

bit 1: Unimplemented: Read as '0'

bit 0: ADON: A/D On bit1 = A/D converter module is operating0 = A/D converter module is shutoff and consumes no operating current

Page 40: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 86 Preliminary 1999 Microchip Technology Inc.

REGISTER 10-2: ADCON1 REGISTER (ADDRESS 9Fh)

U-0 U-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0

ADFM — — — PCFG3 PCFG2 PCFG1 PCFG0 R = Readable bitW = Writable bitU = Unimplemented bit,

read as ‘0’- n = Value at POR reset

bit7 bit0

bit 7: ADFM: A/D Result format select1 = Right Justified. 6 most significant bits of ADRESH are read as ‘0’.0 = Left Justified. 6 least significant bits of ADRESL are read as ‘0’.

bit 6-4: Unimplemented: Read as '0'

bit 3-0: PCFG<3:0>: A/D Port Configuration Control bits

A = Analog input

D = Digital I/O

Note 1: This column indicates the number of analog channels available as A/D inputs and the number of analog channelsused as voltage reference inputs.

PCFG<3:0> AN4RA5

AN3RA3

AN2RA2

AN1RA1

AN0RA0 VREF+ VREF- CHAN /

Refs(1)

0000 A A A A A VDD VSS 5/0

0001 A VREF+ A A A RA3 VSS 4/1

0010 A A A A A VDD VSS 5/0

0011 A VREF+ A A A RA3 VSS 4/1

0100 D A D A A VDD VSS 3/0

0101 D VREF+ D A A RA3 VSS 2/1

011x D D D D D VDD VSS 0/0

1000 A VREF+ VREF- A A RA3 RA2 3/2

1001 A A A A A VDD VSS 5/0

1010 A VREF+ A A A RA3 VSS 4/1

1011 A VREF+ VREF- A A RA3 RA2 3/2

1100 A VREF+ VREF- A A RA3 RA2 3/2

1101 D VREF+ VREF- A A RA3 RA2 2/2

1110 D D D D A VDD VSS 1/0

1111 D VREF+ VREF- D A RA3 RA2 1/2

Page 41: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 88 Preliminary 1999 Microchip Technology Inc.

FIGURE 10-1: A/D BLOCK DIAGRAM

10.1 A/D Acquisition Requirements

For the A/D converter to meet its specified accuracy,the charge holding capacitor (CHOLD) must be allowedto fully charge to the input channel voltage level. Theanalog input model is shown in Figure 10-2. Thesource impedance (RS) and the internal samplingswitch (RSS) impedance directly affect the timerequired to charge the capacitor CHOLD. The samplingswitch (RSS) impedance varies over the device voltage(VDD), Figure 10-2. The maximum recommendedimpedance for analog sources is 10 kΩ. As theimpedance is decreased, the acquisition time may bedecreased. After the analog input channel is selected(changed), this acquisition must be done before theconversion can be started.

To calculate the minimum acquisition time,Equation 10-1 may be used. This equation assumesthat 1/2 LSb error is used (1024 steps for the A/D). The1/2 LSb error is the maximum error allowed for the A/Dto meet its specified resolution.

To calculate the minimum acquisition time, TACQ, seethe PICmicro™ Mid-Range Reference Manual(DS33023).

(Input voltage)

VAIN

VREF+

(Referencevoltage)

VDD

PCFG<3:0>

CHS<2:0>

RA5/AN4

RA3/AN3/VREF+

RA2/AN2/VREF-

RA1/AN1

RA0/AN0

100

011

010

001

000

A/DConverter

VREF-

(Referencevoltage)

VSS

PCFG<3:0>

Page 42: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

PIC16F872

DS30221A-page 112 Preliminary 1999 Microchip Technology Inc.

TABLE 12-2: PIC16CXXX INSTRUCTION SET Mnemonic,Operands

Description Cycles 14-Bit Opcode StatusAffected

Notes

MSb LSb

BYTE-ORIENTED FILE REGISTER OPERATIONS

ADDWFANDWFCLRFCLRWCOMFDECFDECFSZINCFINCFSZIORWFMOVFMOVWFNOPRLFRRFSUBWFSWAPFXORWF

f, df, df-f, df, df, df, df, df, df, df-f, df, df, df, df, d

Add W and fAND W with fClear fClear WComplement fDecrement fDecrement f, Skip if 0Increment fIncrement f, Skip if 0Inclusive OR W with fMove fMove W to fNo OperationRotate Left f through CarryRotate Right f through CarrySubtract W from fSwap nibbles in fExclusive OR W with f

111111

1(2)1

1(2)111111111

000000000000000000000000000000000000

011101010001000110010011101110101111010010000000000011011100001011100110

dfffdffflfff0xxxdfffdfffdfffdfffdfffdfffdffflfff0xx0dfffdfffdfffdfffdfff

ffffffffffffxxxxffffffffffffffffffffffffffffffff0000ffffffffffffffffffff

C,DC,ZZZZZZ

Z

ZZ

CC

C,DC,Z

Z

1,21,22

1,21,2

1,2,31,2

1,2,31,21,2

1,21,21,21,21,2

BIT-ORIENTED FILE REGISTER OPERATIONS

BCFBSFBTFSCBTFSS

f, bf, bf, bf, b

Bit Clear fBit Set fBit Test f, Skip if ClearBit Test f, Skip if Set

11

1 (2)1 (2)

01010101

00bb01bb10bb11bb

bfffbfffbfffbfff

ffffffffffffffff

1,21,233

LITERAL AND CONTROL OPERATIONS

ADDLWANDLWCALLCLRWDTGOTOIORLWMOVLWRETFIERETLWRETURNSLEEPSUBLWXORLW

kkk-kkk-k--kk

Add literal and WAND literal with WCall subroutineClear Watchdog TimerGo to addressInclusive OR literal with WMove literal to WReturn from interruptReturn with literal in WReturn from SubroutineGo into standby modeSubtract W from literalExclusive OR literal with W

1121211222111

11111000101111001100001111

111x10010kkk00001kkk100000xx000001xx00000000110x1010

kkkkkkkkkkkk0110kkkkkkkkkkkk0000kkkk00000110kkkkkkkk

kkkkkkkkkkkk0100kkkkkkkkkkkk1001kkkk10000011kkkkkkkk

C,DC,ZZ

TO,PD

Z

TO,PDC,DC,Z

Z

Note 1: When an I/O register is modified as a function of itself ( e.g., MOVF PORTB, 1), the value used will be that value present on the pins themselves. For example, if the data latch is ’1’ for a pin configured as input and is driven low by an external device, the data will be written back with a ’0’.

2: If this instruction is executed on the TMR0 register (and, where applicable, d = 1), the prescaler will be cleared if assigned to the Timer0 Module.

3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.

Note: Additional information on the mid-range instruction set is available in the PICmicro™ Mid-Range MCU FamilyReference Manual (DS33023).

Page 43: AUTOMATIC HEADLIGHT DIMMER & AUTOMATIC KEYLESS ENTRY

Page | 41

REFERENCES

BIBLIOGRAPHY

Customizing and programming microcontroller-Myke Predcko-TMH

publication-2000

FIM30 user manual.

C programming for embedded systems- Kirk Zurell

Embedded Microcomputer system- Onathan W.Valvano PHI

publication2000

Microcontroller inter facing- Douglas V.hall TMH publication-2000

Automotive Electronics And Computer Controls- Barry Hollem Beak

Automotive Electrical Equipment- P.L. Kohli

WEBILOGRAPHY

www.microchips.com

www.max232n.com/texas

www.mikroelektronika.co.yu/english/product/books/PICbook/0_Uvod.

www.wikipedia.com

www.atmel.databook.com