Parallel Port

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Parallel Port as PDF for free.

More details

  • Words: 10,855
  • Pages: 113
Bibin John Signature Not Verified

Digitally signed by Bibin John DN: cn=Bibin John, c=IN Date: 2006.04.14 23:41:17 Z Reason: I am the author of this document Location: Ernakulam

MY EXPERIENCE IN PARALLEL PORT INTERFACING by BIBIN JOHN

Signatur e Not Verified

Bibin John

Digitally signed by Bibin John DN: cn=Bibin John, c=IN Date: 2006.04.15 00:03:49 Z Reason: I am the author of this document Location: Ernakulam

NOTICE I am writing this for the Indian newbies in robotics and for the beginners working in parallel port. This book is the continuation of my first book ' MY EXPERIENCE IN AUTONOMOUS ROBOTICS '. I thought of writing parallel port in a more elaborate way. I specially thank Anish Adhikari and Sanjo for taking the photos of my circuits. I had wasted 3 months to do parallel port interfacing, which can be studied in a day. I don't want this to happen to other newbies. If you study this book thoroughly then i can assure you that you can do parallel port interfacing within 2 days. I thank my teachers of MNNIT and my colleagues Anil K.M, O.Praveen Kumar Reddy, M. Satish,Vigith Maurice, J Rajashekhar Reddy, Mahesh Paliath,Athul Sona and many other members of Robotics Club, MNNIT Allahabad. So i feel this book can guide you through troubleshooting electronic circuits in robotics. I thank my teachers of THSS Muttom, Thodupuzha from where i learned the very basics of electronics.If you find any problems put a post in yahoo groupbooksbybibin or in roboticsindia. I am providing this book free of cost. You can use this book as a study material. I don't want my book to be used as a material for business without my permission. You are not allowed to upload this book in any other sites. BIBIN JOHN e-mail:[email protected] website:www.geocities.com/njbibin Indian forums for robotics and electronics: Www.roboticsindia.net Www.migindia.com http://www.hamradioindia.org Www.machinegrid.com www.edaboard.com Yahoo group: parallelport interfacing magazine:Robotics For You (RFY) , Electronics For You (EFY)

INDEX Which is the parallel port of my computer???????....................................... 6 Introduction.........................................................................................................7 Data Port..............................................................................................................8 control Register..................................................................................................10 Status Port...........................................................................................................11 Bios Settings........................................................................................................12 Connector ...........................................................................................................15 DB-25 to Centronics...........................................................................................18 My experience with parallel port cable.......................................................... 20 Softwares used in Windows............................................................................ 21 Installing Userport.............................................................................................21 Using LPT.exe.....................................................................................................22 Turbo C commands............................................................................................23 Gcc Commands...................................................................................................24 Java.......................................................................................................................24 Important points to be noted for interface.....................................................25 Troubleshooting Parallel ports.........................................................................27 Let's start..............................................................................................................29 Multimeter..........................................................................................................35 First Program......................................................................................................40 Reading DataPort...............................................................................................41 Writing contorl Port...........................................................................................42 Reading Control Port.........................................................................................42 Reading Status Port............................................................................................42 Troubleshooting .................................................................................................43 Driving Relay......................................................................................................44 Driving a motor..................................................................................................47 H bridge...............................................................................................................48 L293D driving motor.........................................................................................50 Stepper motor driving ......................................................................................52 Unipolar Stepper circuit ...................................................................................56 Why ULN is not used as H-bridge????????....................................................56

7segment display................................................................................................57 LCD display.........................................................................................................61 Analog to Digital Converter..............................................................................66 Temperature Measurement...............................................................................68 LDR sensitivity measurement...........................................................................71 8-channel ADC using analog mux....................................................................73 Measuring Mains Supply...................................................................................75 Computer as CRO...............................................................................................76 Antenna Tracking...............................................................................................76 Reading a comparator .......................................................................................77 Speed measurement of a DC motor.................................................................78 Keypad interfacing.............................................................................................79 Keypad connection with parallel port.............................................................81 Keypad circuit.....................................................................................................82 Key Encoder Intefacing(74922) ........................................................................83 RAM interfacing(7489).......................................................................................86 parallel port expansion......................................................................................88 24 pin output port...............................................................................................88 24 pin input port .................................................................................................89 12 pin inputs and 12 pin outputs......................................................................90 Expanding parallel port for more inputs and outputs..................................93 ROBO DAC..........................................................................................................95 Applications of Robo DAC................................................................................99 Sun Tracker..........................................................................................................99 Line Follower robot...........................................................................................101 Robotic Arm.......................................................................................................102 DITTO..................................................................................................................104 IC Tester..............................................................................................................106 LAN Controlled parallel port..........................................................................113 Game Boy Camera Interface ...........................................................................113 Optical Mouse as Scanner................................................................................113

Which is the parallel port of my computer??????? This will be the first question you are going to ask. See the diagram below,parallel port of my computer.

Parallel Port is same as the printer port in the back side of computer.Parallel Port interfacing is the simplest method of interfacing. Now parallel port interfacing is used for programming microcontrollers and hobby circuit. Here I am going to explain how to interface it in Windows(all versions),Linux in C and Java.

6

INTRODUCTION Parallel Port interfacing is thesimplest method of interfacing. So it is widely used. The main problem with parallel port interfacing is that it has data transfer speed upto 1Mbytes/sec. USB interfacing are available having speed near to 12MBytes/sec. Parallel port is basically the 25 pin Female connector(DB-25) in the back side of the computer(Printer Port). It has 17 input lines for input port and 12 pins for output port. Out of the 25 pins most pins are Ground and there is data register(8 bit), control register(4 bit) and status register(5 bit). We can input port through all the three registers and can output port only through data and control registers only. Each of these register have their own addresses. By using that addresses we can program the port. Parallel Port’s are standardized under the IEEE 1284 standard first released in 1994. This standard defines 5 modes of operation, which are as follows, 1. Compatibility Mode. 2. Nibble Mode. 3. Byte Mode. 4. EPP Mode (Enhanced Parallel Port). 5. ECP Mode (Enhanced Capabilities Mode). Here I am explaining bi-directional mode and simple parallel port. EPP and ECP modes use handshaking signals.

7

DATA PORT

BASE ADDRESS- 0X378 or 0x278 (0x378 mostly used) TOTEM POLE OUTPUT The Data Out pins were orginally driven by a 74LS374 octal latch, which could source 2.6 mA and sink 24 mA. There were 0.0022uF capacitors between each line and ground to reduce transients. The manual warns "It is essential that the external device not try to pull these lines to ground", as this might cause the 74LS374 to source more current than it could handle without damage. The Feedback input port for the Data Out register consisted of a 74LS244 *tri-state buffer*; it is uninverted. Note that this port is only for diagnostics - if at any time the feedback *buffer* for the data port does not match the data being output, there is an error (eg: a line stuck high or low). Exception: bidirectional printer ports allow the 74LS374 (or equivalent) driver chip to be tri*-*stated, which makes the data feedback port into a legitimate unlatched input port.

8

