Blinking of LED using ‘C’

By Sandip Nair sandipnair06@yahoo.com sandipnair.hpage.com

Requirements: 1. 2. 3. 4. Windows 98 installed PC Turbo C Parallel port male connector 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 1 Control0 2 Data0 3 Data1 4 Data2 5 Data3 6 Data4 7 Data5 8 Data6 9 Data7 10 Status6 11 Status7 12 Status5 13 Status4 14 Control1 15 Status3 16 Control2 17 Control3 18-25 Ground Table 1 Pin configuration

Direction Out In/out In/out In/out In/out In/out In/out In/out In/out In In In In Out In Out Out -

Inverted Yes No No No No No No No No No Yes No No Yes No No Yes -

Data line : 8 bit data can be given to the computer from the external circuit or can be transferred from computer to external circuit. 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 Data register (base address +0) Status register (base address +1) Control register (base 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 LPT1 0x378 0x379 0x37a LPT2 0x278 0x279 0x27a

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 available. • You will get details of LPT port. It is to be checked that the port is enabled. • Select tab resource. In that the address range of the port can be viewed. 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 second.

Fig 4 Different orientation of the model

Program: #inlude<stdio.h> #inlude<conio.h> #include<dos.h>

#define PORTADDRESS 0x378 #define DATA PORTADDRESS+0 #define STATUS PORTADDRESS+1 #define CONTROL PORTADDRESS+2 void main() { int b,c,i; b=3; clrscr(); printf(“blinking of LED stars now”); for(i=0;i<=b;i++) { outport(CONTROL, 0x03); sleep(1); outport(CONTROL, 0x0f); sleep(1); outport(CONTROL, 0x09); sleep(1); outport(CONTROL, 0x0a); sleep(1); outport(CONTROL, 0x0b); outport(DATA, 0x01); sleep(1); outport(DATA, 0x02); sleep(1); outport(DATA, 0x04); sleep(1); outport(DATA, 0x08); sleep(1); outport(DATA, 0x10); sleep(1); outport(DATA, 0x20); sleep(1); outport(DATA, 0x40); sleep(1);

outport(DATA, 0x80); sleep(1); } printf(“Blinking of LED stopped\n”); getch(); }

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.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.