Using legacy ports.
No-solder-parallel-port-break-out (Great for home control)
We are going to take the parallel port breakout cable and have some fun with the following code (which I may rewrite) and use some extra parts.
Part 1 C code
Code source
Note asm/io.h s/b sys/io.h in parcon.c
Part II Basic code:
Freebasic: (code snippet) (Note: Compiled code on linux must be run under sudo or root unless special rights are given to the program via chmod +s.)
1
2
3
4
5
6
7
8
| rem turn on D0 (pin 2 on the parallel port) out 888,1 rem get status and print to terminal ? inp(888) rem turn off D0 (pin 2 on the parallel port) out 888,0 rem get status ? inp(888) |
Circuit for testing the code. With the cable it will be easier to set up.
Simple LED driving circuits
You can make simple circuit for driving a small led through PC parallel port. The only components needed are one LED and one 470 ohm resistors. You simply connect the diode and resistor in series. The resistors is needed to limit the current taken from parallel port to a value which light up acceptably normal LEDs and is still safe value (not overloading the parallel port chip). In practical case the output current will be few milliamperes for the LED, which will cause a typical LED to somewhat light up visibly, but not get the full brightness.
LED and resistor
For reference purposes:
http://www.epanorama.net/circuits/parallel_output.html
==========================================
Other interesting info:
The joystick port can be also used too to collect data as we did here. We did not have a case to mount the parts so we just used an old particle board to act as a base and we have an altered plastic case for the emi and etc protection.
REM *************************************************************** REM * program: doorchek.bas REM * purpose check value of joystick port connected to door REM * last update 02/04/1994 REM * Copyright (c) 1994 - 2010 Carboman REM * All rights reserved. REM * REM --------------------------------------------------------------- REM mainline REM GOSUB housekeeping WHILE TRUE% GOSUB dothedoor WEND GOSUB endofjob END REM --------------------------------------------------------------- REM housekeeping housekeeping: REM ........................................ REM basic variables and flag settings OLDFLAG = 0 REM screentype% = 1 is 40 columns and 0 is 80 columns. screentype% = 0 startflag = 0 TRUE% = -1 q$ = CHR$(34) KEY OFF SCREEN screentype% CLS REM ......................................... REM give time before alarm system is set to evacuate FOR click = 1 TO 5000: NEXT click REM ......................................... REM header PRINT title$ = " Door switch recording system" center = (W - LEN(title$)) / 2 PRINT TAB(center); title$ REM .......................................... REM set datafile name to date and time nowdate$ = LEFT$(DATE$, 2) + MID$(DATE$, 4, 2) + RIGHT$(DATE$, 2) nowtime$ = LEFT$(TIME$, 2) + "." + MID$(TIME$, 4, 2) nameoffile$ = nowdate$ + nowtime$ REM ........................................... REM record starting time in file and on screen fileaccess$ = "O" doordid$ = "S" GOSUB dofile PRINT PRINT " Started at: "; TIME$; " on "; DATE$; "." REM ............................................ REM set further file writing to append fileaccess$ = "A" REM ............................................ REM hold header and start time on screen VIEW PRINT 6 TO 24 RETURN REM --------------------------------------------------------------- REM do the door REM dothedoor: GOSUB getdoordata GOSUB reportdoordata GOSUB checkdearm RETURN REM --------------------------------------------------------------- REM check to system if de-armed checkdearm: IF STRIG(3) THEN TRUE% = 0 RETURN REM --------------------------------------------------------------- REM end of job REM endofjob: doordid$ = "E" GOSUB dofile PRINT PRINT " System down at: "; TIME$; " on "; DATE$; "." VIEW PRINT RETURN REM --------------------------------------------------------------- REM get data from door REM getdoordata: r = STRIG(1) SELECT CASE r CASE -1 flag = 1 CASE 0 flag = 2 CASE ELSE GOSUB errornotice END SELECT RETURN REM --------------------------------------------------------------- REM report data from door REM reportdoordata: SELECT CASE flag CASE OLDFLAG RETURN CASE 1 GOSUB doorclosed CASE 2 GOSUB dooropened CASE ELSE GOSUB errornotice END SELECT OLDFLAG = flag RETURN REM --------------------------------------------------------------- REM door closed REM doorclosed: IF startflag = 0 THEN startflag = 1 ELSE doordid$ = "C" GOSUB dofile PRINT " Door closed at: "; TIME$; " on "; DATE$; "." END IF RETURN REM --------------------------------------------------------------- REM door opened REM dooropened: doordid$ = "O" GOSUB dofile PRINT " Door opened at: "; TIME$; " on "; DATE$; "." GOSUB doalarm RETURN REM -------------------------------------------------------------- REM sound alarm doalarm: GOSUB domusic REM gosub domodem REM gosub dotalk RETURN REM -------------------------------------------------------------- REM play music (make up your own tune if you wish.) REM domusic: PLAY "mbcdeccdecdeffdeffgagfecgagfecc<b>cc" RETURN REM --------------------------------------------------------------- REM do the modem thing REM domodem: OPEN "com1:1200,n,8,1" FOR RANDOM AS #2 PRINT #2, "ATDT1234567;" FOR clickon = 1 TO 10000: NEXT clickon PRINT #2, "DT121212121212121212121212121212121212121212121212121212121" FOR clickoff = 1 TO 10000: NEXT clickoff CLOSE #2 RETURN REM ------------------------------------------------------------------ REM do the file thing REM dofile: OPEN fileaccess$, #1, nameoffile$ PRINT #1, q$; doordid$; q$; ","; q$; TIME$; q$; ","; q$; DATE$; q$ CLOSE #1 RETURN REM ------------------------------------------------------------------ REM error notice REM errornotice: VIEW PRINT CLS PRINT PRINT PRINT " Error occurred, Warn supervisor NOW!" RETURN REM ------------------------------------------------------------------ REM * program: doorchek.bas REM * purpose check value of joystick port connected to door REM * last update 02/04/1994 REM * Copyright (c) 1994 Carboman REM * All rights reserved. REM * REM ******************************************************************* REM ------------------------------------------------------------- REM TALK MESSAGE (requires external program!) REM REM dotalkthing: REM FOR Xit = 1 TO 3 REM talkmessage: REM SHELL "say W-AH-R-N-IH-N-G, tz-eh-r ih-s ah-n IH-N-T-R-UH-D-R" REM NEXT Xit RETURN |
Comments
Post a Comment