Writing Data Port:giving data to the outside circuit For normal port C5=0(i.e, the fifth bit of control port must be low) outportb (0x378,0x45); D7=0 D6=1 D5=0 D4=0 D3=0 D2=1 D1=0 D0=1 reaches the port.It should be noted that dataport is a latch so the last data send is stored on the port(since it is a latch). Reading Data Port: Taking data from outside circuit In order to make data port for inputting the control pin C5=1 outportb(0x37a,0x20); a=inportb(0x378); When u execute this program the variable 'a' is stored the value the decimal value of the data inputted to the port. Suppose if you input the all the pins to VCC then we get value a=255 drive load 24mA @ 4.2V (From IBM definition of port) Note: High Impedance state is considered as HIGH by parallel port. If you read the data port without connecting any input, we get all high(a=255)(same as that of LS TTL gates). Suppose if you connect input to D0 and no inputs to the others pins(D1-D7), then only the value at D0 change, the value at (D1-D7) will remain as same as the previous value.

9

CONTROL REGISTER

OPEN COLLECTOR OUTPUTS The Control Out pins were driven by 7405 inverting open collector buffers, pulled to +5 volts via 4.7K resistors. All data lines except C2 are inverted before going to output pins; data line C2 is double inverted before going to pin 16 (ie: is not inverted). Remember that it is better to use 74LS gates at the output because open collector inputs are read as LOGIC HIGH by the 74LS series IC's. Open collector means LOGIC HIGH become high impedance and LOGIC LOW become LOGIC LOW(<.8V)

10

writing Control Port: outportb(0x37a,0x00); then you get at the ouput C0=1,C1=1,C2=0, C3=1 because the C0,C1,C3 are inverted pins. Reading Control Port: We can read Control Port using the command a=inportb(0x37a); No other settings are required. Don't forget to connect buffer at the output of the control port since the voltage level of the port is not exactly 5V. Remember to use 74LS buffer. NOTE: In documentation it has been told that control port has high impedance instead of HIGH, but practically i am getting some difference. When i send HIGH to the port and giving the output to an LED, the LED will glow. STATUS PORT

Status port is used for reading purpose only. It is an input only port. A=inportb(0x379); will read the status port. But remember that some pins are inverted.

11

BIOS SETTINGS Till now we have talk about the registers of parallel port. Now let's start to do something. Bios Setting is the most important point to note while doing interfacing. If you don't set BIOS parallel port option data won't reach the port correctly. Here are the settings i used for my motherboard Motherboard used:INTEL845GVSR In different motherboard there are differnt BIOS configuration. When system start press 'Delete' key or Ctrl+F2 to enter BIOS and go to peripheral configuration then do the following settings Parallel Port [enabled] Mode [bidirectional] Address [0x378] In other motherboards do the following steps. First find where parallel port option, then enable it, then set your address as above, you can use 0x278 but normally not used. Then select bidirectional mode if available, otherwise select any mode which do not contain ECP and EPP. Don't put these modes because they have different protocols. Better you select all the modes except ECP , EPP and ECP+EPP and try. Note: ● ●



Set parallel port mode to any mode except ECP,EPP,ECP+EPP, mostly set to SPP In some branded PC's of IBM etc.. you won't be able to acess BIOS properly.So in that case you won't be able to use dataport for input. Use only status port for input. You should see the bios setting before you start parallel port interfacing. This is the most important step.

12

CONNECTOR Different connectors are shown below.

But accordint to my experience I first used 1284B shown in below diagram with blue tip is shown, but that does not worked properly before one year, but nowadays we are getting such connectors and it works fine .I used the same 1284B connector with white tip(tip means only color). See the my connector 2 years old, still working perfectly. I have heard of 25 pin male on one side and 25 pin female on other side connector, but i haven't worked on it. The connector is a normal printer cable which have 25 male pins on one side and 36 female pins on the other side(circuit side). Better use a 25 – 36 pin connector which is available commonly, costs around Rs.40 or less(cost of my connector 2 years back). Buying Connector: See whether it have 25 male pins on one side and 36 female pins on other side. It is normally called centronics connector available in every computer shop. Some people say it as a printer connector while some others as data cable, so you see the connector before you bring from the shop whether it is a DB25 connector.

15

Now let's see the different type of wires available. The following figure shows diffferent wires. The black wires are very good to get inserted into the female pins of the connctor. They will be held tight and they won't suffer any problems with loose contact. But these black wires will enlarge the holes of the breadboard as well as the cable. But you should use this wire to avoid the problem of soldering. If you can solder the cable then it good. But soldering can cause some short circuits because you had to solder atleast some 18 wires. If some short circuit occurs, sometimes you won't be able to detect and it will eat your time , sometimes it can cause damage to the port also. If you are good in soldering,then no problem. The green wires are medium type wires which can be inserted to the holes of the connector and the breadboard. But the contact won't be good. The black and white wires are the wires we use in breadboard connection. See the thickness of the wires. If you use this wire to connect to the cable to breadboard, then it will always get loose and create too much problem to you.

16

So better use the black wire. I think you got a confusion now. How 25 pins on one side become 36 pin on other side???????. I got same, so I opened both sides of the connector to see the inside connection. Then I drawed the inside connections with the same color of the wires used inside for my cable. See the diagram below. Now you should have got the problem solved. See data pins(8)+control pins(4)+status pins(5)+ground(1)=18pins will be used by us. We will leave the remaining pins unconnected.

17

18

19

MY EXPERIENCE WITH PARALLEL PORT CABLE: If you are not getting data properly from port your connector may or may not be bad. This problem occured to me when I am using a normal connector ,IEEE1284 Type B connector. It is better to use a connector all the time when you are taking output from port. I have seen many person using simple wire to the port and taking output. That is a wrong practice. The connector I brought first can be opened on both sides. I opened it and identified the colours of the wires connected to the pins as show in figure above. That is not working properly and not getting ouput properly. So I brought new one which cannot be opened on both sides. The property of the holes in the second connector is that if we insert a wire it is just fixed on the hole, so a small force applied on the wire won't take the wire out. It is MALE to FEMALE connector and having a White colour instead of Blue colour in IEEE1284B connector. It is IEEE1284B connector itself. The following shows the Centronics pins on the other side of the cable(36 pin side) 1-co' 2-do 3-d1 4-d2 5-d3 6-d4 7-d5 8-d6 9-d7 10-s6 11-s7' 12-s5 13-s4 14-c1' 36-c3' 32-s3 31-c2 19-gnd connect port ground to circuit ground. Then connect the data pins in the order in bread board at one place.

20

SOFTWARES USED IN WINDOWS All operating systems of Windows upto Window ME(included) requires no driver software for parallel port. You can interface it by a simple program in Turbo C. But operating systems after Windows ME have a security to parallel port. So we have to break it inorder to interface with outside circuits. This is done by using USERPORT. Installing USERPORT: You can get userport.zip with this file or from yahoo group-parallelport.

http://www.embeddedtronics.com:80/public/Electronics/minidaq/userport/UserPort.zip

Download this file and unzip it then copy Userport.sys to WINDOWS\SYSTEM32\DRIVERS then run USERPORT.EXE u will get a message driver started. Click Start two times then you will get the following message. This is the next step after BIOS Settings.

Now u do programming in C/C++/JAVA and interface in XP or other version of Windows. USERPORT is necessary software you should install. If you are using VB or VC then you can get DLL's from www.logix4u.net

21

