'=========================================================================== ' Subject: PROGRAM THE PARALLEL PORT Date: 07-13-96 (13:44) ' Author: Christoph Kummetat Code: QB, QBasic, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: MISC.ABC '=========================================================================== '> With 8 data lines I have many options and combinations thereof. I am '> not familair with the bit structure of characters. Any clue as to how '> to go about deciding the characters to use that would activate line '> "1" only while leaving the others alone? 'here's some code, which might help you to program the parallel port. 'Originally it is a programm to set 8 relais via LPT. I shortened it to the 'important things. If you have more questions about, feel free to ask me... InitVar: DEFINT A-Z DIM SHARED Bit(8), BitStatus, Port, RelNr DIM SHARED Anzahl(8) CONST Blk = 0, Blu = 1, Grn = 2, Zyn = 3, Red = 4 'set colors CONST Gry = 7, Yel = 14, Wht = 15, Blink = 16 CONST TRUE = 1, FALSE = NOT TRUE 'set boolean CLS : Count = 1 FOR i = 1 TO 8 Bit(i) = Count 'set bits with bit-values Count = Count + Count 'increase values (0,1,2,4,8,16,32,64,128) NEXT i CALL DATEN.Find.LPT 'search for LPTs BitStatus = 0 'switch all lines OFF OUT Port, BitStatus 'send to LPT CALL DATEN.Get.Status 'read LPT WHILE INKEY$ <> "q" CALL DATEN.Set.Status FOR i = 1 TO 8 CALL DATEN.Get.Status NEXT i WEND OUT Port, LEDStatus 'an par. SN senden SUB DATEN.Find.LPT DEF SEG = 0: DIM Port(4) Count = 0: COLOR Wht, Blu FOR i = 1032 TO 1036 STEP 2 IF PEEK(i) + 256 * PEEK(i + 1) > 0 THEN Count = Count + 1 Port(Count) = VAL("&H" + HEX$(PEEK(i) + 256 * PEEK(i + 1))) LOCATE 4 + Count, 6 PRINT "Printerport"; STR$(Count); " : "; PRINT "&H" + HEX$(PEEK(i) + 256 * PEEK(i + 1)) END IF NEXT i IF Count = 0 THEN 'no port found PRINT "No parallel port found on your PC !"; ch$ = INPUT$(1) CLOSE : COLOR Wht, Blk: CLS : END END IF GetPrt: 'choose LPT LOCATE , 6: PRINT "Which parallel port do you want to use : "; v$ = INPUT$(1) 'ask for LPT IF VAL(v$) < 1 OR VAL(v$) > Count THEN SOUND 3200, .3: GOTO GetPrt 'invalid value END IF Port = Port(VAL(v$)) 'define port END SUB SUB DATEN.Get.Status BitStatus = INP(Port) 'read LPT FOR i = 1 TO 8 IF BitStatus AND Bit(i) THEN Status = 1 ELSE Status = 0 END IF CALL DISPLAY.Status(i, Status) NEXT i END SUB SUB DATEN.Relais.Reset BitStatus = 0: OUT Port, BitStatus 'reset all registers at LPT END SUB SUB DATEN.Set.Status 'send value to LPT COLOR Blk, Gry: LOCATE 12, 6: PRINT "which line to set ? : " LOCATE 13, 6: PRINT "(number 1 - 8 or 0 for all OUT) " GetBit: v$ = INPUT$(1) 'number of LPT BitNr = VAL(v$) IF ASC(v$) = 27 THEN COLOR Wht, Blk: CLS : END 'Escape, end program IF BitNr > 8 THEN SOUND 3200, .3: GOTO GetBit 'hey, you can only choose between 1 and 8 GetSts: IF BitNr = 0 THEN BitStatus = 0 'switch all lines OFF OUT Port, BitStatus 'send to LPT CALL DISPLAY.Status(BitNr, BitStatus) 'display status ELSEIF BitStatus AND Bit(BitNr) THEN 'is line ON or OFF ? BitStatus = BitStatus XOR Bit(BitNr) 'swith bit/line to OFF OUT Port, BitStatus 'send to LPT CALL DISPLAY.Status(BitNr, BitStatus) 'display status ELSE BitStatus = BitStatus + Bit(BitNr) 'add bit/line OUT Port, BitStatus 'send to LPT CALL DISPLAY.Status(BitNr, BitStatus) 'display status END IF END SUB SUB DISPLAY.Status (BitNr, Status) 'show status of bits/lines IF BitNr >= 1 THEN IF Status >= 1 THEN COLOR Wht, Red 'bit/line active LOCATE 8, ((BitNr * 8) + BitNr) - 3: PRINT " ON " ELSE COLOR Wht, Grn 'bit/line inactive LOCATE 8, ((BitNr * 8) + BitNr) - 3: PRINT " OFF " END IF ELSE COLOR Wht, Grn 'all bits/lines OFF FOR i = 1 TO 8 LOCATE 8, ((i * 8) + i) - 3: PRINT " OFF " NEXT i END IF END SUB