Sie sind auf Seite 1von 71

INTRODUCTION

It is microcontroller based application by using microcontroller we can develop application like autonomous robots, electronic projects and other embedded system applications. We are making pick n drop robot. We controlling this robot with remote. We can use this for picking object from one place and move it to another place and place it on other place.it is one of the embedded application.

Embedded System:
Microcontroller are widely used in Embedded System products. An Embedded product uses the microprocessor(or microcontroller) to do one task & one task only. A printer is an example of Embedded system since the processor inside it perform one task only namely getting the data and printing it. Contrast this with Pentium based PC. A PC can be used for any no. of applications such as word processor, print server, bank teller terminal, video game player, network server or internet terminal. Software for variety of applications can be loaded and run. Of course the reason a PC can perform multiple task is that it has RAM memory and an operating system that loads the application software into RAM & lets the CPU run it. In and Embedded system there is only one application software that is typically burn into ROM. An x86PC Contain or its connected to various Embedded Products such as keyboard, printer, modem, Disc controller, Sound card, CD-Rom Driver, Mouse & so on. Each one of these peripherals as a microcontroller inside it that performs only one task. For example inside every mouse there is microcontroller to perform the task of finding the mouse position and sending it to PC. Although microcontroller are preferred choice for many Embedded systems, There are times that a microcontroller is inadequate for the task. For this reason in recent years many manufactures of general purpose microprocessors such as INTEL, Motorolla, AMD & Cyrix have targeted their microprocessors for the high end of Embedded market. While INTEL, AMD, Cyrix push their x86 processors for both the embedded and desktop pc market, Motorolla is determined to keep the 68000 families alive by targeting it mainly for high end of embedded system.

One of the most critical needs of the embedded system is to decrease power consumptions and space. This can be achieved by integrating more functions into the CPU chips. All the embedded processors based on the x86 and 680x0 have low power consumptions in additions to some forms of I/O, Com port & ROM all on a single chip. In higher performance Embedded system the trend is to integrate more & more function on the CPU chip & let the designer decide which feature he/she wants to use.

1.1

MICROPROCESSOR (MPU)
A microprocessor is a general-purpose digital computer central processing unit (CPU).

Although popularly known as a computer on a chip is in no sense a complete digital computer. The block diagram of a microprocessor CPU is shown, which contains an arithmetic and logical unit (ALU), a program counter (PC), a stack pointer (SP),some working registers, a clock timing circuit, and interrupt circuits.

BLOCK DIAGRAM OF A MICROPROCESSOR

1.2

MICROCONTROLLERS (MCU) Figure shows the block diagram of a typical microcontroller, which is a true computer on

a chip. The design incorporates all of the features found in micro-processor CPU: ALU, PC, SP, and registers. It also added the other features needed to make a complete computer: ROM, RAM, parallel I/O, serial I/O, counters, and clock circuit.

BLOCK DIAGRAM OF A MICROCONTROLLER

1.3

COMPARISON BETWEEN MICROPROCESSORS AND MICROCONTROLLERS

PIN CONFIGURATIONS Total pins Address pins Data pins Interrupt pins I/O pins ARCHITECTURE 8-bit registers 16-bit registers Stack size Internal ROM Internal RAM External memory Timers Flags

MPU 40 16(fixed) 8(fixed) 2(fixed) 0 20 4 64 0 0 64K 0 6

MCU 40 16 8 2 32 34 2 128 4K 128 128K 2 4

The microprocessor must have many additional parts to be operational as a computer whereas microcontroller requires no additional external digital parts. The prime use of microprocessor is to read data, perform extensive calculations on that data and store them in the mass storage device or display it. The prime functions of microcontroller is to read data, perform limited calculations on it, control its environment based on these data. Thus the microprocessor is said to be general-purpose digital computers whereas the microcontroller are intend to be special purpose digital controller. Microprocessor need many opcodes for moving data from the external memory to the CPU, microcontroller may require just one or two, also microprocessor may have one or two types of bit handling instructions whereas microcontrollers have many. Thus microprocessor is concerned with the rapid movement of the code and data from the external addresses to the chip, microcontroller is concerned with the rapid movement of the bits within the chip. Lastly, the microprocessor design accomplishes the goal of flexibility in the hardware configuration by enabling large amounts of memory and I/O that could be connected to

the address and data pins on the IC package. The microcontroller design uses much more limited set of single and double byte instructions to move code and data from internal memory to ALU.