USING LPT.EXE: This is a small VB program which shows the status of the parallel port registers You can get it with this book or yahoo group-parallelport or from the link http://neil.fraser.name/software/lpt/ After BIOS settings and userport installation next step is to check whether your parallel port will work or not and which ports will work well. Run lpt.exe

select your port address first as you set on the BIOS. The following diagram shows how to check port. You 'tick' indicates high on that port. So change tick on the port. Make it low and high. If it is changing for data register and control register then your parallel port is working fine and will work fine. But if the 'tick' is not changing then you won't be able to use it. You won't be able to use the ports in which 'ticks' are not changing. In the above diagram we can see that Pin1 (strobe C0) is not having tick(i.e is low), but if you connect an LED then it will glow because C0' is there and the port get's HIGH. Suppose if you input LOW on pin1 then the Strobe will get HIGH in the software. So remember this when you do troubleshooting circuits with lpt.

22

TURBO C commands #include<dos.h> this header file is used for doing IO operations. Delay(time_ms); This function delays time in milliseconds. That is execution will be stopped for time_ms time. Outportb(port,data); This command will send data(data) to the port address (port) in the command a=inportb(port); This command will read a port. The data(a) will be in decimal format. Printf(“%x”,a); This command will print the hexadecimal value of 'a' on the screen

23

GCC commands #include<sys/io.h> #include these header files should be used in the program. ioperm(base,3,1); This function is used to provide acess to port. You should be in root of the system ioperm(base,3,0); this function leave the acess to parallel port. usleep(time_us); delay in microseconds. outb(value, address); inb(address); This function is used to get value from a given address. There is only small change in format compared to Turbo C commands. See the following link: http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html http://www.epanorama.net/circuits/parallel_output.html

Java: You can get the sourcecode from yahoo group-parallelport. The file named 'interfacing in Java'(.rar file).

24

Important points to be noted for interface: 1.You have to make the port bidirectional before applying the external voltage to the data port because it can cause problem to your port (C5=1) 2.Don't remove the covering of the cable. If you are using Centronics pin as Female pin then take wire out of the pins shown above. Don't try to remove covering to take the wires out, because it can create problem of short-circuiting or you can solder the wires to a PCB. 3.proper delays must be used in inporting/outporting sequencially delay functions are defined in delay(value); will halt the program execution for 'value' milliseconds, or you can apply looping by keeping it in a loop to produce delay. The need of delay is that Parallel Port has a speed of only 1MB/s, but your program execution speed is comparable to processor speed, so you should apply some delay between two port acess commands. But sometimes there is no need ( I got positive result by doing without delay better to put it). Usually we use parallel port speed about 1KB/sec(delay(1);) 4.don't try to draw power from parallel port. This cause damage to port. So it is necessary to use external power supply. 5.use only 74LS series IC's to interface between port and the other IC's because the Parallel Port is LS TTL ouputs and inputs. This is valid for inputting or outputting also. 6.switch on the circuit first then only connect the connector to the port 7.first disconnect the port then only switch off the circuit 8.don't forget to connect the ground of the port from the connector to the ground of the circuit. 9.Connect the ouput of the port to the input of the buffer and use the output of the buffer as the output of the port.

25

Note: When you are inputting the port connect the wire to the input of a buffer and take the output of the buffer to the port. NOTE: use only 74LS buffer or 74LS IC's to the port directly. If you want to connect 40xx,45xx series IC's in the circuit it is better not to connect to the IC directly to the port. It is better to use buffer in between port and IC. 10. Don't connect motors or relays directly to parallel port. You are allowed to connect only normal digital IC's and transistor where driving current it low. Connect motors and relays using power transistors. 11.The data transfer speed of parallel port is 1MB/sec. 12. High Impedance state is considered as HIGH by parallel port That means if u doesn't connect any input and u apply inportting through port we get all high(a=255)(same as that of LS TTL gates). 13.If you use 74HC244 then it takes the high impedance state as LOGIC LOW but 74LS244 takes it as LOGIC HIGH. 14.BIOS settings is the main thing to note. Set BIOS to bidirectional port, if not available set it to any configuration except ECP,EPP,ECP+EPP 15.The external power supply must have the driving capability to drive the external circuit. You can use the SMPS of the computer you are working on. 16.Remember that all ports are registers, so they all keep the last data sent to the port 17. Don't extend the parallel port cable for long distance. If you want to use it for long distance use some buffer(74244) in after the length of the cable. Every cable has some resistance, capacitance and other factors and the voltage through printer cable is 5V, so if a HIGH is send from printer port, then it should reach HIGH for the circuit and this is possible only when you use the cable within limited length. If you see a serial port cable, you will get more length than parallel port cable because the HIGH for a serial port cable is -3V to -25V and LOW for 3 to 25V, so a good voltage swing is there and you can get good distance.

26

TROUBLESHOOTING PARALLEL PORTS: This is the most important section which normally unavailable in internet. Here I am saying about my own experiences. 1.) First of all your system has not attacked by any WORM or any other type of virus like shutdown virus(remember that this problem only comes after when a shutdown virus given you shutdown message and you run shutdown -a ). This problem occured with me recently. Then your parallel port won't work. 2.) You must install UserPort.zip for working in Windows operating systems above Windows ME 3.) For outporting: check the BIOS settings 4.) check the connector or connector configuration connected be wrong( connector can be bad but rare condition) 5.) compiler (Turbo C <dos.h>) VB then apply suitable dll's (get from www.logix4u.net) if you are using any software or program see it's format to apply (If you are using any software driver for port)

6.) Check proper tightness of the connector to the port. Insert the connector properly to the port. 7.) Test the buffer you are using whether it is bad or good and it is of 74LS family. If you are using 74HC which takes the high impedance state as logic LOW where 74LS take as HIGH. 8.)Power Supply should be correct and check whether the LED's are good or not.

27

9.) You can connect LED directly to port by taking one data pin as the positive terminal and ground as -ve terminal. The wire should be properly inserted to the breadboard and the Centronics cable . 10.) The ground of the port and the circuit should be short circuited. 11.) Don't try to connect without any buffer although no serious problem(you can connect but the voltage level be low) 12.) See any motor or relay connected to the port without power transistor or any buffer. 13.) See whether the pin number of Centronics is correct. See whether that the bit is inverted or non-inverted. 14.) proper delays must be used in outporting sequencially. 15.) For inputting the port: It is better to apply input the port using a buffer ( the advantage is that if overvoltage occurs the buffer will get damaged first, port is secured) 16.) While inporting data port then make sure that C5=1 In inputting status port there is no problem occur mostly. 17.)If your data port reading of Turbo C gives a reading 170(in decimal) and the input you had given is a different one, but lpt.exe is reading the input correctly, then reboot the system. This the problem occuring with Turbo C in hardware interfacing.

28

LET'S START Before starting let me explain the components i am going to use. First about my power supply. I am using the adapter of 12V,500mA with voltage ranging from 1.5V-12V. I have explained it on my first book MY EXPERIENCE ON AUTONOMOUS ROBOTICS.I want to show you how i am doing things so that you will be able to do all the projects given in this book very fastly and follow the right way.

SMPS is prefered over adapter. The knob of my adapter is shown below.

29

30

Now come to Breadboard. This is the breadboard of my college.

31

This is an LED connected in series with a 100 ohm resistor. This white led gives red light.

