ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 3113

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

196 16 Remote Relay Controller over Telephone Lines

Table 16.1. DTMF combinations of frequencies for each digit

Digit

Low frequency (Hz)

1

2

3

A

697

Digit

4

5

6

B

770

7

8

9

C

852

*

0

#

D

941

High frequency (Hz) 1209

1336

1477

1633

Table 16.2. The binary codes associated with the digits of the telephone set keypad

Digit

Q4

Q3

Q2

Q1

1

0

0

0

1

2

0

0

1

0

3

0

0

1

1

4

0

1

0

0

5

0

1

0

1

6

0

1

1

0

7

0

1

1

1

8

1

0

0

0

9

1

0

0

1

0

1

0

1

0

.

1

0

1

1

#

1

1

0

0

A

1

1

0

1

B

1

1

1

0

C

1

1

1

1

D

0

0

0

0

VCC

U4

DT

R12

2

TR

Q

3

PA5

4

7

R11

1K

R

DIS

5

CV

THR

6

6K8

R13

C6

C7

10K

1

GND

V+

8

VCC

10n

100n

LM555N

GND GND GND

GND

Fig. 16.4. Schematic of the multivibrator that generates the dialog tones

the DTMF commands received. This is a classic multivibrator, built with NE555, calibrated to generate a square wave signal with frequency around 1 kHz.

The circuit is controlled by the output line PA5 of the microcontroller. When PA5 = 1 the multivibrator is enabled. The duration of the audible beep transmitted is controlled by software by controlling PA5. One long beep (1 s) is used to indicate that


16.3 Description of the Software

197

the last DTMF command is invalid, while three short beeps (0.3 s) indicate a valid command.

16.3 Description of the Software

The structure of the software application, as defined in MAIN.ASM, is entirely similar to the structure of the other HC11 applications described in this book:

INCLUDE

68HC11F1.DEF

INCLUDE

AS11.MAC

INCLUDE

MAP.ASM

CODE

VECTOR_RESET

RESET

EQU

*

INCLUDE

INIT.ASM

MLOOP

EQU

*

INCLUDE

TIMER.ASM

INCLUDE

RING.ASM

INCLUDE

DTMF.ASM

INCLUDE

BEEP.ASM

JMP

MLOOP

END

The application-specific modules are RING.ASM, which controls the ring detector and the auto-answer circuits, DTMF.ASM, containing the interrupt service routine that handles the data from CM8870, and executes the commands, and BEEP.ASM, which contains the routines for controlling the generation of the dialog tones.

The central element of RING.ASM is the interrupt service routine for TIC3, called on the rising edge of the output of the ring detector circuit. This increments the variable RCNT (Ring Counter) and sets the variable QRING to $FF, to inform the main program that a ring has been detected.

The logic diagram of the task RING.ASM is presented in Fig. 16.5. Besides the variable RCNT, which is compared to the EEPROM constant MAXRING to determine the moment when the controller must open the telephone line, RING.ASM uses two software timers.

The first timer controls the time interval between two successive rings detected. If this interval is longer than 3 seconds, the detection sequence is aborted and RCNT is cleared. The other timer provides a software mechanism to terminate the connection and close the line when no DTMF tones are detected for more than 30 seconds.

The interesting aspect of this piece of software is that it is implemented as a finite state machine. The ring detection and auto-answer machine has three distinct states, encoded by the variable RSTATUS.

State 0 is the idle state, when no ring has been detected yet, and the line is closed. State 1 corresponds to the situation when 1 < RCNT < MAXRING, and state 2 is the open line state, when the controller receives and executes DTMF commands.


198 16 Remote Relay Controller over Telephone Lines

RCNT=0

RSTATUS=0

Ring ?

No

Yes

RCNT++

RSTATUS=1

Start 3s timer

Ring ?

No

Yes

RCNT>=

Timer

Yes

No

MAXRING

expired ?

Yes

No

Open line

RSTATUS=2

Start 30s timer

No

DTMF tone?

Timer

Yes

expired ?

No

Restart timer

Yes

Close line

Fig. 16.5. Logic diagram of the ring counter and auto-answer program