WHAT IS ROBOTIES?
Whenever we talk about robot two questions come to our mind What is a Robot ? What does it do? What is a robot? The word robot comes from the Czech word Robota, which means obligatory work or servitude or forced labour. The word robot was first used in 1921by Karl Capek in a Czech play called R.U.R. (Rossum's Universal Robots) .The play depicts a race of humanoid robots that turn on their masters and destroy them. A theme that robots will take control of their creators seems always to be associated with robots. What does it do? As stated by the Robot Institute of America. A robot is a programmable multi functional manipulator designed to move material, parts, tools or specialized devices through variable programmed motions for the performance of a variety of tasks. The modern definition of a robot classifies it as a system which has : One or more sensors to interact with the environment A program that processes the inputs received from the environment A decision maker, who on the basis of processed inputs decides what action to be performed , also in charge of overall operations A mechanical assemblage like an arm, hand, or other moving part to perform the intended function like lifting, assembling, or moving something .

An electrical assemblage which provides the motive force to the mechanical parts In short A robot is a machine designed to execute one or more tasks repeatedly, with speed and precision Issac Asimov , Russian science fiction writer, coined the word Robotics in his story Runaround ( 1942) , to denote the science devoted to the study of robots. LAWS OF ROBOTICS Issac Asimov conceived the robots as humanoids, devoid of feelings' His robots were well-designed, fail-safe machines, whose brains were programmed by human beings. Anticipating the dangers and havoc such a device could cause, he postulated three rules of Robotics , and they are: A robot should not injure a human being or, through inaction, allow a human to be harmed A robot must obey orders given by humans except when that conflicts with the First law A robot must protect its own existence unless that conflict with the First or Second law Later, Asimov added the "zeroth" law: A robot may not injure humanity, or, through inaction, allow humanity to come to harm. Japan's ministry guidelines require manufacturers To install a sufficient number of sensors to keep robots from running into people. To use Lighter or softer materials prevent injury. To provide Emergency shut-off buttons prominently placed for easy access by concerned humans for controlling out-of-control machines First Generation The first generation robots arc repeating, non servo, pick-andelectromechanical devices without sensors. They were mostly in automobile industry for welding and assembly work in factories. The technology is fully developed and at present about 80% robots in use in the industry are of this kind. It is predicted that these will continue to be in use for a long time. Second Generation Second-generation robots were developed in the 1980s place, or point to- point kind. First-generation robots date from the 1970s and consist of stationary, nonprogrammable,

They have sensors and programmable controllers. The addition of sensing devices and enabling the robot to alter its movements in response to sensory feedback Third Generation The third generation is marked with robots having human like intelligence. Thirdgeneration robots were developed between approximately 1990 and the present. The growth in computers led to high-speed processing of information and, thus, robots also acquired artificial intelligence, self-learning, on-line computations and control and conclusion drawing capabilities by past experiences. These machines can be stationary or mobile, autonomous or insect type, with sophisticated programming, speech recognition and/or synthesis, and other advanced features. The technology is still in infancy and has to go a long way. Fourth Generation This is futuristic and may be a reality only during the millennium. Prediction about its features is difficult, if not impossible. It may be a true android or an artificial biological robot or a super humanoid capable of producing its own clones. This might provide for fifth and higher generation robots. Androids are advanced kind of Robo because of their superficial resemblance to human beings. Androids are mobile, usually moving around on wheels or a track drive not look or behave anything like humans. The ultimate in robotic intelligence and sophistication might take on forms yet to be imagined. An android is a robot designed to look and act human. The word derives from Greek Though the word derives from a gender-specific root, its usage in English is usually gender neutral. The term "android" appears in US patents as early as 1863 in reference to miniature humanlike toy automations. Gynoid is a term used to describe a robot designed to look like a human female, as compared to an android modeled after a male. The term is not common, however, with android often being used to refer to both "genders" of robot. These robots exhibit path-control capabilities. This technological breakthrough came around 1980s

An android is a robot designed to look and act human.

HARDWARE AND SOFTWARE REQUIREMENTS Hardware Name 1. Microcontroller PIC16f877A 2. DC geared motor 3. Servo motor 4. L293D 5. ILQ74 6. IR Sensor 7. Crystal oscillator 8. Voltage regulator(7805) 9. Capacitor 10. Resistor 11. Light emitting diode 12. Switch(3 pin) 13. Push button 14. Battery(12v) 15. Chassis Board 16. Tyre 17. Track 18. Screws/nut/bolts 19. Sony TV Remote 20. Wooden Sheet 21. IC BASE Component list Quantity 01 03 01 02 02 01 01 01 08 18 01 01 01 01 01 04 04 --01 01 05

COMPONENT DESCRIPTION
Motors Electrical Motor Converts electrical energy into mechanical energy. There are two types of electrical motors. AC motors designed to run on AC electric power. DC motor designed to run on DC electric power. For our study we would be focusing on learning of DC motors Types of DC motors 1. 2. 3. 4. Brushed DC motors Brushless DC motors Servo motors Stepper DC

All DC motors require two magnetic fields: One produced by the stationary part of the motor (the stator, or field), Second and one by the rotating part (the rotor, or armature). These are produced either by a winding of coils carrying a current, or by permanent magnets. If the field is a coil of wire, this may be connected in a variety of ways, which produces different motor characteristics. We will learn DC motors where: Magnetic field is produced by permanent magnets STATOR Armature has set of coils which produces magnetic field when current passes through the coils ---- Rotor

10

RELATIVE ARRANGEMENTS OF COMPONENTS OF A DC MOTOR

Stator The stator generates a stationary magnetic field that surrounds the rotor. This field is generated by either permanent magnets or electromagnetic windings. Rotor, also called the armature, Made up of one or more windings. When these windings are energized they produce a magnetic field. The magnetic poles of This rotor field will be attracted to the opposite poles generated by the stator, causing the rotor to turn. As the motor turns, the windings are constantly being energized in a different sequence so that the magnetic poles generated by the rotor do not overrun the poles generated in the stator. This switching of the field in the rotor windings is called commutation.

11

12

Permanent Magnet Brushed DC (PMDC) Most common motors Permanent magnets produce the stator field. PMDC motors are generally used in applications involving FHP The drawback is that the magnets lose their magnetic properties over time.

The performance curve (voltage vs. speed), is very linear

BASIC DRIVE CIRCUITS Drive circuits are used in applications where a controller is being used and speed control is required.

The purpose of a drive circuit is to give the controller a way to vary the current in the windings of the BDC motor. In our application, the drive circuits are based on pulse width modulation of the voltage supplied to a BDC motor. In terms of power consumption, this method of speed control is a far more efficient way to vary the speed of a BDC motor compared to traditional analog control methods. BDC motors are driven in a variety of ways. Unlike other electric motor (i.e., brushless DC, AC induction), BDC motors do not require a controller to switch current in the motor windings. Instead, the commutation of the windings of a BDC motor is done Mechanically.

Brushes and Commutator

13

A segmented copper sleeve, called a commutator, resides on the axle of a BDC motor. As the motor turns, carbon brushes slide over the commutator, coming in contact with different segments of the commutator. The segments are attached to different rotor windings, therefore, a dynamic magnetic field is generated inside the motor when a voltage is applied across the brushes of the motor.

Prone to wear To run the motor in forward direction

To run the motor in reverse direction Servos motors:

Gearing and feedback control loop circuitry (No motor drivers required) Most servo motors can rotate about 90 to 180 degrees. Some rotate through a full 360 degrees However, servos are unable to continually rotate (unless modified), Precision positioning makes them ideal for robot arms and legs, rack and pinion steering, and sensor scanners

14

To connect a servo, All servos have three wires: Black or Brown is for ground. Red is for power (~4.8-6V). Yellow, Orange, or White is the signal wire (3-5V). To operate a servo Servos can be programmed for direction of rotation By varying the square wave pulse width from 1-2ms for controlling position/velocity L293d The L293 is an integrated circuit motor driver used for: Simultaneous, bi-directional control of two small motors. Sourcing capacity is limited to 600 mA Use heat sinking to keep the case temperature down. L293 comes in a standard 16-pin, dual-in line IC package. L293D has built in fly-back diodes to minimize inductive voltage spikes. ,

15

16

Arrangement for Two motors in one direction One motor in both directions

17

ILQ74 Optocoupler, Phototransistor Output: IL74/ILD74/ILQ74 is an optically coupled pair with a GaAIAs infrared LED and a silicon NPN phototransistor.
18

Signal information, including a DC level, can be transmitted by the device while maintaining a high degree of electrical isolation between input and output.

It can be used to replace relays and transformers in many digital interface applications, as well as analog applications

The LQ74 has four isolated channels per package

Treat an optocoupler as a device with two components:

The input LED Output transistor As the two are electrically isolated, we have flexibility of connecting them into circuit. All we really have to do is work out a convenient way of turning the input LED on and

off Turning on and off LED will be used for switching of the phototransistor to generate an output waveform or logic

19

Switches Selecting a Switch There are three important features to consider when selecting a switch:

Circuit symbol for a simple on-off switch

Contacts (e.g. single pole, double throw) Ratings (maximum voltage and current) Method of Operation (toggle, slide, key etc.)

SWITCH CONTACTS Several terms are used to describe switch contacts:


Pole - number of switch contact sets. Throw - number of conducting positions, single or double. Way - number of conducting positions, three or more. Momentary - switch returns to its normal position when released. Open - off position, contacts not conducting. Closed - on position, contacts conducting, there may be several on positions.
20

For example: the simplest on-off switch has one set of contacts (single pole) and one switching position which conducts (single throw). The switch mechanism has two positions: open (off) and closed (on), but it is called 'single throw' because only one position conducts. Switch Contact Ratings Switch contacts are rated with a maximum voltage and current, and there may be different ratings for AC and DC. The AC values are higher because the current falls to zero many times each second and an arc is less likely to form across the switch contacts. For low voltage electronics projects the voltage rating will not matter, but you may need to check the current rating. The maximum current is less for inductive loads (coils and motors) because they cause more sparking at the contacts when switched off.

STANDARD SWITCHES Type of Switch Circuit Symbol Example

21

ON-OFF Single Pole, Single Throw = SPST A simple on-off switch. This type can be used to switch the power supply to a circuit. When used with mains electricity this type of switch must be in the live wire, but it is better to use a DPST switch to isolate both live and neutral. (ON)-OFF Push-to-make = SPST Momentary A push-to-make switch returns to its normally open (off) position when you release the button, this is shown by the brackets around ON. This is the standard doorbell switch. ON-(OFF) Push-to-break = SPST Momentary A push-to-break switch returns to its normally closed (on) position when you release the button. ON-ON Single Pole, Double Throw = SPDT This switch can be on in both positions, switching on a separate device in each case. It is often called a changeover switch. For example, a SPDT switch can be used to switch on a red lamp in one position SPDT toggle switch Push-to-break switch Push-to-make switch SPST toggle switch

22

and a green lamp in the other position. A SPDT toggle switch may be used as a simple on-off switch by connecting to COM and one of the A or B terminals shown in the diagram. A and B are interchangeable so switches are usually not labelled. ON-OFF-ON SPDT Centre Off A special version of the standard SPDT switch. It has a third switching position in the centre which is off. Momentary (ON)OFF-(ON) versions are also available where the switch returns to the central off position when released. Dual ON-OFF Double Pole, Single Throw = DPST A pair of on-off switches which operate together (shown by the dotted line in the circuit symbol). A DPST switch is often used to switch mains electricity because it can isolate both the live and neutral connections. Dual ON-ON Double Pole, Double Throw = DPDT A pair of on-on switches which operate together (shown by the dotted line in DPST rocker switch SPDT rocker switch SPDT slide switch (PCB mounting)

23

the circuit symbol). A DPDT switch can be wired up as a reversing switch for a motor as shown in the diagram. ON-OFF-ON DPDT Centre Off A special version of the standard SPDT switch. It has a third switching position in the centre which is off. This can be very useful for motor control because you have forward, off and reverse positions. Momentary (ON)-OFF-(ON) versions are also available where the switch returns to the central off position when released. Wiring for Reversing Switch DPDT slide switch

24

SPECIAL SWITCHES Type of Switch Push-Push Switch (e.g. SPST = ON-OFF) This looks like a momentary action push switch but it is a standard on-off switch: push once to switch on, push again to switch off. This is called a latching action. Microswitch (usually SPDT = ON-ON) Microswitches are designed to switch fully open or closed in response to small movements. They are available with levers and rollers attached. Keyswitch A key operated switch. The example shown is SPST. Tilt Switch (SPST) Tilt switches contain a conductive liquid and when tilted this bridges the contacts inside, closing the switch. They can be used as a sensor to detect the position of an object. Some tilt switches contain mercury which is poisonous. Reed Switch (usually SPST) The contacts of a reed switch are closed by bringing a small magnet near the switch. They are used in security circuits, for example to check that doors are closed. Standard reed switches are SPST (simple on-off) but SPDT (changeover) versions are also available. Warning: reed switches have a glass body which is easily Example

25

broken!

For

advice

on

handling

please

see

the

Electronics in Meccano website. DIP Switch (DIP = Dual In-line Parallel) This is a set of miniature SPST on-off switches, the example shown has 8 switches. The package is the same size as a standard DIL (Dual In-Line) integrated circuit. This type of switch is used to set up circuits, e.g. setting the code of a remote control. Multi-pole Switch The picture shows a 6-pole double throw switch, also known as a 6-pole changeover switch. It can be set to have momentary or latching action. Latching action means it behaves as a push-push switch, push once for the first position, push again for the second position etc. Multi-way Switch Multi-way switches have 3 or more conducting positions. They may have several poles (contact sets). A popular type has a rotary action and it is available with a range of contact arrangements from 1-pole 12-way to 4-pole 3 way. The number of ways (switch positions) may be reduced by adjusting a stop under the fixing nut. For example if you need a 2pole 5-way switch you can buy the 2-pole 6-way version and adjust the stop. Contrast this multi-way switch (many switch positions) with the multi-pole switch (many contact sets) described above. 1-pole 4-way switch symbol Multi-way rotary switch

26

27

RESISTORS
Colour Code | Tolerance | Real Values (E6 & E12 series) | Power Rating Example: FUNCTION Resistors restrict the flow of electric current, for example a resistor is placed in series with a light-emitting diode (LED) to limit the current passing through the LED. CONNECTING AND SOLDERING Circuit symbol:

The Resistor Colour Code Colour Number Black Brown 0 1 2 3 4 5 6 7 8 9

Resistors may be connected either way round. They are not damaged by heat Red Orange when soldering. Yellow Resistor values - the resistor colour code Resistance is measured in ohms, the symbol for ohm is an omega 1 1k is quite small so resistor values are often given in k = 1000 values 1 M = 1000000 . are normally shown using coloured bands. and M . . Green Blue Violet Grey White

Resistor

Each colour represents a number as shown in the table. Most resistors have 4 bands:

The first band gives the first digit. The second band gives the second digit. The third band indicates the number of zeros. The fourth band is used to shows the tolerance (precision) of the resistor, this may be ignored for almost all circuits but further details are given below.

28

This resistor has red (2), violet (7), yellow (4 zeros) and gold bands. So its value is 270000 = 270 k . On circuit diagrams the is usually omitted and the value is written 270K.

Find out how to make your own Resistor Colour Code Calculator

Small value resistors (less than 10 ohm) The standard colour code cannot show values of less than 10 . To show these small values two special colours are used for the third band: gold which means 0.1 and silver which means 0.01. The first and second bands represent the digits as normal. For example: red, violet, gold bands represent 27 0.1 = 2.7 green, blue, silver bands represent 56 0.01 = 0.56 Tolerance of resistors (fourth band of colour code) The tolerance of a resistor is shown by the fourth band of the colour code. Tolerance is the precision of the resistor and it is given as a percentage. For example a 390 39 = 429 (39 is 10% of 390). A special colour code is used for the fourth band tolerance: silver 10%, gold 5%, red 2%, brown 1%. If no fourth band is shown the tolerance is 20%. Tolerance may be ignored for almost all circuits because precise resistor values are rarely required. resistor with a and 390 + tolerance of 10% will have a value within 10% of 390 , between 390 - 39 = 351

29

RESISTOR SHORTHAND Resistor values are often written on circuit diagrams using a code system which avoids using a decimal point because it is easy to miss the small dot. Instead the letters R, K and M are used in place of the decimal point. To read the code: replace the letter with a decimal point, then multiply the value by 1000 if the letter was K, or 1000000 if the letter was M. The letter R means multiply by 1. For example: 560R means 560 2K7 means 2.7 k = 2700 39K means 39 k 1M0 means 1.0 M = 1000 k

Real resistor values (the E6 and E12 series) You may have noticed that resistors are not available with every possible value, for example 22k and 47k are readily available, but 25k and 50k are not! giving 10, 20, 30, 40,

Why is this? Imagine that you decided to make resistors every 10

50 and so on. That seems fine, but what happens when you reach 1000? It would be pointless to make 1000, 1010, 1020, 1030 and so on because for these values 10 is a very small difference, too small to be noticeable in most circuits. In fact it would be difficult to make resistors sufficiently accurate. To produce a sensible range of resistor values you need to increase the size of the 'step' as the value increases. The standard resistor values are based on this idea and they form a series which follows the same pattern for every multiple of ten. The E6 series (6 values for each multiple of ten, for resistors with 20% tolerance) 10, 15, 22, 33, 47, 68, ... then it continues 100, 150, 220, 330, 470, 680, 1000 etc. Notice how the step size increases as the value increases. For this series the step (to the next value) is roughly half the value.

30

The E12 series (12 values for each multiple of ten, for resistors with 10% tolerance) 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82, ... then it continues 100, 120, 150 etc. Notice how this is the E6 series with an extra value in the gaps. The E12 series is the one most frequently used for resistors. It allows you to choose a value within 10% of the precise value you need. This is sufficiently accurate for almost all projects and it is sensible because most resistors are only accurate to 10% (called their 'tolerance'). For example a resistor marked 390 could be any value between 351 and 429 . Resistors in Series and Parallel For information on resistors connected in series and parallel please see the Resistance page, Power Ratings of Resistors Electrical energy is converted to heat when current flows through a resistor. Usually the effect is negligible, but if the resistance is low (or the voltage across the resistor high) a large current may pass making the resistor become noticeably warm. The resistor must be able to withstand the heating effect and resistors have power ratings to show this. Power ratings of resistors are rarely quoted in parts lists High power resistors (5W top, 25W bottom) Photographs Rapid Electronics could vary by 10% 390 = 39 , so it

because for most circuits the standard power ratings of 0.25W or 0.5W are suitable. For the rare cases where a higher power is required it should be clearly specified in the parts list, these will be circuits using low value resistors (less than about 300 ) or high voltages (more than 15V).

31

The power, P, developed in a resistor is given by: P = I R or P = V / R where: P = power developed in the resistor in watts (W) I = current through the resistor in amps (A) R = resistance of the resistor in ohms ( ) V = voltage across the resistor in volts (V)

Examples:

A 470 A 27

resistor with 10V across it, needs a power rating P = V/R = 10/470 = 0.21W. resistor with 10V across it, needs a power rating P = V/R = 10/27 = 3.7W.

In this case a standard 0.25W resistor would be suitable.

A high power resistor with a rating of 5W would be suitable.

32

CAPACITORS
Function Capacitors store electric charge. They are used with resistors in timing circuit because it takes time for a capacitor to fill with charge. They are used to smooth varying DC supplies by acting as a reservoir of charge. They are also used in filter circuits because capacitors easily pass AC (changing) signals but they block DC (constant) signals.

Capacitance This is a measure of a capacitor's ability to store charge. A large capacitance means that more charge can be stored. Capacitance is measured in farads, symbol F. However 1F is very large, so prefixes are used to show the smaller values. Three prefixes (multipliers) are used, (micro), n (nano) and p (pico):

means 10-6 (millionth), so 1000000F = 1F n means 10-9 (thousand-millionth), so 1000nF = 1F p means 10-12 (million-millionth), so 1000pF = 1nF Capacitor values can be very difficult to find because there are many types of capacitor

with different labelling systems! There are many types of capacitor but they can be split into two groups, polarised and unipolarised Each group has its own circuit symbol.

33

Polarised capacitors (large values, 1F +)

Examples: Electrolytic Capacitors

Circuit symbol:

Electrolytic capacitors are polarised and they must be connected the correct way round, at least one of their leads will be marked + or -. They are not damaged by heat when soldering. There are two designs of electrolytic capacitors; axial where the leads are attached to each end (220F in picture) and radial where both leads are at the same end (10F in picture). Radial capacitors tend to be a little smaller and they stand upright on the circuit board. It is easy to find the value of electrolytic capacitors because they are clearly printed with their capacitance and voltage rating. The voltage rating can be quite low (6V for example) and it should always be checked when selecting an electrolytic capacitor. If the project parts list does not specify a voltage, choose a capacitor with a rating which is greater than the project's power supply voltage. 25V is a sensible minimum for most battery circuits. Tantalum Bead Capacitors Tantalum bead capacitors are polarised and have low voltage ratings like electrolytic capacitors. They are expensive but very small, so they are used where a large capacitance is needed in a small size. Modern tantalum bead capacitors are printed with their capacitance, voltage and polarity in full. However older ones use a colour-code system which has two stripes (for the two digits) and a spot of colour for the number of zeros to give the value in F. The standard colour code is used, but for the spot, grey is used to mean 0.01 and white means 0.1 so that values of less than 10F can be shown. A third colour stripe near the leads shows the voltage (yellow 6.3V, black

34

10V, green 16V, blue 20V, grey 25V, white 30V, pink 35V). The positive (+) lead is to the right when the spot is facing you: 'when the spot is in sight, the positive is to the right'. For example: blue, grey, black spot means 68F For example: blue, grey, white spot means 6.8F For example: blue, grey, grey spot means 0.68F Unpolarised capacitors (small values, up to 1F)

