Page Sponsored by 
Back to Victorian University Electronics Intranet Home Page Mirror.
Interfacing switches and leds to computer parallel port.

It is possible to use the same hardware used to interface an AT89C2051 micro-controller to switches and leds to interface them to a computer via the parallel port.

Photo showing switches and leds interfaced to a computer parallel port using a DT004 & DT203.

Switches and leds interfaced using the sample program below. The keyboard character enter is a '1', there the binary as shown by the leds is '10001100' LSB to MSB.

Sample 8088 program to drive leds and read a switch.

;Written by Peter Averill 13-5-1999
;Sample program to output the ascii value of a key pressed at the
;k/b in binary on leds connected to a parallel port.  The program
;will continue in a loop until a switch connected to the ACK line
;on the parallel port is pressed. Tested using a Dontronics DT004
;& DT203 boards (see photo).  The top left push button switch is
;connected to the ACK line.  This is D8 on the Simmbus.  There are
;5 inputs on the status port of the parallel port (base address + 1)
;that can be wired to switches.  In the example I have only connected
;the one switch.
;Because DOS waits for a key to be pressed, to exit the program
;you need to press the switch connected to the ACK line and press
;a key on the keyboard.  The ACK line can also be used to generate
;an interrupt.

port    equ     0278h   ;lptx base address
ack_active equ  03fh

.model  small

.stack  20h



main    proc    far

        push    ds          ;Push DS onto stack
        sub     ax,ax       ;Push zero offset
        push    ax          ;  onto stack
        mov     ax,_data    ;setup
        mov     ds,ax       ;data segment address

top:    call    get_key
        mov     dx,port
        out     dx,al
        inc     dx
        in      al,dx
        cmp     al,ack_active
        jne     top

        ret                 ;Return to DOS

main    endp


get_key proc    near
        mov     ah,01
        int     21h
get_key endp


        end     main

Copying these pages:
Back to Victorian University Electronics Intranet Home Page Mirror.

DonTronics Links:
Home Products Prices Directory Order Contact New Books Files Links FAQ