REM FILE: DTMF2PRN.BAS, WRITTEN IN QBASIC, by Paul Bergsman REM REM Inputs 4-bit data from an M8870, DTMF Receiver to Binary converter, REM via an IBM-compatible Parallel Printer Port. Output from the REM M8870 is read into the parallel port's (Base Address + 1). D6 REM of the (Base Address + 1), the ACKbit, is used to input M8870's REM strobe signal. When D6 goes to an active HIGH, the new byte value is REM displayed on the screen. The ACK bit can also be used as a hardware REM TSR, (Terminate and Stay Resident), input. If some additional REM software is added, this circuit can be operated as a TSR device. REM The program opens a file on Disk Drive "A:\". All files begin with REM "DTMF", followed by four digits coding today's date. For example, if REM today's date is 12/23/1994, the program opens a file titled: REM DTMF1223.DAT REM All DTMF signals decoded on 12/23, will be stored in the file REM called DTMF1223. Each record in the file will start with the time REM the phone was taken off-hook, followed by all DTMF codes, and REM ending with the time of hang-up. The file will include a "P" for a REM pause greater than 10 seconds. If the pause is longer than two REM minutes, the program closes the current record and waits for an REM off-hook signal to start a new record. REM REM Each day starts a new file. If operating at midnight the program REM closes the current file and opens a new one for the new date. REM REM To EXIT the program, press "E" REM REM The following IC chips are equivalent: REM CMD CM8870C, Crystal CS8870, Motorola MC8870, and Teltone M8870 REM OpenFile: FileName$ = DATE$ FileName$ = "DTMF" + LEFT$(FileName$, 2) + MID$(FileName$, 4,2) + ".DAT" FileName$ = "A:\" + FileName$ OPEN FileName$ FOR APPEND AS #1: REM add records to today's file INPUTBITS = 0: ActiveTone = 0: OffHook = 0: TonePresent = 0: D0 = 1: D1 = 1: D6 = 64: LptPortAddress = 0: PhoneNumber$ = "" LptPortAddress = 888: REM Base address of Graphic Card's printer port. REM Use 632 for 3ED printer port base address. REM Use 956 for Monochrome Card's printer port. CLS Today$ = DATE$ PRINT "Open file = "; FileName$ WaitForCall: OffHook = INP(LptPortAddress + 1) IF Today$ <> DATE$ THEN GOTO CloseFile: REM new day means new file Ch$ = INKEY$ IF (Ch$ = "e") OR (Ch$ = "E") THEN GOTO ExitProgram: IF (OffHook AND D0) = 0 THEN GOTO WaitForCall: REM phone off-hook? REM start new record StartTime& = TIMER PhoneNumber$ = TIME$ + " ": REM record begins with start time WaitForDTMFcode: StartTime& = TIMER OUT (LptPortAddress + 2), 4: REM set all bits HIGH with 000001100 TonePresent = INP(LptPortAddress + 2): REM is a DTMF tone present OffHook = INP(LptPortAddress + 1) IF (OffHook AND D0) = 0 THEN GOTO DigestDTMFcode: EndTime& = TIME&: ElapsedTime& = EndTime& - StartTime& IF (ElapsedTime& > 120) THEN GOTO CloseFile: IF (ElapsedTime& > 10) AND (RIGHT$(PhoneNumber$, 2) <> "P ") THEN PhoneNumber$ = PhoneNumber$ + "P " END IF DigestDTMFcode: IF (TonePresent AND DO) = 0 THEN GOTO WaitForDTMFcode: ActiveTone = INP(LptPortAddress + 1): REM input decoded Touch-Tones REM -=[ reformat raw data as low nibble, D0 - D3 J=- ActiveTone = ActiveTone XOR 128: REM invert the inverted bit, D7 IF (ActiveTone AND 128) = 128 THEN ActiveTone = ((ActiveTone - 128) * 2) + 128 GOTO Shift5Right: ELSE ActiveTone = ActiveTone * 2: END IF Shift5Right: ActiveTone = ActiveTone \ 16: AddToneToRecord: SELECT CASE ActiveTone CASE 1 TO 9 Temp$ = STR$ (ActiveTone): REM decode characters "1" TO "9" CASE 10 Tenp$ = "0" CASE 11 Temp$ = "*" CASE 12 Temp$ = "#" CASE 13 TO 15 Temp$ = STRS$ (ActiveTone + 53): REM decode characters "A" TO "C" CASE 0 Temp$ = "D" END SELECT PhoneNumber$ = PhoneNumber$ + Temp$ + " " PRINT Temp$; " "; : REM display DTMF code OUT (LptPortAddress + 2), 4: REM set all bits HIGH with 00000100 IF (INP(LptPortAddress + 2) AND D1) = 0 THEN GOTO SaveRecord: OffHook = INP(LptPortAddress + 1): REM is phone still off hook? IF (OffHook AND DO) = 0 THEN GOTO WaitForDTMFcode: PRINT SaveRecord: Temp$ = Temp$ + TIME$: REM add hang-up time to file PRINT #1, Temp$: REM save record to file PRINT Temp$: PRINT: REM display record GOTO WaitForDTMFcode: CloseFile: CLOSE GOTO OpenFile: ExitProgram: CLOSE END