Examples:

Circuit symbol:

Small value capacitors are unpolarised and may be connected either way round. They are not damaged by heat when soldering, except for one unusual type (polystyrene). They have high voltage ratings of at least 50V, usually 250V or so. It can be difficult to find the values of these small capacitors because there are many types of them and several different labelling systems! Many small value capacitors have their value printed but without a multiplier, so you need to use experience to work out what the multiplier should be! For example 0.1 means 0.1F = 100nF. Sometimes the multiplier is used in place of the decimal point: For example: 4n7 means 4.7nF. Capacitor Number Code A number code is often used on small capacitors where printing is difficult:

the 1st number is the 1st digit, the 2nd number is the 2nd digit, the 3rd number is the number of zeros to give the capacitance in pF. Ignore any letters - they just indicate tolerance and voltage rating.

35

Colour Code Colour Number For example: 102 means 1000pF = 1nF (not 102pF!) For example: 472J means 4700pF = 4.7nF (J means 5% tolerance). Capacitor Colour Code Black Brown Red Orange Yellow 0 1 2 3 4 5 6 7 8 9

A colour code was used on polyester capacitors for many years. It is Green Blue now obsolete, but of course there are many still around. The colours should Violet be read like the resistor code, the top three colour bands giving the value in Grey pF. Ignore the 4th band (tolerance) and 5th band (voltage White rating). For example: brown, black, orange means 10000pF = 10nF = 0.01F. Note that there are no gaps between the colour bands, bands actually appear as a wide band. For example: wide red, yellow means 220nF = 0.22F. so 2

