computer interfacing tutorial-printer, serial, game, usb port
 

 

PREVIOUS NEXT

1.5. Parallel Port - Test Circuitry

Refer to the figure titled Figure #4 - Printer Port Test Circuitry. This illustrates a very simple test fixture to allow you to figure out what inversions are taking place in the hardware associated with the printer port. Program test_prt.c sequentially turns each of the 12 LED's on and then off and then continually loops to display the settings on the five input switches.

/* File TEST_PRT.C   
**
** Program to exercise 12 outputs and five inputs.
**
** Program sequentially turns off LEDs on Bits 7, 6, 5, ... 0 on the
** Data Port, and then Bits #, 2, 1 and 0 on the Control Port. Each
** LED is held off for nominally 1 second. Note that an LED is turned
** off with a logic one. This process is executed once.
**
** Program then loops, scanning the highest five bits on the Status Port
** and continuously displays the content in hexadecimal.
**
** P.H. Anderson, Dec 25, '95
*/

#include <stdio.h>
#include <dos.h> /* required for delay function */

#define DATA 0x03bc /* for the PC I used */
#define STATUS DATA+1
#define CONTROL DATA+2

void main(void)
{
int in, n;

outportb(DATA,0x00); /* turn on all LEDs on Data Port */
outportb(CONTROL, 0x00^0x0b); /* same with Control Port */

/* now turn off each LED on Data Port in turn by positioning a logic
one in each bit position and outputing.
*/
for (n=7; n>=0; n++)
{
outportb(DATA, 0x01 << n);
delay(1000);
}
outportb(DATA, 0x00);

/* now turnoff each LED on control port in turn
** note exclusive-or to compensate for hardware inversions
*/

outportb(CONTROL, 0x08^0x0b); /* bit 3 */
delay(1000);
outportb(CONTROL, 0x04^0x0b); /* bit 2 */
delay(1000);
outportb(CONTROL, 0x02^0x0b); /* bit 1 */
delay(1000);
outportb(CONTROL, 0x01^0x0b); /* bit 0 */
delay(1000);

outportb(CONTROL, 0x00);

/* Continuously scan switches and print result in hexadecimal */

while(1)
{
in = (inportb(STATUS)^0x80)&0xf8;
/* Note that BUSY (msbit) is inverted and only the
** five most significant bits on the Status Port are displayed.
*/
printf("%x\n", in);
}
}

PREVIOUS NEXT

 

Free Software
Delphi

Lesson 1
Delphi Programming
1.1. IDE Delphi
1.2. Component


Lesson 2
Printer Port
/ LPT
1.1.Basic
1.2.Address
1.3.Port Register
1.4.8 Bit Data Input
1.5.Test Circuitry
1.6.Assignment

Lesson 3
Printer Port / LPT
Experiments

3.1.LED
3.2.Swicht
3.3.Motor Stepper
3.4.DAC
3.5.ADC
3.6.Graph Display

Lesson 4
Serial Port

4.1.Basic
4.2.Hardware
4.3.Port Register

Lesson 5
Serial Port Experiments

5.1.LED
5.2.Stepper Motor
5.3.Swicht
5.4.ADC

Lesson 6
Game Port
Joy Stick
6.1. Basic
6.2. Experiments