Sierra

Radio

PayPal: View Cart

Project:  8870 DTMF Decoder

This project uses a 8870 DTMF decoder chip.  


The idea is to connect the line or discriminator audio out from a receiver to the prototype board.  As DTMF digits are decoded, the output is sent to the serial port and LCD display.


The audio input level should be between 0.5 and 1v.



'  HamStack DTMF Decoder 8870 Example.bas

'  This program listens to the output of a 8870 DTMF decoder and will

'  send each DTMF digit value out the serial port.

'  Version 1.0


Device = 18F4620             ' Set the CPU type to a Microchip 18F4620

Clock = 10                   ' Set CPU clock frequency to 10 MHz

#option LCD_DATA = PORTD.0

#option LCD_RS = PORTD.4

#option LCD_EN = PORTD.5

Include "usart.bas"          ' Include the RS232 UART subroutines

Include "convert.bas"

Include "lcd.bas"

Include "utils.bas"


'----- VARIABLE DEFINITIONS ---------------------------------------

Dim x   As Byte              ' Working variable used to count how many times we go through the loop

Dim dv As PORTB.4

Dim d1 As PORTB.0

Dim d2 As PORTB.1

Dim d4 As PORTB.2

Dim d8 As PORTB.3

Dim led As PORTC.0

Dim loop_count As LongInt

Dim dtmf_char As Char


'----- DEFINE PIN DIRECTIONS --------------------------------------

'      0 = output

'      1 = input

TRISC.0 = 0                  ' Status LED is defined as an output pin

TRISB.0 = 1

TRISB.1 = 1

TRISB.2 = 1

TRISB.3 = 1

TRISB.4 = 1

TRISC.0 = 0


'----- INITIALIZE VARIABLES AND SERIAL PORT ------------------------

x = 0                        ' Initialize loop counter to zero

loop_count = 0

SetBaudrate(br9600)          ' Set serial baud rate to 9600

Cls   

WriteAt(1,1,"DTMF Decoder")   ' Update LCD display



'----- START MAIN PROGRAM CODE -------------------------------------

DelayMS(100)                 ' Pause for 100ms after hardware reset to settle down

USART.Write("Hello world from HamStack", 13, 10)    ' Send hello world greeting


'----- START MASTER CONTROL LOOP ------------------------------------

master_loop:


If dv = 1 Then

   GoTo debounce_dv

   EndIf

GoTo master_loop


debounce_dv:

    DelayMS (10)

    If dv = 0 Then GoTo master_loop EndIf


    x = 0

    'dv still present, continue...      

    If PORTB.0 = 1 Then x = 1     EndIf

    If PORTB.1 = 1 Then x = x + 2 EndIf

    If PORTB.2 = 1 Then x = x + 4 EndIf

    If PORTB.3 = 1 Then x = x + 8 EndIf


    Select x

           Case  1 dtmf_char = "1"

           Case  2 dtmf_char = "2"

           Case  3 dtmf_char = "3"

           Case  4 dtmf_char = "4"

           Case  5 dtmf_char = "5"

           Case  6 dtmf_char = "6"

           Case  7 dtmf_char = "7"

           Case  8 dtmf_char = "8"

           Case  9 dtmf_char = "9"

           Case 10 dtmf_char = "0"

           Case 11 dtmf_char = "*"

           Case 12 dtmf_char = "#"

           Case 13 dtmf_char = "A"

           Case 14 dtmf_char = "B"

           Case 15 dtmf_char = "C"

           Case 0  dtmf_char = "D"

    EndSelect


    USART.Write("Decoded value = ", dtmf_char, " (", DecToStr(x), ")", 13, 10)

    WriteAt(2,1,"       ")   ' Update LCD display

    WriteAt(2,1,dtmf_char, " (", DecToStr(x), ")")   ' Update LCD display


debounce_dv2:

    DelayMS (10)

    If dv = 1 Then GoTo debounce_dv2 EndIf

    GoTo master_loop