identical

Polystyrene Capacitors This type is rarely used now. Their value (in pF) is normally printed without units. Polystyrene capacitors can be damaged by heat when soldering (it melts the polystyrene!) so you should use a heat sink (such as a crocodile clip). Clip the heat sink to the lead between the capacitor and the joint. Real capacitor values (the E3 and E6 series) You may have noticed that capacitors are not available with every possible value, for example 22F and 47F are readily available, but 25F and 50F are not!

36

Why is this? Imagine that you decided to make capacitors every 10F giving 10, 20, 30, 40, 50 and so on. That seems fine, but what happens when you reach 1000? It would be pointless to make 1000, 1010, 1020, 1030 and so on because for these values 10 is a very small difference, too small to be noticeable in most circuits and capacitors cannot be made with that accuracy. To produce a sensible range of capacitor values you need to increase the size of the 'step' as the value increases. The standard capacitor values are based on this idea and they form a series which follows the same pattern for every multiple of ten. The E3 series (3 values for each multiple of ten) 10, 22, 47, ... then it continues 100, 220, 470, 1000, 2200, 4700, 10000 etc. Notice how the step size increases as the value increases (values roughly double each time). The E6 series (6 values for each multiple of ten) 10, 15, 22, 33, 47, 68, ... then it continues 100, 150, 220, 330, 470, 680, 1000 etc. Notice how this is the E3 series with an extra value in the gaps. The E3 series is the one most frequently used for capacitors because many types cannot be made with very accurate values.

37

VARIABLE CAPACITORS Variable capacitors are mostly used in radio tuning circuits and they are sometimes called 'tuning capacitors'. They have very small capacitance values, typically between 100pF and 500pF (100pF = 0.0001F). The type illustrated usually has trimmers built in (for making small adjustments - see below) as well as the main variable capacitor. Variable Capacitor Variable Capacitor Symbol

Many variable capacitors have very short spindles which are not suitable for the standard knobs used for variable resistors and rotary switches. It would be wise to check that a suitable knob is available before ordering a variable capacitor. Variable capacitors are not normally used in timing circuits because their capacitance is too small to be practical and the range of values available is very limited. Instead timing circuits use a fixed capacitor and a variable resistor if it is necessary to vary the time period. Trimmer Capacitor Symbol Trimmer capacitors Trimmer capacitors (trimmers) are miniature variable capacitors. They are designed to be mounted directly onto the circuit board and adjusted only when the circuit is built. A small screwdriver or similar tool is required to adjust Trimmer Capacitor

trimmers. The process of adjusting them requires patience because the presence of your hand and the tool will slightly change the capacitance of the circuit in the region of the trimmer! Trimmer capacitors are only available with very small capacitances, normally less than 100pF. It is impossible to reduce their capacitance to zero, so they are usually specified by their minimum and maximum values, for example 2-10pF. Trimmers are the capacitor equivalent of preset which are miniature variable resistors.

ICS (CHIPS)
38

ICs (chips) are easily damaged by heat when soldering and their short pins cannot be protected with a heat sink. Instead we use an IC holder, strictly called a DIL socket (DIL = Dual In-Line), which can be safely soldered onto the circuit board. The IC is pushed into the holder when all soldering is complete. IC holders are only needed when soldering so they are not used on breadboards. Commercially produced circuit boards often have ICs soldered directly to the board without an IC holder, usually this is done by a machine which is able to work very quickly. Please don't attempt to do this yourself because you are likely to destroy the IC and it will be difficult to remove without damage by de-soldering. Removing an IC from its holder If you need to remove an IC it can be gently prised out of the holder with a small flatblade screwdriver. Carefully lever up each end by inserting the screwdriver blade between the IC and its holder and gently twisting the screwdriver. Take care to start lifting at both ends before you attempt to remove the IC, otherwise you will bend and possibly break the pins.

CONNECTORS

39

Connectors: Battery clips | Terminal blocks | Croc clips | 4mm & 2mm | DC power Audio & communication: Jack | Phono | Coax | BNC | DIN | D | IDC & RJ45