32

See this figure carefully. See how i connected the individual ports. See I have used different wires. A thick black wire from cable to breadboard. I used a green wire also. The wires in the breadboard are small size as I shown it previously.

33

35

Here is the multimeter which i am using. It costs around Rs300. I have talked about this multimeter in my previous book MY EXPERIENCE IN AUTONOMOUS ROBOTICS. Now we can start. First install userport.zip and do bios settings.

Now let's check the voltage from different ports.

Make the data port all high.

36

In the above diagram you can see that i checked the voltage at the data port. In that I connected LED and multimeter to same point. Let's remove Led and check

37

see the voltage difference. Here i used 100 ohm series with LED.

38

This diagram shows how i check for the control port. The voltage of control port is high compared to data port.

39

First Program Writing to data port #include"bparlib.c" void main() { Write_DataPort(0x99); } Program: 1.c This program sends 0x99 to data port i.e D0=1,D3=1,D4=1,D7=1 and remaining are LOGIC LOW. Now check the status using an LED. Figure below shows the status of D7. Check the status at every pin of data port.

40

Reading Data Port Program: 2.c #include"bparlib.c" void main() { printf("%x",Read_DataPort()); } Here I used %x to print the hexadecimal value instead of decimal value. Now let's connect some input to data port and check. In the figure below I am connecting LOW to D0. Now run this program. You can see the output is 0x98. Only the value at D0 has changed, the remaining values from D1-D7 remains unchanged.

41

Writing to Control Port Program: 3.c #include"bparlib.c" void main() { Write_ControlPort(0x00); } This program will send 0x00 to control port. i.e c0,c1,c3 led has glown because they are inverted pins and C2=0. Reading Control Port program:4.c #include"bparlib.c" void main() { printf("%x",Read_ControlPort()); } i connected c2=high, remember that previous values will be stored in the port. The output of pgm4 is 4. ie. C2=1 and remaining all others are LOW. Reading Status Port program:5.c #include"bparlib.c" void main() { printf("%x",Read_StatusPort()); } first execute this program without connecting any inputs. I got the value 0x78. Now connected Pin4 to HIGH then it read 0x78 again because the Pin4 is already high in this program.

42

NOTE: 1. Use lpt.exe to see the status of every ports everytime when you execute the program. 2. You can use this as an ideal status detector. 3. Try all different combinations by sending different values to port as well as inputting different values. 4. Remember that when you input the voltage should not be greater than 5V. Make sure this first, then only you do this. You can use the output of other port as input to some other port. Do thorough with reading and writing different ports first then only go for the next programs. 5. Take some time to do this because this is the basic step and you should be thorough with that for the other programs. TROUBLESHOOTING 1. The cable may not be good some time. This occurred to me in the beginning. So You had to see this problem first. Now let's see how to do it 2. Use multimeter continuity tester to test continuity between the wires of the breadboard and the copper strip of the cable. Try to vary values, ie. Apply both LOW and HIGH to see whether the wire is properly inserted into the cable and the continuity is good. This is the main step. 3. See for any problems with breadboard. 4. Careful about ground. You have to short circuit external ground and ground of parallel port. 5. See whether there is any short circuit between the pins of the cable or wires. Solve this first. This may occur if you go for soldering. 6. There might be some loose contact between cable and wire. Fix it properly. In order to avoid this use wires of good thickness. 7. Always check the voltage of external power supply. It should not be greater than 5V. Otherwise sometimes, some problems can occur to the parallel port. 8. See whether your parallel port is working using lpt.exe by changing the 'ticks' If 'ticks' are not changing then you won't be able to use that port. 43

Driving a Relay:

for tutorials see my previous book MY EXPERIENCE IN AUTONOMOUS ROBOTICS. Here I am going to use a 6V relay which is more comfortable in terms of supply. The other end of the relay can be connected to even a home equipment work on 230V. Specifications: 6V,100 ohm ,1.5A , 230V relay. Figure below show the connections.

44

45

By default LED is ON, if you send High to D0 then relay will become active and LED will turn OFF. Program: relay.c You can use this circuit to control your home equipments using computer. Here if you use 12 relays using both control and data port of parallel port, you can control 12 equipments working upto 230V(including). Here I used LED to explain it clearly. See troubleshooting tips on my previous book MY EXPERIENCE IN AUTONOMOUS ROBOTICS. DO IT: Try to make a timed control of your home equipment. Suppose you want to turn ON your equipments after Ton time and work it for Toff time and turn OFF. i.e, the equipment work for Toff time. Suppose if you set Ton=1hr and Toff=1/2 hour. Then the equipment will become ON after 1hr. From now and work for ½ hours and turn OFF after this ½ hour. Also try to make your home voice controlled using VB or Java. See the link below: http://www.roboticsindia.com/modules.php?name=News&file=article&sid=115

46

Driving a motor Use the same circuit to drive motor. You connect collector to one end of motor and other end of motor to the Vcc(12V or 6V according to your motor). Program: motor.c

47

H-BRIDGE

See the circuit diagram above you will get it. For forward motion transistors (1,3) should be ON and remaining (2,4) OFF. For Backward motion transistors (2,0) should be ON and (1,3) should be OFF. For stopping(0,0) condition of H-bridge, Transistors(1,3) should be ON and (0,3) should be OFF. For braking(1,1) transistors (1,2) should be ON and (0,3) should be OFF. So make a programm according to this to turn motor forward,backward,brake. Program: HBRIDGMO.c see not to short circuit Vcc and power supply by making (2,3) ON, first condition and (0,1) ON another condition when Vcc is connected to ground and short circuit occurs. But if you use power transistor then the heat sink will get heated too much. adapter o/p 6.42v,voltage across motor 2.35v.

48

49

L293D driving motor program: L293d.c D0,D1 outputs are used as inputs of L293D.

50

See how to troubleshoot L293D in my previous book MY EXPERIENCE IN AutONOMOUS RobOTICS. See the program. DO IT: try to control a robot forward,backward and stop using L293D. Try to make it voice controlled. See this link to make a parallel port controlled bot http://www.roboticsindia.com/modules.php?name=News&file=article&sid=65 http://www.roboticsindia.com/modules.php?name=News&file=article&sid=115

51

STEPPER MOTOR DRIVING

Figure shows a general stepper motor. This is a 6 wire stepper motor which can be used both as unipolar and bipolar stepper motor. Figure below shows the stepper motor i used costs around Rs.270. The first task is to identify terminals (a,b,c,d,e,f). They are identified and as show below hold it like a 2X3 row 1,1 is common 1,2 is one end of coil 1, 1,3 other end of coil1 2,1 is common of coil2 and so on. The resistance of one coil is 108 ohm and between (a,c) is 54 ohm( I checked it). Programs for driving stepper motor as bipoloar: bipolar.c unipolar: unipolar.c use separate power supply for logic and control circuit http://www.seattlerobotics.org/encoder/may98/steppers.html http://micromouse.cannock.ac.uk/motors/stepper_driving.htm These links gives the circuit diagram.

52

UNIPOLAR STEPPER CIRCUIT Above diagram shows how i connected the stepper circuit. This diagram above has one wire missing. The circuit is given below