Each time the program enters this task, it is directed to a different section, according to the value of the variable RSTATUS. The value of RSTATUS is used as an offset in a table containing the starting addresses of the routines associated with the corresponding states:

LDX

#JTAB

;X points to jump table

LDAB

RSTATUS

LSLB

;multiply by 2 !

ABX

;adjust X

LDX

0,X

;get the address to jump

to

JMP

0,X

;and jump there

...

...

RNG00

...

;jump here when RSTATUS=0

...

RNG10

...

;jump here when RSTATUS=1

...

RNG20

...

;jump here when RSTATUS=2

...


16.3 Description of the Software

199

JTAB

DW

RNG00

;2 bytes for each address

DW

RNG10

DW

RNG20

The transitions from one state to another occur when global variables, controlled by the interrupt service routines or by other tasks, change their values. Here is an example showing how this particular state machine changes state from 0 to 1:

RNG00

TST

QRING

;QRING is set by TIC3 ISR

BEQ

END_RING

;if no ring, continue

;to next

task

LDAA

#$01

STAA

RSTATUS

;prepare

transition

;to next

state

LDAA

#3

STAA

T1S0

;start 3

sec. timer

CLR

QRING

;clear QRING

;after using it

JMP

END_RING

;execute

the rest of tasks

;before entering state1

This simple technique can be used to implement pretty complex finite state machines, with dozens of states.

The module DTMF.ASM handles data provided by the interrupt service routine for TIC2, the interrupt generated by the data strobe of CM8870. This routine places the DTMF data in a four-byte buffer DTBUF. When the end of buffer is reached, or when the binary code associated with the key ‘#’ is detected, the flag DBFULL is set to true to inform the program that the data buffer is full, and ready to be interpreted.

The following commands are accepted:

*10# – Change relay status to OFF

*11# – Change relay status to ON

•*2x# – Change the number of rings before the call is answered to the value x, ranging from 2 to 9. This parameter is stored in the EEPROM location MAXRING.

*30# – Close the line and terminate the session.

The content of the buffer is checked against this structure, and if a valid command is recognized, it is executed immediately, and three short beeps are transmitted to the telephone line to acknowledge the command. One long beep indicates invalid data detected in the buffer.

Here is the listing of the interrupt service routine for TIC2:

VECTOR_TIC2

LDAA

TFLG1

ORAA

#$02

STAA

TFLG1

;clear interrupt flag

LDAA

#30

STAA

T1S1

;restart off-hook timer

LDAA

PORTD

;get DTMF code


200

16 Remote Relay Controller over Telephone Lines

LSRA

;shift to the lower nibble

LSRA

CMPA

#$0A

;$0A is the code for ’0’

BNE

TIC210

CLRA

;change it to 0

TIC210

LDX

XDTBUF

;get pointer in DTBUF

STAA

0,X

;put data in buffer

INX

;update pointer

CPX

#ENDDBUF

;check for end of buffer

BHS

TIC220

CMPA

#$0C

;DTMF code for ‘#’

BEQ

TIC220

RTI

TIC220

LDX

#DTBUF

;point to start of buffer

STX

XDTBUF

LDAA

#$FF

;true the flag DBFULL

STAA

DBFULL

RTI

The information prepared in DTBUF by the interrupt service routine is interpreted in the task DTMF.ASM. The following code fragment shows how the relay is controlled according to the contents of the reception buffer:

TST

DBFULL

;if buffer not full,

;exit task

JEQ

END_DTMF

LDX

#DTBUF

LDAA

0,X

CMPA

#$0B

;check if first code

;is ‘*’

BNE

DT99

;error if not

LDAA

1,X

;check next code

CMPA

#$01

;check all valid opcodes

BEQ

DT10

CMPA

#$02

BEQ

DT20

CMPA

#$03

BEQ

DT30

BRA

DT99

;any other value

;is invalid

DT10

LDAA

2,X

;relay ON/OFF command

BEQ

RELOFF

CMPA

#$01

BEQ

RELON

BRA

DT99

;any other value is

invalid

RELON

LDAA

PORTA

;relay ON

ORAA

#$40

STAA

PORTA

BRA

DT90

;generate dialog tone