Battery clips and holders The standard battery clip fits a 9V PP3 battery and many battery holders such as the 6 AA cell holder shown. Battery holders are also available with wires attached, with pins for PCB mounting, or as a complete box with lid, switch and wires. Many small electronic projects use a 9V PP3 battery but if you wish to use the project for long periods a better choice is a battery holder with 6 AA cells. This has the same voltage but a much longer battery life and it will work out cheaper in the long run. Larger battery clips fit 9V PP9 batteries but these are rarely used now. Terminal blocks and PCB terminals PCB terminal block Terminal blocks are usually supplied in 12-way lengths but they can be cut into smaller blocks with a sharp knife, large wire cutters or a junior hacksaw. They are sometimes called 'chocolate blocks' because of the way they can be easily cut to size. PCB mounting terminal blocks provide an easy way of making semi-permanent connections to PCBs. Many are designed to interlock to provide more connections. Crocodile clips The 'standard' crocodile clip has no cover and a screw contact. However, miniature insulated crocodile clips are more suitable for many purposes including test leads. They have a solder contact and lugs which fold down to
40

Terminal block

Crocodile clips

grip the cable's insulation, increasing the strength of the joint. Remember to feed the cable through the plastic cover before soldering! Add and remove the cover by fully opening the clip, a piece of wood can be used to hold the jaws open. 4mm plugs, sockets and terminals These are the standard single pole connectors used on meters and other electronic equipment. They are capable of passing high currents (typically 10A) and most designs are very robust. Shrouded plugs and sockets are available for use with high voltages where there is a risk of electric shock. A wide variety of colours is available from most suppliers. Plugs Plugs may have a screw or solder terminal to hold the cable. Check if you need to thread the cable through the cover before connecting it. Some plugs, such as those illustrated, are 'stackable' which means that they include a socket to accept another plug, allowing several plugs to be connected to the same point - a very useful feature for test leads. 4mm terminal and solder tag

41

Sockets These are usually described as 'panel mounting' because they are designed to be fitted to a case. Most sockets have a solder contact but the picture shows other options. Fit the socket in the case before attaching the wire otherwise you will be unable to add the mounting nut. Terminals In addition to a socket these have provision for attaching a wire by threading it through a hole (or wrapping it around the post) and tightening the top nut by hand. They usually have a threaded stud to fit a solder tag inside the case. 2mm plugs and sockets These are smaller versions of the 4mm plugs and sockets described above, but terminals are not readily available. The plugs illustrated are stackable. Despite their small size these connectors can pass large currents and some are rated at 10A. DC power plugs and sockets These 2-pole plugs and sockets ensure that the polarity of a DC supply cannot be accidentally reversed. The standard sizes are 2.1 and 2.5mm plug diameter. Standard plugs have a 10mm shaft, 'long' plugs have a 14mm shaft. Sockets are available for PCB or chassis mounting and most include a switch on the outer contact which is normally used to disconnect an internal battery when a plug is inserted. Miniature versions with a 1.3mm diameter plug are used where small size is essential, such as for personal cassette players.

42

Jack plugs and sockets " (6.3mm) jack plug and socket These are intended for audio signals so mono and stereo versions are available. The sizes are determined by the plug diameter: " (6.3mm), 3.5mm and 2.5mm. The 2.5mm size is only available for mono. Screened plugs have metal bodies 3.5mm jack plug and socket

connected to the COM contact. Most connections are soldered, remember to thread cables through plug covers before soldering! Sockets are designed for PCB or chassis mounting. " plug connections are similar to those for 3.5mm plugs shown below. " socket connections are COM, R and L in that order from the mounting nut, ignore R for mono use. Most " sockets have switches on all contacts which open as the plug is inserted so they can be used to isolate internal speakers for example. The connections for 3.5mm plugs and sockets are shown below. Plugs have a lug which should be folded down to grip the cable's insulation and increase the strength of the joint. 3.5mm mono sockets have a switch contact which can be used to switch off an internal speaker as the plug is inserted. Ignore this contact if you do not require the switching action. 3.5mm jack line socket (for fitting to a cable)

L = left channel signal R = right channel signal COM = common (0V, screen) 3.5mm jack plug and socket connections (the R connection is not present on mono plugs)

43

Do not use jack plugs for power supply connections because the contacts may be briefly shorted as the plug is inserted. Use DC power connectors for this.

Phono plugs and sockets These are used for screened cables carrying audio and video signals. Stereo connections are made using a pair of phono plugs and sockets. The centre contact is for the signal and the outer contact for the screen (0V, common). Screened plugs have metal bodies connected to the outer contact to give the signal additional protection from electrical noise. Sockets are available for PCB or chassis mounting, singly for mono, or in pairs for stereo. Line sockets are available for making extension leads.

Construction of a screened cable

Coax plugs and sockets

These are similar to the phono plugs and sockets described above but they are designed for use with screened cables carrying much higher frequency signals, such as TV aerial leads. They provide better screening because at high frequencies this is essential to reduce electrical noise.

BNC plugs and sockets These are designed for screened cables carrying high frequency signals where an undistorted and noise free twist action, to disconnect you need to twist and pull. Plugs and sockets are rated by their impedance (50 or 75 ) which must be the same as the BNC plug signal is essential, for example oscilloscope leads. BNC plugs are connected with a push and

cable's impedance. If the connector and cable impedances are not matched the signal will be
44

distorted because it will be partly reflected at the connection, this is the electrical equivalent of the weak reflection which occurs when light passes through a glass window. DIN plugs and sockets These are intended for audio signals but they can be used for other low-current purposes where a multi-way connector is required. They are available from 3 way to 8 way. 5 way is used for stereo audio connections. The contacts are numbered on the connector, but they are not in numerical order! For audio use the 'common' (0V) wire is connected to contact 2. 5 way plugs and sockets are available in two versions: 180 and 270 (the angle refers to the arc formed by the contacts).

DIN plug

5 way 180 DIN socket (chassis mounting)

Plastic covers of DIN plugs (and line sockets) are removed by depressing the retaining lug with a small screwdriver. You may also need small pliers to extract the body from the cover but do not pull on the pins themselves to avoid damage. Remember to thread the cable through the cover before starting to solder the connections! Soldering DIN plugs is easier if you clamp the insert with the pins. Wires should be pushed into the hollow pins - first 'tin' the wires (coat them with a thin layer of solder) then melt a little solder into the hollow pin and insert the wire while keeping the solder molten. Take care to avoid melting the plastic base, stop and allow the pin to cool if necessary. Mini-DIN connectors are used for computer equipment such as keyboards and mice but they are not a good choice for general use unless small size is essential.

D connectors These are multi-pole connectors with provision for screw fittings to make semi-permanent connections, for example on computer

45

equipment. The D shape prevents incorrect connection. Standard D-connectors have 2 rows of contacts (top picture); 9, 15 and 25-way versions are the most popular. High Density Dconnectors have 3 rows of contacts (bottom picture); a 15-way version is used to connect computer monitors for example. Note that covers (middle picture) are usually sold separately because both plugs and sockets can be fitted to cables by fitting a cover to a chassis mounted connector. PCB mounting versions of plugs and sockets are also available. The contacts are usually numbered on the body of the connector, although you may need a magnifying glass to see the very small markings. Soldering D-connectors requires a steady hand due to the closeness of the contacts, it is easy to accidently unsolder a contact you have just completed while attempting to solder the next one!

IDC communication connectors These multi-pole insulation displacement connectors are used for computer and

telecommunications equipment. They automatically cut through the insulation on wires when installed and special tools are required to fit them. They are available as 4, 6 and 8-way versions. The 8-way RJ45 is the standard connector for modern computer networks. If you regularly use these you may be interested in our network lead tester project. Standard UK telephone connectors are similar in style but a slightly different shape. They are called BT (British Telecom) connectors. TOOLS REQUIRED FOR ELECTRONICS Soldering iron For electronics work the best type is one powered by mains electricity (230V in the
46

UK), it should have a heatproof cable for safety. The iron's power rating should be 15 to 25W and it should be fitted with a small bit of 2 to 3mm diameter. Photograph Rapid Electronics Other types of soldering iron Low voltage soldering irons are available, but their extra safety is undermined if you have a mains lead to their power supply! Temperature controlled irons are excellent for frequent use, but not worth the extra expense if you are a beginner. Gas-powered irons are designed for use where no mains supply is available and are not suitable for everyday use. Pistol shaped solder guns are far too powerful and cumbersome for normal electronics use.

