dtmf generator for atmega8

DTMFOUT

 

Top  Previous  Next

 

Action

 

Sends a DTMF tone to the compare1 output pin of timer 1.

 

 

 

 

 

Syntax

 

DTMFOUT number, duration

 

DTMFOUT string , duration

 

 

 

 

 

Remarks

 

Number

 

A variable or numeric constant that is equivalent with the number of your phone keypad.

 

Duration

 

Time in mS the tone will be generated.

 

string

 

A string variable that holds the digits to be dialed.

 

 

 

The DTMFOUT statement is based on an Atmel application note (314).

 

 

 

It uses TIMER1 to generate the dual tones. As a consequence, timer1 can not be used in interrupt mode by your application. You may use it for other tasks.

 

 

 

Since the TIMER1 is used in interrupt mode you must enable global interrupts with the statement ENABLE INTERRUPTS. The compiler could do this automatic but when you use other interrupts as well it makes more sense that you enable them at the point where you want them to be enabled.

 

 

 

The working range is from 4 MHz to 10 MHz system clock(xtal).

 

 

 

The DTMF output is available on the TIMER1 OCA1 pin. For a 2313 this is PORTB.3.

 

 

 

 

 

Take precautions when connecting the output to your telephone line.

 

 

 

 Ring voltage can be dangerous!

 

 

 

 

 

 

 

System Resources used

 

TIMER1 in interrupt mode

 

 

 

 

 

See also

 

NONE

 

 

 

 

 

ASM

 

The following routine is called from mcs.lib : _DTMFOUT

 

R16 holds the number of the tone to generate, R24-R25 hold the duration time in mS.

 

Uses R9,R10,R16-R23

 

 

 

The DTMF table is remarked in the source and shown for completeness, it is generated by the compiler however with taking the used crystal in consideration.

 

 

 

 

 

 

 

Example

 

'-----------------------------------------------------------------------------------------

 

'name                     : dtmfout.bas

 

'copyright                : (c) 1995-2021, MCS Electronics

 

'purpose                  : demonstrates DTMFOUT statement based on AN 314 from Atmel

 

'micro                    : Mega48

 

'suited for demo          : yes

 

'commercial addon needed  : no

 

'-----------------------------------------------------------------------------------------

 

 

 

$regfile = "m48def.dat"                                   ' specify the used micro

 

$crystal = 8000000                                         ' used crystal frequency

 

$baud = 19200                                               ' use baud rate

 

$hwstack = 32                                               ' default use 32 for the hardware stack

 

$swstack = 10                                               ' default use 10 for the SW stack

 

$framesize = 40                                             ' default use 40 for the frame space

 

 

 

'since the DTMFOUT statement uses the TIMER1 interrupt you must enable

 

'global interrupts

 

'This is not done by the compiler in case you have more ISRs

 

Enable Interrupts

 

 

 

 

 

'the first sample does dtmfout in a loop

 

Dim Btmp As Byte , Sdtmf As String * 10

 

 

 

Sdtmf = "12345678"                                         ' number to dial

 

 

 

Do

 

 

 

Dtmfout Sdtmf , 50                                         ' lets dial a number

 

'                ^ duration is 50 mS for each digit

 

Waitms 1000                                               ' wait for one second

 

 

 

 

 

' As an alternative you can send single digits

 

' there are 16 dtmf tones

 

For Btmp = 0 To 15

 

Dtmfout Btmp , 50                                       ' dtmf out on PORTB.3 for the 2313 for 500 mS

 

  'output is on the OC1A output pin

 

  Waitms 500                                             ' wait 500 msec

 

Next

 

Loop

 

End

 

 

 

'the keypad of most phones looks like this :

 

'1  2  3    optional are A

 

'4  5  6                 B

 

'7  8  9                 C

 

'*  0  #                 D

 

 

 

'the DTMFOUT translates a numeric value from 0-15 into :

 

' numeric value    phone key

 

'   0                0

 

'   1                1

 

'   2                2

 

'   3                3

 

' etc.

 

'   9                9

 

'  10                *

 

'  11                #

 

'  12                A

 

'  13                B

 

'  14                C

 

'  15                D

 

 

ارسال sms

​​درصورت هرنونه سوال . نضر . پیشناهاد در وبلاگ دارید پیام بگزارید

ارسال پیام صوتی