Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C

 

BACK          HOME         NEXT

 

Interfacing with LED

 

To interface an LED, the cathode should be connected towards the port of the computer and anode towards the positive five volts external supply.

A series resistor, typically 330 ohms, must be present to limit the current passing through the LED.

             or

 

The ground of the external power supply must also be connected to the ground of the parallel port.

With this configuration, the LED will only light if 0V or low logic is present in the output port. This is so because there will be a potential difference between the external supply and computer port.  This will eventually cause an electric current to flow, a current enough to lit up the LED.

 

LED Blinking Program

Consider this problem:

An LED is interfaced to D0 of the parallel printer port. Write a program that will control it to blink five times.

 

Interfacing Circuit Diagram

 

One way to solve this interfaced programming problem is identify first the statement or statements that will control the load. In our case, we will use the outportb function of Turbo C. Then we will solve the number to be send.

 To activate the LED, the following bits should be sent to the data port:

We should send 0 to D0 so that the LED will light. The other data pins are marked X since they can be any bit (0 or 1), they can not affect the LED which is only connected to D0.

But it is still necessary to put specific bits to D7-D1. So we�ll just fill them with all 0�s so that it can easily be converted to hexadecimal number.

The next step is to convert the binary digits into hexadecimal number. We can also convert it to decimal number but binary to hexadecimal conversion is more simple.

Therefore, our Turbo C statement will be

Executing this statement will cause the LED to light.

Next we will solve the statement that will turn off the LED. We can do this by sending bit 1 to D0.

We still send 0�s to D7-D1 so that the whole byte can be easily converted.

Next we will convert the number.

Therefore, our Turbo C statements that will turn off the LED should be:

So we can now write our Turbo C program that will control the LED to blink 5 times.

 

 

#include <dos.h>

void main()

{

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink 1*/

delay(200);

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink 2*/

delay(200);

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink 3*/

delay(200);

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink 4*/

delay(200);

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink 5*/

delay(200);

outportb(0x378, 0x01);

 

Or we can use the loop structure to write the program.

 

#include <dos.h>

void main()

{

int c;

for (c=1; c<=5; c++)

{

outportb(0x378, 0x01);

delay(200);

outportb(0x378, 0x00); /*LED Blink */

delay(200);

}

outportb(0x378, 0x01);

}

 

 

BACK           HOME          NEXT

 

 

    Contents

    Parallel Printer Port  

    Port Functions

    Sending a Byte

    Reading a Byte

    Interfacing LED

    Interfacing Push Button

    Interfacing 7-Segment

    Interfacing Coil

    Interfacing Relay

    Interfacing  S. Motor

    Interfacing AC Load

    Interfacing Sensor

 

 

 

Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C

 

 

 

 

Google

 

 

 

1.  The Parallel Printer Port     2.  Port Functions in Turbo C    3.  Sending a Byte to the Port    4.  Reading a Byte     5.  Interfacing with LED

6.   Interfacing with Push Button     7.  Interfacing with 7-Segment    8.  Interfacing with Coil    9.  Interfacing with Relay    

10.  Interfacing with Stepper Motor    11.  Interfacing with AC Load    12.  Interfacing with Sensor

For questions, corrections and suggestions, 

email to: [email protected]

Hosted by www.Geocities.ws

1