Soldering iron stand You must have a safe place to put the iron when you are not holding it. The stand should include a sponge which can be dampened for cleaning the tip of the iron. Photograph Rapid Electronics

Desoldering pump (solder sucker) A tool for removing solder when desoldering a joint to correct a mistake or replace a component. Photograph Rapid Electronics

Solder remover wick (copper braid) This is an alternative to the desoldering pump shown above.
47

Photograph Rapid Electronics

Solder Wire The best size for electronics is 22swg (swg = standard wire gauge). Photograph Rapid Electronics

Side cutters For trimming component leads close to the circuit board. Photograph Rapid Electronics

Wire strippers Most designs include a cutter as well, but they are not suitable for trimming component leads. Small pliers Usually called 'snipe nose' pliers, these are for bending component leads etc. If you put a strong rubber band across the handles the pliers make a convenient holder for parts such as switches while you solder the contacts. Small flat-blade screwdriver For scraping away excess flux and dirt between tracks, as well as driving screws!

48

The following tool is only required if you are using stripboard: Track cutter A 3mm drill bit can be used instead, in fact the tool is usually just a 3mm drill bit with a proper handle fitted.

Small electric drill Ideally this should be mounted in a drill stand. You will need a range of small drill bits, but for most holes a 1mm bit is suitable. Larger holes can be drilled with a hand drill but 1mm bits are too fragile to use reliably in a hand drill.

49

HOW TO SOLDER
First a few safety precautions Never touch the element or tip of the soldering iron.

They are very hot (about 400C) and will give you a nasty burn.

Take great care to avoid touching the mains flex with the tip of the iron.

The iron should have a heatproof flex for extra protection. An ordinary plastic flex will melt immediately if touched by a hot iron and there is a serious risk of burns and electric shock.

Always return the soldering iron to its stand when not in use.

Never put it down on your workbench, even for a moment!

Work in a well-ventilated area.

The smoke formed as you melt solder is mostly from the flux and quite irritating. Avoid breathing it by keeping you head to the side of, not above, your work.

Wash your hands after using solder.

Solder contains lead which is a poisonous metal.

If you are unlucky (or careless!) enough to burn yourself please read the First Aid section.

50

PREPARING THE SOLDERING IRON

Place the soldering iron in its stand and plug in. The iron will take a few minutes to reach its operating temperature of about 400C. Dampen the sponge in the stand. The best way to do this is to lift it out the stand and hold it under a cold tap for a moment, then squeeze to remove excess water. It should be damp, not dripping wet.

Wait a few minutes for the soldering iron to warm up. You can check if it is ready by trying to melt a little solder on the tip. Wipe the tip of the iron on the damp sponge. This will clean the tip. Melt a little solder on the tip of the iron. This is called 'tinning' and it will help the heat to flow from the iron's tip to the joint. It only needs to be done when you plug in the iron, and occasionally while soldering if you need to wipe the tip clean on the sponge.

You are now ready to start soldering Hold the soldering iron like a pen, near the base of the handle. Imagine you are going to write your name! Remember to never touch the hot element or tip. Touch the soldering iron onto the joint to be made.

Make sure it touches both the component lead and the track. Hold the tip there for a few seconds and...

Feed a little solder onto the joint.

It should flow smoothly onto the lead and track to form a volcano shape as shown in the diagram. Apply the solder to the joint, not the iron.

Remove the solder, then the iron, while keeping the joint still.

51

Allow the joint a few seconds to cool before you move the circuit board. It should look shiny and have a 'volcano' shape. If not, you will need to reheat it and feed in a little more solder. This time ensure that both the lead and track are heated fully before applying solder. If you are unlucky (or careless!) enough to burn

Inspect the joint closely.

yourself please read the First Aid section. Using a heat sink Some components, such as transistors, can be damaged by heat when soldering so if you are not an expert it is wise to Crocodile clip Photograph Rapid Electronics

use a heat sink clipped to the lead between the joint and the component body. You can buy a special tool, but a standard crocodile clip works just as well and is cheaper. Further information For a much more detailed guide to soldering, including troubleshooting, please see the Basic Soldering Guide on the Everyday Practical Electronics Magazine website. Soldering Advice for Components It is very tempting to start soldering components onto the circuit board straight away, but please take time to identify all the parts first. You are much less likely to make a mistake if you do this!
1.

Stick all the components onto a sheet of paper using sticky tape. Identify each component and write its name or value beside it. Add the code (R1, R2, C1 etc.) if necessary. Many projects from books and magazines label the components with codes (R1, R2, C1, D1 etc.) and you should use the project's parts list to find these codes if they are given.

2.

3.

52

4.

Resistor values can be found using the resistor colour code which is explained on our Resistors page. You can print out and make your own Resistor Colour Code Calculator to help you.

5.

Capacitor values can be difficult to find because there are many types with different labelling systems! The various systems are explained on our Capacitors page.

Some components require special care when soldering. Many must be placed the correct way round and a few are easily damaged by the heat from soldering. Appropriate warnings are given in the table below, together with other advice which may be useful when soldering. For more detail on specific components please see the Components page or click on the component name in the table. For most projects it is best to put the components onto the board in the order given below: Components 1 IC Holders (DIL sockets) 2 Resistors 3 Small value capacitors (usually less than 1F) Pictures Reminders and Warnings Connect the correct way round by making sure the notch is at the correct end. Do NOT put the ICs (chips) in yet. No special precautions are needed with resistors. These may be connected either way round. Take care with they polystyrene are easily capacitors 4 Electrolytic capacitors (1F and greater) 5 Diodes because

damaged by heat. Connect the correct way round. They will be marked with a + or - near one lead. Connect the correct way round. Take care with germanium diodes (e.g. OA91) because they are easily damaged by heat. Connect the correct way round. The diagram may be labelled a or + for

6 LEDs

53

anode and k or - for cathode; yes, it really is k, not c, for cathode! The cathode is the short lead and there may be a slight flat on the body of round 7 Transistors LEDs. Connect the correct way round. Transistors have 3 'legs' (leads) so extra care is needed to ensure the connections are correct. 8 Wire Links between points on the circuit board. single core wire Easily damaged by heat. Use single core wire, this is one solid wire which is plastic-coated. If there is no danger of touching other parts you can use tinned copper wire, this has no plastic coating and looks just like 9 Battery clips, buzzers and other parts with their own wires 10 Wires to parts off the circuit board, including switches, relays, variable resistors and loudspeakers. 11 ICs (chips) stranded wire You should use stranded wire which is flexible and plastic-coated. Do not use single core wire because this will break when it is repeatedly flexed. Connect the correct way round. Many ICs are static sensitive. Leave ICs in their antistatic packaging until you need them, then earth your hands by touching a metal water pipe or window frame before touching the ICs. Carefully insert ICs in their holders: make sure all the pins are lined up with solder but it is stiffer. Connect the correct way round.

54

the socket then push down firmly with your thumb. What is solder? Solder is an alloy (mixture) of tin and lead, typically 60% tin and 40% lead. It melts at a temperature of about 200C. Coating a surface with solder is called 'tinning' because of the tin content of solder. Lead is poisonous and you should always wash your hands after using solder. Reels of solder

Solder for electronics use contains tiny cores of flux, like the wires inside a mains flex. The flux is corrosive, like an acid, and it cleans the metal surfaces as the solder melts. This is why you must melt the solder actually on the joint, not on the iron tip. Without flux most joints would fail because metals quickly oxidise and the solder itself will not flow properly onto a dirty, oxidised, metal surface. The best size of solder for electronics is 22swg (swg = standard wire gauge).

Desoldering At some stage you will probably need to desolder a joint to remove or re-position a wire or component. There are two ways to remove the solder: 1. With a desoldering pump (solder sucker)

Set the pump by pushing the springloaded plunger down until it locks.

Using a desoldering pump (solder sucker)