a,b,c,d corresponds to (D0,D1,D2,D3). See the program unipolar.c Why ULN is not used as an H-bridge???? You can see that ULN is coming as a single IC package and it is of cheap cost compared to power transistors used for H-bridge. Still no one is using ULN as Hbridge for driving motor, although it is convenient in circuit making and cost.

Suppose V1=0 then both transistors are cut off and no current will flow. When V1=HIGH then both transistors are ON and the 'output' will become LOW(0v)(i.e, emitter will get gnd). So at V1=0 it has 'output'=Z and V1=1 has 'output'=LOW. A power transistor has two states, there is short circuit between E and Collector or there is no connection. But in ULN the collector will get either high impedance or a LOW voltage(gnd). So it can't be used for H-bridge. Here when the input is HIGH the transistor emitter will get ground instead of a short circuit between E and C.

56

DISPLAYS 7-segment display

The above circuit shows how to connect multiple displays with a single decoder. You can do it without a decoder and some transistors. But here I am using 74126 a tri-state buffer and a 7segment decoder. Corresponding pins of displays are short ciruited together. i.e, 'a' of all displays are short circuited, same as b'. Program:led.c Algoritham Clear_ControlPort_bit(0); Clear_ControlPort_bit(1); Clear_ControlPort_bit(2); Clear_ControlPort_bit(3); This is used to remove the Vcc to all displays so that nothing can be seen on display.

57

