Pantech.AI

How to Interface MT8870 DTMF with 8051 microcontroller

Introduction

DTMF (Dual Tone Multi-Frequency) is a signaling technique in telecommunications that uses a combination of two pure tone frequencies (sine waves) to generate dial tones in telephones. When a key is pressed, a pair of tones—one low and one high frequency—is sent. There are 8 unique frequencies: 4 in a lower range and 4 in a higher range. This setup enables 16 possible combinations, corresponding to the 16 keys on a keypad.

The MT8870 is a DTMF decoder that identifies which key is pressed by decoding the incoming DTMF signal. It contains a band-split filter that separates the input signal into low and high frequencies, enabling it to detect the specific key. The decoder outputs a 4-bit digital code, allowing 16 unique outputs for each key.

The microcontroller can read this 4-bit code to determine the pressed key. For more details on the MT8870 DTMF decoder and its application, refer to the “MT8870 DTMF Decoder” section in Sensors and Modules.

Interfacing diagram

DTMF Decoder Interfacing with 8051

Example

In this section, we’ll interface the MT8870 DTMF receiver/decoder module with the 8051 microcontroller to receive keypress inputs from a cellphone keypad and display the decoded key on a 16×2 LCD.

Programming for DTMF

/*
 * Interfacing DTMF with 8051
 * http://www.electronicwings.com
 */

#include<stdio.h>
#include<reg52.h>
#include<LCD_16x2_8-bit_Header_File.h>

#define DTMF_Input_Read P2

void External_Interrupt_Init();

volatile char Key_detect;		/* flag to check Tone is received or not */

void main()
{   
	unsigned char DTMF_Key;		/* variable to store detected key */           
	LCD_Init();
	LCD_Clear();
	DTMF_Input_Read = 0xff;		/* set port as input */
	LCD_String_xy(0,0,"DTMF Key:");
	External_Interrupt_Init();
	Key_detect = 0;
	while(1)
	{
		MSdelay(1);
		if(Key_detect)                /* Key_detect = 1 indicates Tone Received*/
		{
			Key_detect = 0;
			LCD_Command(0xc0);
			DTMF_Key = 0;
			DTMF_Key = (DTMF_Input_Read & 0x0f);
			switch(DTMF_Key)  /* detect received key*/
			{
				case 0x01: LCD_Char('1');
				           break;
				case 0x02: LCD_Char('2');
					   break;
				case 0x03: LCD_Char('3');
					   break;
				case 0x04: LCD_Char('4');
					   break;
				case 0x05: LCD_Char('5');
					   break;
				case 0x06: LCD_Char('6');
					   break;
				case 0x07: LCD_Char('7');
					   break;
				case 0x08: LCD_Char('8');
					   break;
				case 0x09: LCD_Char('9');
					   break;
				case 0x0A: LCD_Char('0');
					   break;
				case 0x0B: LCD_Char('*');
					   break;
				case 0x0C: LCD_Char('#');
					   break;
			}
		}
	}
}


void External_Interrupt_Init()				
{
	EA  = 1;		/* Enable global interrupt */
	EX0 = 1;      		/* Enable Ext. interrupt0 */			
	IT0 = 1;      		/* Select Ext. interrupt0 on falling edge */ 	
}
/* ISR is used to check tone is received or not */
											
void External0_ISR() interrupt 0    
{
	Key_detect = 1;		/* Toggle pin on falling edge on INT0 pin */
}

Leave a Comment

Your email address will not be published. Required fields are marked *