Apply both the pump nozzle and the tip of your soldering iron to the joint. Wait a second or two for the solder to melt. Then press the button on the pump to release the plunger and suck the molten solder into the tool. Repeat if necessary to remove as much solder as possible.

55

The pump will need emptying occasionally by unscrewing the nozzle.

2. With solder remover wick (copper braid)

Solder remover wick

Apply both the end of the wick and the tip of your soldering iron to the joint.

As the solder melts most of it will flow onto the wick, away from the joint. Remove the wick first, then the soldering iron. Cut off and discard the end of the wick coated with solder. After removing most of the solder from the joint(s) you may be able to remove the wire

or component lead straight away (allow a few seconds for it to cool). If the joint will not come apart easily apply your soldering iron to melt the remaining traces of solder at the same time as pulling the joint apart, taking care to avoid burning yourself. First Aid for Burns Most burns from soldering are likely to be minor and treatment is simple:

Immediately cool the affected area under gently running cold water Keep the burn in the cold water for at least 5 minutes (15 minutes is recommended). If ice is readily available this can be helpful too, but do not delay the initial cooling with cold water.

Do not apply any creams or ointments. The burn will heal better without them. A dry dressing, such as a clean handkerchief, may be applied if you wish to protect the area from dirt.

Seek medical attention if the burn covers an area bigger than your hand.

To reduce the risk of burns:


Always return your soldering iron to its stand immediately after use. Allow joints and components a minute or so to cool down before you touch them. Never touch the element or tip of a soldering iron unless you are certain it is cold.

SOFTWARE REQUIREMENT

56

Mplab software Pic programmer


SYSTEM DESCRIPTION

It is microcontroller based application by using microcontroller we can develop application like autonomous robots, electronic projects and other embedded system applications. We are making pick n drop robot. We controlling this robot with remote. We can use this for picking object from one place and move it to another place and place it on other place. it is one of the embedded application.

SOFTWARE DESCRIPTION

57

Mplab Software mplab software is compiler(for convert high level language into machine level language) for pic family microcontroller. In this we can write the program in assembly as well as in c language. we used this software for generating machine file of assembly program Pic Programmer Pic programmer is used for writing the machine file into microcontroller room.

58

MAIN PROGAM IN ASSEMBLY LANGUAGE


;********************************************************************** list p=16f877A ; list directive to define processor #include <p16f877A.inc> ; processor specific variable definitions ; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _LVP_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS w_temp EQU 0x30 ; variable used for context saving status_temp EQU 0x31 ; variable used for context saving irerror EQU 0x32 ; variable used for possible errors while receiving irtimer EQU 0x33 ; variable to save the bitlenght time ircounter EQU 0x34 ; variable used as a counter for the bits IRCMD EQU 0x35 ; variable wich hold the received command IRADR EQU 0x36 ; variable wich hold the received address irtemp EQU 0x37 ; variable used for calc ircommand to utputs delay1 EQU 0x38 delay2 EQU 0x39 LED EQU IR EQU BANK3 EQU 020h CBLOCK BANK3 DEL1 DEL2 COUNT COUNT2 hold ENDC #DEFINE status STATUS ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG movwf movf movwf 0x004 ; interrupt vector location w_temp ; save off current W register contents STATUS,w ; move status register into W register status_temp ; save off contents of STATUS register 0x01 0x00 ; variable to assign LED output ; variable to assign IR input

; isr code can go here or be located as a call subroutine elsewhere BTFSC PIR1,TMR1IF

59

GOTO INTRE BTFSC PIR1,CCP1IF GOTO FROMCCP GOTO EXIT INTRE MOVLW 0XB1 MOVWF TMR1H MOVLW 0XDF MOVWF TMR1L BCF PIR1,TMR1IF bsf PORTC,7 GOTO EXIT FROMCCP BCF PIR1,CCP1IF BCF PORTC,7 GOTO EXIT

EXIT

movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt

init ;///////////////////////////////// BSF INTCON, PEIE BANKSEL PIE1 CLRF TRISC BSF PIE1,TMR1IE BSF PIE1,CCP1IE BANKSEL T1CON CLRF T1CON MOVLW 0XB1 MOVWF TMR1H MOVLW 0XDF MOVWF TMR1L BCF PIR1,TMR1IF MOVLW 0X09 MOVWF CCP1CON MOVLW 0XB5 MOVWF CCPR1H MOVLW 0XC7 MOVWF CCPR1L BSF PORTC,7

60

;/////////////////////////////// CLRF PORTA clrf hold ;Initialize PORTA by setting CLRF PORTB CLRF PORTD BSF PORTA,LED ; ; ; ; ; ; bsf hold,0 bsf PORTA,0; testing MOVLW 0X07 MOVWF CMCON BCF STATUS, RP1 BSF STATUS, RP0 BANKSEL TRISA CLRF TRISD MOVLW B'00000110' MOVWF ADCON1 ;Select Bank1 MOVLW b'11111101' ; MOVWF clrf TRISC MOVLW MOVWF CLRF TRISB BCF return TRISA b'00000000' TRISB STATUS, RP0

;output data latches

;Turn comparators off and ;enable pins for I/O ;functions

;Value used to initialize ;data direction ;Set RA<1> as output ;Value used to initialize ;data direction ;Set Rb<7:0> as outputs ;Select bank 0 ;return from subroutine

read_sony BSF irerror,0 ;Set the errorbit (will be cleared later when receiving a good code) BCF INTCON,GIE ;Disable interupts temporary CLRWDT ;Clear the watchdog timer BSF STATUS,RP0 ;Select bank1 MOVLW b'10000101' ;Sets the prescaler and timer 1:64 MOVWF OPTION_REG BCF STATUS,RP0 ;Select bank0 BANKSEL PORTA BTFSC PORTA,0 ;If it was just a short parasite on the ir line skip reading code with error. GOTO end_sony CLRF TMR0 ;Clear timer to measure startbit lenght sony_st1 BTFSS PORTA,IR ;Measure the startbit, WAIT UNTIL FIRST UP DETECTED GOTO sony_st1 MOVF TMR0,0 ;move value of bitlength to irtimer MOVWF irtimer MOVLW d'32' ;If startbit lenght less then 2ms then end reading code with error. SUBWF irtimer,0 BTFSS STATUS,C GOTO end_sony MOVLW d'213' ;If startbit was longer then 2,6ms then end reading ;code with error. ADDWF irtimer,0 ;Because when not valid startbit ir code is not sony protocol BTFSC STATUS,C ;So startbit must be between 2ms and 2,6ms. GOTO end_sony MOVLW d'7' ;Set ir counter to receive 7 commandbits.

61

MOVWF ircounter rd_sony_cmd CLRF TMR0 900s sony_prt1_c BTFSC PORTA,IR GOTO sony_prt1_c MOVF TMR0,0 MOVWF irtimer MOVLW d'5' SUBWF irtimer,0 BTFSS STATUS,C GOTO end_sony MOVLW d'241' ADDWF irtimer,0 BTFSC STATUS,C GOTO end_sony CLRF TMR0 CLRWDT sony_prt2_c BTFSS PORTA,IR GOTO sony_prt2_c

;Measure the first part of the bitlength: If it ;is not between 300 and ;Then exit inmediatly the routine with an error

;Clear the watchdog ;Measure part2 of the command bits and test ;if the length is between 300 and 1600s ;If between these ranges test if second ; bitpart is shorter or longer than 900s

MOVF TMR0,0 MOVWF irtimer MOVLW d'5' SUBWF irtimer,0 BTFSS STATUS,C GOTO end_sony MOVLW d'230' ADDWF irtimer,0 BTFSC STATUS,C GOTO end_sony MOVLW d'241' ADDWF irtimer,0 BTFSC STATUS,C GOTO sony_its_1 sony_its_0 BCF STATUS,C ;if shorter than 900 s the received bit is a zero RRF IRCMD,1 GOTO nxt_sony_cmd sony_its_1 BSF STATUS,C RRF IRCMD,1 nxt_sony_cmd DECFSZ ircounter,1 ;test if all command bits are processed if not receive ;next GOTO rd_sony_cmd ;if longer than 900s the received bit is a one BCF STATUS,C RRF IRCMD,1;Rotate ircmd one position to become correct ;command MOVLW d'5' ;set ircounter to receive 5 address bits MOVWF ircounter rd_sony_adr CLRF TMR0 sony_prt1_a BTFSC PORTA,IR ;measure firtst bitlenght if shorter than 300 ;s or longer than 900s GOTO sony_prt1_a ;then exit inmediatly with error MOVF TMR0,0