Here we use the technique of persistance of vision. i.e, our eye cannot detect what is happening within 1/16 of a second. Delay(7); This command gives a delay of 7ms and the digits to be displayed on LED are given to the data port and the corresponding control bit is taken. Suppose if the input number is 1234 So 4 should be displayed on the last 7 segment. So we first get digit 4 from the input and send it to the data port and Set C3 to HIGH. Thus we get 4 on last display and it last for 7ms, while in the mean time the power supply for other displays are OFF and nothing will be displayed on them. After 7ms we make C3=LOW to OFF the display and we send '3' to the data port and enable the C2 = HIGH. So the second last 7 segment will display for 7ms and after that it will become OFF, while all other displays are OFF. This will continue for (j<1000, an arbitary time). When one cycle is over, the same process will repeat. See all these events are happening in milliseconds and for one cycle it will take at max.50ms(let's say by calculating all other time). This time of 50ms is too small for our eye to detect and our eye will perceive as displays are ON all the time. Troubleshooting: 1. Check the connections like 'a' of all are short circuited. 2. Check whether all the segments of the display are working by connecting Vcc of all to Power supply and LT'=GND. In that case all displays should glow. 3. See whether your breadboard has any problems and the connections are interchanged or not 4. The pin3 and pin8 can be used for VCC but only one at a time. 5. Here i have not used resistor, it is better to insert a series resistance of 100 ohm according to the intensity of the display.

58

59

60

LCD DISPLAY Here I am using a 16X2 LCD display available for around Rs.140. The LCD JHD162A

61

More tutorials about LCD is available on the following links http://www.roboticsindia.com/modules.php?name=News&file=print&sid=75 http://www.beyondlogic.org/parlcd/parlcd.htm http://www.eio.com/lcdintro.htm http://home.iae.nl/users/pouweha/lcd/lcd0.shtml#hd44780 http://ee.cleversoul.com/lcd_project.html

See the commands from the first link and see the program. Program: lcd.c

62

first select the instruction register to write these following commands. See the table of commands init[0] = 0x01; init[1] = 0x38; init[2] = 0x0c; init[3] = 0x06; init[4] = 0x80; 0x01 is used to clear display 0x38 for 2 lines and 8 bits 0x0c 0x06 0x80 is the CRA Address Corresponds to the cursor address. This is the main thing you should do first Now select the data register and write the data you want to send. Delays should be proper for the display to set. The following program writes some data into the LCD which will remain stored in the RAM of LCD TROUBLESHOOTING: 1. Make the LCD ON by varying the contrast. You vary the potentiometer knob so that the contrast will vary and you will get dark matrix on the screen. 2. Reduce the contrast so that dark dot's of less intensity will be seen. 3. Now run the program, check for parallel port troubleshooting. 4. The delay inserted in the program should be sufficient. 5. The CRA address should be correct.

63

Here is the output of the program.

64

65

ANALOG TO DIGITAL CONVERTER

program: adc2.c Here I used Vref=Vcc=5V. This voltage may change depending on load. You can use any other Vref using a potentiometer at the Vref/2 pin. See datasheet for the maximum value of Vref. Digital and analog grounds are short circuited. Here the 10K and 150pF determines the speed of conversion. The normal speed is 100uSec. You can change this. If you increase the speed, then it is called overclocking. I used 222pF instead of 150pF. So if you don't get 150 pF then u can use other values but the speed of conversion will vary. Here I am using the free running mode of operation for easiness. Mainly used mode is interrupt mode. In free running mode ADC will never end the conversion. Some power is wasted in this case compared to interrupt mode. First we have to Enable Write pin then disable it after some time. This time will be in milliseconds because the conversion time of ADC is in terms of milliseconds(.1ms). So the conversion time of ADC in our program is 2ms. i.e, you can get 500 conversions in a second. Most of the application this much speed is enough, especially when we used sensors in robotics. You can try for a better speed. Here the voltage is calculated using the formula V=ouput of ADC/(2^8-1)*Vref. Here Vcc=5V and output of ADC is of 8 bit so we divide it by 255. See the least count of ADC = 5/255=1/51=.02V . You can see that if you decrease Vref, then we can get a better accuracy.

66

Program: adc1.c This program is used to check what is the output of the ADC when chip select and read are not enabled. The output will be 0xff not Z(high impedance). In most of the cases you have to see it if you use it with some multiplexed bus. Suppose if you want to expand parallel port and by using control signals we disable ADC but still a voltage of HIGH remains at the output. So be careful about multiplexing ADC with any bus. Use a buffer to the output of the ADC to enable the chip reading when you are using multiplexed bus.

67

TEMPERATURE MEASUREMENT

The most commonly available LM35 is LM35DZ measures temperature from 0 to 100 degree.Output is 10mV* degree in Celsius. That is if the temperature is 29 degree then Vout=.29V. Therefore we require a least count of .01V for measurement of temperature with 1degree difference. So we should select a proper Vref least count=Vref/255 , gives Vref=2.55. So we have to apply 2.55/2(Vref/2) to the pin9. Program:lm35.c

68

69

70

LDR SENSITIVITY MEASUREMENT How to measure the sensitivity of an LDR?????? I thought of using ADC to measure and see the time difference between three consecutive different reading. I can't say this method is ideal, but this method can somehow measure the sensitivity to an extent. By this method i got sensitivity around 3ms, but I have seen that LDR sensitivity is around 10ms. Anyway this circuit can be used to read LDR output in digital format.

Program: ldr.c read the LDR 400 times continously and take the least count in which consecutive 3 readings will differ. You can use this circuit to change the parameters of your computer monitor so that you will feel same effect with variation in external light.

71

72

8-CHANNEL ADC(USING ANALOG MUX)

Figure shows analog mux is used to multiplex 8 analog voltages to the ADC. Here we are using an analog mux MC14051 or CD4051. The selection pins of the analog mux is connected to the output of the control port.INH is disabled. Thus by selecting proper inputs we can get different channel outputs. Analog mux can work as a digital mux while digital mux can't. Program:amux.c

73

74

MEASURING MAINS SUPPLY: You can measure mains supply using the same circuit of ADC. You can measure instantaneous voltage, peak voltage and frequency(maximum 500Hz) of the mains supply. First step is to reduce the analog 230v,50Hz supply within 5V range. You can do this using a transformer which can reduce 230V to 5V. But there is a problem of negative voltage exist. i.e, for -230V you will get -5V from the transformer. So you have to use a comparator to determine whether the voltage is above or below 0V. So you give the output of transformer to the input of comparator and ground the other terminal (V+), so that comparator output will become HIGH when voltage is below ground. Now you have to convert -5V output of transformer to 5V. i.e,you have to avoid -ve voltage and make that voltage to equivalent +ve supply. You can do this using a bridge rectifier(full wave rectifier) or a center tap rectifier(usually available transformers are center tap transformers). But there will be some significant drop across the diode. You had to compensate for it in your program. Mostly available transformers are 230V/15V center tap transformers. So here you have to step down voltage to 5V. You can do this using 3 resistor in series with output and voltage input to ADC is taken across the last resistor whose other pin is ground, so that you will get 5V corresponding to 15V. But this method can create some errors due to drops across diodes and other losses. But this is the simplest method to measure main supply. Compensate losses in your program and make the reading ideal. You can get voltage from 0-255V with 1v as least count. Remember that if most of the 15V transformers have output greater than 15V sometimes(suppose if voltage is greater than 230V). So be careful to see the maximum voltage in your design. The transformers won't be ideal enough to give a maximum of 15V output. So beware of that also. Now you can get instantaneous voltages, from that you can get the maximum voltage(peak voltage) and the comparator output gives the frequency of the sinal.

75

COMPUTER AS CRO: http://www.geocities.com/lptscope/hw.html Here you can use the same logic as you used in above project. But there is a limitation for maximum frequency in this case. Here we have to use some method so that we can measure high frequency. So we have to remove delay(1) and use some C graphics to plot the waveform. Circuit for this was published in Electronics For You. See the above link. Here also we required to plot the negative side, so in this case also we use comparator. Go for some high speed ADC's to get good performance. It is better to use Interrupt mode for this, so that we can get speed upto 10Khz and we can measure and plot the same. You can overclock the ADC to measure high frequencies. See this link where you can get a high speed one using USB http://www.eix.co.uk/Ethernet/USB/ see this link for making CRO using audio port http://www.roboticsindia.com/modules.php?name=News&file=article&sid=112

ANTENNA TRACKING: The aim of antenna tracking is to place antenna in a position to get the maximum signal. So in this case we are holding the antenna vertically in a platform which can be rotated using a simple DC motor. So we have to measure the signal strength(i.e,output voltage) at every point in the rotation of the motor. We connect the signal output to ADC to measure the maxium voltage. Step down the signal voltage, if it is above the maximum ratings of the antenna. So rotate the antenna using the motor. Make a 360 degree rotation and get the maximum peak signal. Store the maxium peak signal and again rotate the antenna such that it is aligned to the direction from which maximum signal strength is received. You can rotate the antenna from 0-180 in one direction and 0-180 in opposite direction or 0-360 in one direction depends on your mechanical structure. This setup can be used to align the antenna to the direction of maximum signal strength when you shift it from one place to another.

76

REDING A COMPARATOR It is often required to read a compartor for sensing black and white using a comparator or some other applications using comparator. Here I am using status port to read the comparator.

Here you can see I am connecting comparator output to the status port pin7. The output of comparator may not be accurately 5V . It is in the range of 3.5V . But all voltages above 2.4V is treated as HIGH by the digital circuits. Here you can use potentiometer output as the reference voltage. Program:lm324.c

77

SPEED MEASUREMENT OF A DC MOTOR: Most of the DC motors have maximum speed about 2400 rpm . Ie, 40 rotation/sec. So we can measure this using a sensor whose sensitivity is greater than 1/40 in a second. Suppose if you use an LDR or a photo diode, then we can measure the speed easily. Attaching some spikes at the shaft or at the wheel of the motor(or make wheel in that type construction), use photo diode or LDR. A photo diode is the best option which can have have distance upto 5-7cm, but LDR is not having that much because of external light. Use IRLED+photo diode combination. Use a series resistance with a photo diode and connect the resistance voltage to the comparator. Count the number of spikes passed. The spikes are placed at equal angles with the center. Meaure the speed using number of spikes moved, diameter of the wheel and the time taken. This is the simple method instead of usingshaft encoders. See the mechanical setup to measure the position of a mouse in a ball mouse(not optical mouse), then you can understand better.

78

KEYPAD INTERFACING This section i will explain about connecting keypad to the parallel port. Let's see the keypad connection. A normal keypad costs around Rs.150. A keypad has a problem of keydebouncing and we have to eliminate it in our program.

79

80

KEYPAD CONNECTION WITH PARALLEL PORT

81

KEYPAD CIRCUIT

See the above circuit diagram and understand the connection. Take Row 0 and column 0. A switch has four leads in which two leads are short circuited internaly to form a swich. Suppose if you press the switch then all the terminals will be short circuited. If we send C0=1 and C2=C1=C3=0 then first row become active and remain rows will be deactive. One row of all switches get HIGH (i.e, switches in row 0 , one terminal will get high). If you won't press a switch in the row then output will be zero(you can see the output terminal of the switch is short circuited to No Connection terminal of the switch. So by default the output is zero at d1,d2,d0,d3.

82

Suppose if you press row 0 and column1 switch then d1 become HIGH and all remaining d0,d2,d3 become LOW. Here we are using a resistance with every output to see the output voltage. When no switch is pressed the output voltage will be zero and when switch is pressed output voltage will become HIGH. In all the cases you can see that bottom 2 switches of all row become HIGH and top one is not connected=LOW and other is output. So when you press the switch all become HIGH if you had selected the row for that switch. Program: keypad.c TROUBLESHOOTING: 1. You should avoid key debouncing problem by inserting proper delays in the program. A normal person can press only 10 switches in a second (at max). So insert a delay of 100ms after pressing a switch to void keydebouncing. 2. See the appropriate keydebouncing algoritham. 3. Soldering should be proper.Better go for a redymade keypad. 4. At the starting of the program make all output ports low. Make sure when you make a particular row HIGH, other rows should be LOW. 5. IF you want to avoid keydebouncing problem and a software making then go for 74922 or 74923. KEY ENCODER INTERFACING(74922) Mostly available keyencoders like 74147,74148 have a problem of key debouncing. So in order to eliminate it we had to use 74922 or 74923 encoders. It costs around Rs.200! And you had to make the keypad. You can use the above keypad for this purpose. Using this we can avoid software burden and the listening of the program for keypad. The encoder has 5 outputs. 4 data and one Data Available. So when a key is pressed Data Avaiable become HIGH and parallel port has to sense this to read the keypad. See the capacitance values properly. I used .01uF as C . The capacitance values should be C and 10C for proper operation otherwise keydebouncing problem won't be eliminated properly.

83

84

Here I have short circuited X2 and Y1 so the output will be 1. Program:922.c The program will wait for a keypress (i.e short circuiting between two pins(x, y)) and print the pressed value.

85

RAM INTERFACING(7489) locations.

7489 is a 64 bit RAM arranged in 16x4 memory

Here you can see that RAM's address bus is of 4 bits(2^4=16) and input data of 4 bits and output data of 4 bits(complemented). 4 bit of address bus is connected to D0-D3 of data port and 4 bits of data input is connected to D4-D7 of data port and output of RAM is connected to S7-S4 and the chip select and W/R select is connected to C0 and C1 respectively. Program:7489.c You should insert proper delays in the program to acess RAM. See the datasheet for the delays. In the program I am writing to a speicific memory location and I am reading it again.

86

87

PARALLEL PORT EXPANSION In some cases you want more outputs or more inputs from the parallel port than how many inputs and outputs we have from the output of the parallel port. So you want to expand parallel port. You can use 8255 to expand the parallel port input and output. You can get either 24 output pins or 24 input pins or 8 input and 16 output pins using 8255. But 8255 is costlier. We can get same solution using D flipflops(or u can do using any latch). 24 PIN OUTPUT PORT

88

Here you can see that output of data port is connected to the input of D flip flop and control port pins as the clock of the D flip flop. The clock for 74374 is produced by making the clock pin HIGH from a LOW state of the clock pin. The output should be enabled. First you write the data you want to write to the flip flop into the data register of the parallel port and the clock the flip flop. Suppose if you want to write to flip flop connected to C0, then Write_DataPort(data to be written to flip flop) Clear_ControlPort_bit(0); delay(1); Set_ControlPort_bit(0);

24 PIN INPUT PORT

89

The buffers become active only when a LOW is applied to the control pin of the buffer. So in the starting of the program we have to make all pins HIGH so that two buffers are not selected at a time. Suppose if you want to select the first flip flop connected to C0. Clear_ControlPort_bit(0); a=Read_DataPort(); Set_ControlPort_bit(0); you should make the pin high before you leave the buffer. This way we can get 24 inputs from the parallel port. 12 PIN INPUTS AND 12 PIN OUTPUTS

90

First you should disable the output of the buffers(74244's) in the beginning of the program. Make the clock to the flip flop by making the corresponding control port pin LOW and then HIGH. Buffers input should be made LOW to read the buffer and the data port should be made for input before reading the buffer program: exp1.c

91

92

EXPANDING PARALLEL PORT FOR MORE INPUTS AND OUTPUTS Here I am using decoder at the output of the control port for more inputs and outputs. If you have a 3x8 decoder then you can make 7x8 outputs or 7x8 inputs or (nx8 inputs and (7-n)x8 outputs). If you use a 4x16 decoder then you can expand it further to produce higher number of inputs and higher number of outputs. A decoder has 8 outputs, but we can use only 7 outputs because if we want to output to a flip flop and flip flop want clock transition from 0 to 1 for a flip flop connected to output 4 of the decoder and output 7 is not connected, then first put the data to the data port of the flip flop and write control port to 4 and after some delay write again to control port (7). So when control port gets 4 then clock=0 and when control port is 7 then clock=1 and we get a transition from 0 to 1 and data latched into the flip flop. Suppose if you want to use 8 flip flops then when we select 4 first then we have to select another value to make clock to 1, suppose if you select 7 then clock of the flip flop connected to 7 gets 0 and we next had to write data to 7 otherwise the flip flop data will get corrupted.

93

ROBO DAC A data acquisition Card is always need to get data in different form, analog or digital . The data can be inputted or outputted or used as a independent counter / timer. But in Robo DAC we are having 8 analog inputs, 8 digital inputs and 8 digital outpus. We can also expand the number of digital outputs and digital inputs.

Here you can see that first flip flop is used for 8 digital outputs and second flip flop for controlling the DAC like ADC signalling, used as select pins for the analog mux. In DAC there is facility for extending 8 analog inputs or 32 digital inputs or 32 digital outputs or 16 digital inputs and outputs. So first we clock the first flip flop to output a digital data. Then we use control flip flop to select different channels of analog mux and signalling ADC conversion. The output of ADC conversion is given to the input of one 74244 buffer which is read by making C3 pin LOW. Program:dac.c remember that in the program you are taking the value as decimal and you will get output of the flipflop as hexadecimal.

96

97

98

APPLICATIONS OF ROBO DAC SUN TRACKER: Sun Tracker is a mechanism which keep Solar Panels always perpendicular to Sun. The maximum radiation is obtained when Solar panel is perpendicular to sunlight, so maximum power. Everyday sun moves from East to West and a lateral shift of 23.5degree on both sides of normal(i.e, change with seasons like summer and winter).See http://www.eaas.co.uk/news/seasons.html. So we need two axis tracking. Sun sets at west and our system shut downs automatically when a particular intensity of light is reached (i.e in night and in rain time). When it set at west and during morning it had to come back to east i.e in morning it had to shift 180 degree.. Sun Tracker should work perfectly with Sunlight and in darkroom in presence of sodium vapor lamp.

99

100

RA0,RA1,RA2,RA3 is the output of the flip flop(74374).

You can connect the output of 74374 to the enable of L293D. When the LDR resistance is too high , the enable of L293D should be disabled because there is no need of moving sun tracker because the availability of light is less. You can decide it in your program. There should be an option for suntracker to align automatically to the direction of maximum sunlight when it is shifted from one position to other. You can provide a suitable algoritham in your program. You can disable the L293D for sometime and thus power consumption is somewhat reduced(see in case of big motors H-bridge consuming good amount of power) . LINE FOLLOWER ROBOT Suppose you want to make a line follower robot with 4 sensors on each side and 16 speed reductions then you can make it using ROBO DAC. If you use varying supply voltage to drive the motor then you can use this circuit. Make a proper algoritham for driving the motor.

101

ROBOTIC ARM A robotic arm requires precise movement of the motor. You can make a robotic arm using steppers,but it won't have enough torque to drive the arm. Normal robotic arms are made using Servo motors which are very costly. We can have a less cost solution using a DC motor and a potentiometer. Potentiometer will give the feedback to the computer. But only 270 degree rotation is possible with a potentiometer. We couple DC motor shaft with the knob of a potentiometer, so that relative motion between DC motor shaft and potentiometer is zero. Then connect the output to ROBO DAC and measure the voltage corresponding to a specific angle. Suppose if you want to move the arm to a specific angle,then we should see the database, corresponding voltage for that angle . Rotate that motor until the potentiometer output reaches the corresponding value.

102

103

DITTO This is a robotic arm which makes equivalent movement with the movement of the other robotic arm. You might have seen in some vidoes of humanoid robots that if our hand moves equivalent movement occurs in the hand of the humanoid robot. In this case we use a robotic arm. Use ROBO DAC to sense the movement.

105

IC TESTER

We all know that different IC's have different input and output pins.The first procedure is to program which pins are for input and output. This programming is done by writing data into control register. That is the name of that register is control register. We can only input 13 data from parallel port at a time. But this is not sufficient. So what I am doing is that I am storing data into data register and read the output from all pins. This will work with all digital IC's work on 5v. I tested it for 74/40/45 series.(don't forget to buy 74LS244 not 74HC244) WORKING: Before reading this you have to see the datasheet of the IC's and how it work(if you don't know about these IC's). First we see the testing of combinationl circuits.So I am taking a simple IC 7404, same logic for all other IC's working without clock.

106

Before programming you have to see the control port pins. You can see that c2,c1',c0' . So see the below table for corresponding IC's.From the table we can see that if you want the output of the decoder to be Q0 then we have to write 3 to control port ,i.e,011 so the output of port will be 000. Always use this table when you are seeing code. decoder software 03 12 21 30 47 56 75 First connect pin1 of IC to the 1 shown in circuit diagram.

Now next aim to set control register. You can see that pin 1,3,5 are for input and 2,4,6 for output and 7 for ground, 8 is not used in diagram. So we want to send voltages to pins 1,3,5,7. First setting control register(2) 1.select control register(2): since Q2 of decoder is connected to clock of the register. So first select the register by decoder. First make clock to 0 by 0x01. Now we get clock low. Then we write to data port. Then select any other pin of decoder which is not connected. I am using the unconnected output of decoder that is Q7(0x04). So control register got the data from data port. I am using this way for all registers.

107

2.Write to data port: so we want the input to be 10101010(pin1-1 and so on) Now we configured pins 1,3,5,7 for input by applying high to the control of tri-state buffer.But you know that D0 is connected to Do7(data port) so we have to read from right to left for corresponding data to be send to data port. outportb(0x37a,0x01); D; outportb(0x378,0x55);//1010,1010 first three is for ic's //next 1 is for ground next one no need so i made it Z D; outportb(0x37a,0x04); D; /* control register(2) is configured*/ Here D is the delay of 1mS Setting for control register(1): outportb(0x37a,0x00); D; outportb(0x378,0x2b);//1101,0100 first Vcc three ic's and a Z D; outportb(0x37a,0x04); D; /* control register(1) is configured*/ use the same step of control register(2) to control register(1) first select control register(1) by selecting that register by writing 0x00 to control port (that is clock is low). Then make the corresponding data control to control register. Then select another decoder output(0x04 as default) /*first sending all to low*/ outportb(0x37a,0x02); D; outportb(0x378,0x00);//all zero since ground is there D; outportb(0x37a,0x04); D; /*data register(2) is entered zeros*/ outportb(0x37a,0x03); D; outportb(0x378,0x01 );//1000,0000 since pin 14 is VCC D;

108

outportb(0x37a,0x04); D; /*data register(1) is enterd zer0*/ inporting should be done by using C5=1,and select the enable of 74LS244 /* data inputting for all zeros*/ outportb(0x37a,0x26); D; a=inportb(0x378); D; printf("pins from 1 t0 8, reading float as zero\n"); printf("a(0)d2=%d\n",a); D; printf("output should be=01010100\n"); D; // data inputted for lower pins1 to 8 outportb(0x37a,0x27); D; a=inportb(0x378); D; printf("pins 16 to 9, reading floating as one\n"); D; printf("a(0)d1=%d\n",a); D; printf("output should be=10101011"); D; //data inputted for higher pins 16 to 9 /*data outputted all high*/ outportb(0x37a,0x02); D; outportb(0x378,0xbf);//1111,1101 D; outportb(0x37a,0x04); D; //data entered data(2) outportb(0x37a,0x03); D;

109

outportb(0x378,0xff); D; outportb(0x37a,0x04); D; //data entered data(1) //started entering all high /* inputting all high*/ outportb(0x37a,0x26); D; a=inportb(0x378); D; printf("all high for and floating zero pin 1 to 8"); D; printf("a(1)d2=%d",a); D; printf("output is a=10101000"); D; //data from data register(2) outportb(0x37a,0x27); D; getch(); a=inportb(0x378); D; printf("all high for pin 16 to 9"); D; printf("a(1)d1=%d",a); printf("output is a=11010101"); D; //data from data register(1) } This way you can test combinational logic IC's For clock driven IC's first clock check reset and set using normal IC's combinational IC's. For applying clock first apply data register pin to 1 then apply the corresponding pin to 0. Thus we get clock for -ve edge level triggering. I think you will sometimes won't be getting this. Just think of it, you can get. See the code below you will get it outcontrol3(0x99); outcontrol2(0xff);

110

//apply reset outdata0(0x55); outdata1(0x7b); a=inp5(); bin(a,b); if(b[1]==0) ic[1]+=1; if(b[5]==0) ic[2]+=1; //apply set outdata0(0xb3); outdata1(0xbd); a=inp5(); bin(a,b); if(b[1]==1) ic[1]+=1; if(b[5]==1) ic[2]+=1; //J=1 , K=0 outdata0(0xa2); outdata1(0xff); //apply clk outdata1(0xde); a=inp5(); bin(a,b); if(b[1]==1) ic[1]+=1; if(b[5]==1) ic[2]+=1; //J=0, K=1 outdata0(0x55); outdata1(0xf7); //apply clk outdata1(0xd6); a=inp5(); bin(a,b); if(b[1]==0) ic[1]+=1; if(b[5]==0) ic[2]+=1; //J=K=0 //applying reset outdata1(0x7b); outdata0(0x44); outdata1(0xf7);

111

//apply clk outdata1(0xd6); a=inp5(); bin(a,b); if(b[1]==0) ic[1]+=1; if(b[5]==0) ic[2]+=1; //applying set outdata1(0xbd); outdata0(0x22); outdata1(0xf7); //apply clk outdata1(0xd6); a=inp5(); bin(a,b); if(b[1]==1) ic[1]+=1; if(b[5]==1) ic[2]+=1; //apply J=K=1 //apply reset outdata1(0x7b); outdata0(0xb3); outdata1(0xff); //apply clk outdata1(0xde); a=inp5(); bin(a,b); if(b[1]==1) ic[1]+=1; if(b[5]==1) ic[2]+=1; //next clk outdata1(0xff); outdata1(0xde); a=inp5(); bin(a,b); if(b[1]==0) ic[1]+=1; if(b[5]==0) ic[2]+=1;

112

LAN CONTROLLED PARALLEL PORT You might have heard of controlling home equipments using Lan or internet. Here we are going to use one for Lan. The folder named lan controlled parallel port has the source code and executable file. This program has been done by Mahesh Paliath. He used VC++ and WinSock library to make the program. GAME BOY CAMERA INTERFACE Here are some links for game boy camera interface http://geocities.com/vjkemp/gbcam.htm http://pages.zoom.co.uk/andyc/camera.htm http://sophiateam.undrgnd.free.fr/microcontroller/camera/index.html you can buy game boy camera using a credit card from www.ebay.com OPTICAL MOUSE AS SCANNER http://prism.mem.drexel.edu/stanciu/Web_page/optical_mouse.htm http://www.engadget.com/2006/01/08/turn-your-optical-mouse-into-a-crappyscanner/ http://slashdot.org/articles/06/01/08/1536200.shtml

113

I am winding up this book hoping this book will help newbies to start with parallel port interfacing. All the source codes given are tested and verified. I haven't verified the following sourcecodes bipolar.c unipolar.c keypad.c The remaining source codes worked well with me and it will work for you. Once you have completed this book then go for microcontroller . My next book will be on AVR microcontroller. BIBIN JOHN

Related Documents

Parallel Port
October 2019 31
Parallel Port
December 2019 30
Parallel Port
November 2019 31
Parallel Port
November 2019 31
Parallel Port Tut
November 2019 28