You are on page 1of 8

Blinking of LED using ‘C’

Sandip Nair
Requirements: -
1. Windows 98 installed PC
2. Turbo C
3. Parallel port male connector
4. Resistors(1kΩ) & LED

Circuit Diagram: -

Fig 1 The arrangement of LED and resistors to the parallel port pins
Theory: -
Pin no D-type Register-bit Direction Inverted
1 Control0 Out Yes
2 Data0 In/out No
3 Data1 In/out No
4 Data2 In/out No
5 Data3 In/out No
6 Data4 In/out No
7 Data5 In/out No
8 Data6 In/out No
9 Data7 In/out No
10 Status6 In No
11 Status7 In Yes
12 Status5 In No
13 Status4 In No
14 Control1 Out Yes
15 Status3 In No
16 Control2 Out No
17 Control3 Out Yes
18-25 Ground - -
Table 1 Pin configuration
Data line : 8 bit data can be given to the computer from the
external circuit or can be transferred from computer to external
Control line : To control the external circuit.
Status line : Signal given to the computer from the external circuit.
In the PC there will be D-25 type of female connector having 25
pins and in the printer; there will be a 36-pin Centronics connector.
Fig 2 Parallel port male connector

Fig 3 Pin configuration

Register LPT1 LPT2
Data register (base 0x378 0x278
address +0)
Status register (base 0x379 0x279
address +1)
Control register (base 0x37a 0x27a
address +2)
Table 2 Port address
Data, status and control lines are connected to the respective registers
inside the CPU. The contents are changed in these lines by changing the
contents in their respective registers. Programming the parallel port is
easier and faster than programming the serial port. Since a large amount
of transmission lines are required therefore parallel ports cannot be used
in long distance communication. Parallel ports are usually used for
device control and communication. The following shows the respective
address of data register, control register and status register.
Note: - All ports do not have bi-directional capability. Earlier parallel
ports had output enabled data pins since printers had only input pins. But
latter, to make parallel port capable of commutating with other devices,
bi-directional pins were introduced.
By default, data port is output port. To enable the bidirectional property
of the port, we need to set the bit 5 of the control register.
In order to check the configuration of the ports, one has to restart the PC
and go to BIOS and see portions related to parts. One will find the port
address as well as its type of the following type: -
• SPP (standard parallel port not bidirectional).
• Bi-directional (standard parallel port with bi-direction facility).
• EPP (enhanced parallel port).
• ECP (extended capabilities parallel port).
The following procedure had been prescribed to know the details of the
parallel port available: -
• Right click on ‘My Computer’ and go to properties.
• Select the tab hardware and select the device manager.
• Double click on ECP printer port (LPT1) or any other LPT port if
• You will get details of LPT port. It is to be checked that the port is
• Select tab resource. In that the address range of the port can be
Input/output can be assessed in turbo c/c++ by using following library
functions: -
• inport(register, data)
• outport(register, data)
Working: -
The main aim of the project is to understand the basic operation of
the parallel/printer port. The male connector is used in which LED and
resistors are connected as given in the figures given below. Here the
CONTROL signals are indicated by red LED and DATA signals are
indicated by green LED. All the components are soldered together. Pin
17 to 25 are ground connections which are soldered together.
After the program is written and compiled in ‘C’, as it runs the
blinking of LED starts one after the other. It starts from the red LED i.e.
from the forth CONTROL bit of the eighth DATA bit after every

Fig 4 Different orientation of the model

Program: -
#define PORTADDRESS 0x378
void main()
int b,c,i;
printf(“blinking of LED stars now”);
outport(CONTROL, 0x03);
outport(CONTROL, 0x0f);
outport(CONTROL, 0x09);
outport(CONTROL, 0x0a);
outport(CONTROL, 0x0b);
outport(DATA, 0x01);
outport(DATA, 0x02);
outport(DATA, 0x04);
outport(DATA, 0x08);
outport(DATA, 0x10);
outport(DATA, 0x20);
outport(DATA, 0x40);
outport(DATA, 0x80);
printf(“Blinking of LED stopped\n”);
Conclusion: -
The project, ‘blinking of LED’ has been done to understand the
concept of interfacing the parallel/printer port of CPU with the external
circuit using ‘C’. It is a simple arrangement where the LED and resistors
are connected to the parallel port connector.