62

MOVWF irtimer MOVLW d'5' SUBWF irtimer,0 BTFSS STATUS,C GOTO end_sony MOVLW d'241' ADDWF irtimer,0 BTFSC STATUS,C GOTO end_sony CLRF TMR0 CLRWDT ;clear watchdog timer sony_prt2_a BTFSS PORTA,IR GOTO sony_prt2_a ;measure second bitlenght if shorter than 300s or longer than 1600s MOVF TMR0,0 ;then exit with error MOVWF irtimer ;If between these ranges test if the bit is a one or zero (shorter or longer than 900s) MOVLW d'5' SUBWF irtimer,0 BTFSS STATUS,C GOTO end_sony MOVLW d'230' ADDWF irtimer,0 BTFSC STATUS,C GOTO end_sony MOVLW d'241' ADDWF irtimer,0 BTFSC STATUS,C GOTO sony_its_1_a sony_its_0_a BCF STATUS,C ;if second bitpart was shorter than 900s it's a 0 RRF IRADR,1 GOTO nxt_sony_adr sony_its_1_a BSF STATUS,C ;if second bitpart was longer than 900s it's a 1 RRF IRADR,1 nxt_sony_adr DECFSZ ircounter,1 ;Test if all bits are processed if not receive next GOTO rd_sony_adr BCF STATUS,C ;Rotate tree time the iradr to become the correct ;address RRF IRADR,1 BCF STATUS,C RRF IRADR,1 BCF STATUS,C RRF IRADR,1 CLRF irerror ;Because every bitlength was measured between ;correct limits no errors occured bcf PORTA,LED end_sony BCF INTCON,T0IF ;Clear timer0 interrupt flag to avoid an interrupt BSF STATUS,RP0 MOVLW b'00000101' MOVWF OPTION_REG BCF STATUS,RP0 BTFSS hold,0 return BSF T1CON,TMR1ON ; INTERRUPT ENABLED FOR SERVO SOFT PWM BSF INTCON,GIE ;; RETURN

63

ir_to_outp

movf

movf

not_button0

IRCMD,W ;Save ircmd in irtemp to prevent loosing the ;received code movwf irtemp sublw d'90' ;Check if ir command is higher or ;equal then 10 if so exit and do nothing btfss STATUS,C goto end_output irtemp,W ;Check if ir command is 9 (bn 0) if so clear all outputs sublw d'9' btfss status,Z goto not_button0 clrf PORTB CLRF PORTD ; STOP goto end_output movf irtemp,W ;Check if ir command is 0 (bn1) if so toggle bit 0 btfss status,Z goto not_button1 MOVLW B'00001010' ; forward MOVWF PORTD movlw b'00000010' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 1 (bn2) if so toggle bit 1 sublw d'1' btfss status,Z goto not_button2 movlw b'00000101' ;reverse movwf PORTD movlw b'00000001' xorwf PORTB,1 goto end_output irtemp,W ;Check if ir command is 2 (bn3) if so toggle bit 2 sublw d'2' btfss status,Z goto not_button3 MOVLW B'00001001' ; LEFT MOVWF PORTD call delayrout1 ; call delayrout1 CLRF PORTD ; ; movlw b'00000100' xorwf PORTB,1 goto end_output irtemp,W ;Check if ir command is 3 (bn4) if so toggle bit 3 sublw d'3' btfss status,Z goto not_button4 MOVLW B'00000110' ; RIGHT MOVWF PORTD call delayrout1 ; call delayrout1 CLRF PORTD

not_button1

not_button2

movf

not_button3

movf

64

not_button4

not_button5

not_button6

not_button7

movlw b'00001000' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 4 (button5) if so toggle bit 4 sublw d'4' btfss status,Z goto not_button5 MOVLW B'10000000' ; UP MOVWF PORTD call delayrout1 call delayrout1 ; call delayrout1 ; call delayrout1 CLRF PORTD movlw b'00010000' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 5 (button6) if so toggle bit 5 sublw d'5' btfss status,Z goto not_button6 MOVLW B'01000000' ; DOWN MOVWF PORTD call delayrout1 call delayrout1 ; call delayrout1 ; call delayrout1 clrf PORTD movlw b'00100000' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 6 (button7) if so toggle bit 6 sublw d'6' btfss status,Z goto not_button7 movlw b'01000000' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 7 (button8) if so toggle bit 7 sublw d'7' btfss status,Z goto not_inch movlw b'10000000' xorwf PORTB,1 goto end_output movf irtemp,W ;Check if ir command is 7 (button8) if so toggle bit 7 sublw 0x3B btfss status,Z goto not_prog_pbutton MOVLW B'00000110' MOVWF PORTD CALL UTURN CLRF PORTD goto end_output

not_inch

65

not_prog_pbutton movf toggle bit 7 sublw btfss goto hold,0 goto not_prog_nbutton movf toggle bit 7 sublw 0x11 btfss status,Z goto end_output CALL UNHOLD BCF hold,0 goto end_output end_output delayrout1 looping2 looping1 return movlw d'255' movwf delay2 movlw d'255' movwf delay1 nop nop decfsz delay1,1 goto looping1 decfsz delay2,1 goto looping2 return irtemp,W ;Check if ir command is 7 (button8) if so 0x10 status,Z not_prog_nbutton end_output irtemp,W ;Check if ir command is 7 (button8) if so

bsf

MS1_DELAY MOVLW .44 MOVWF DEL1 MOVLW .5 MOVWF DEL2 DECFSZ DEL2, F GOTO $-1 DECFSZ DEL1, F GOTO $-5 MOVLW .50 MOVWF DEL2 DECFSZ DEL2, F GOTO $-1 RETURN main call test init

66

call

read_sony ; BTFSC hold,0 BSF INTCON,GIE btfsc irerror,0 goto test ;BTFSC hold,0

; CALL HOLD ;

; CALL HOLD call call ir_to_outp delayrout1

;//////////////////////////////////////////////////////////////// btfsc hold,0 ; CALL HOLD

HOLD BSF INTCON,GIE BSF INTCON, PEIE BANKSEL PIE1 CLRF TRISC BSF PIE1,TMR1IE BSF PIE1,CCP1IE BANKSEL T1CON CLRF T1CON MOVLW 0XB1 MOVWF TMR1H MOVLW 0XDF MOVWF TMR1L BCF PIR1,TMR1IF MOVLW 0X09 MOVWF CCP1CON MOVLW 0XB5 MOVWF CCPR1H MOVLW 0XC7 MOVWF CCPR1L BSF PORTC,7 BSF PIR1,TMR1ON RETURN

UNHOLD MOVLW 0X80 MOVWF PORTC CALL MS1_DELAY CALL MS1_DELAY CALL MS1_DELAY CLRF PORTC

67

UTURN MOVLW .24 MOVWF COUNT CALL MS1_DELAY DECFSZ COUNT,F GOTO $-2 ; DECFSZ COUNT2,F ;GOTO UNHOLD RETURN INCH_OPEN MOVLW 0X80 MOVWF PORTC CALL MS1_DELAY CALL MS1_DELAY CALL MS1_DELAY CLRF PORTC MOVLW .10 MOVWF COUNT CALL MS1_DELAY DECFSZ COUNT,F GOTO $-2 ; DECFSZ COUNT2,F ; GOTO UNHOLD RETURN ; remaining code goes here

END

; directive 'end of program'

68

CIRCUIT DIAGRAM

69

PHOTOGRAPH OF PROJECT

70

FUTURE SCOPE This is useful project .we can enlarge this project for industrial uses. This project is like a jcb machine where we need a human power but this Project is controlled by remote so one man can controlled more than one machine without any physical exercise.

71

Das könnte Ihnen auch gefallen