djc
Advanced Member level 1

Hi,
I have written a C code using CodeVision AVR and Tiny2313 to detect dtmf tones using 8870 and turn on the relay if any of the valid code is found. Code is as followsm,
Logic is, when phone is off hook, i have to detect valid dtmf tone, so i checked Est pin,then made TOE pin high and read the OUTPUT and stored the digit accordingly. Used one counter 'i' to know how many times dtmf tone has been appeared, as code is 4 digit. So when i==4 means i have got all four digits then i formed complete number and checked it with numbers stored in an array. I Dont know where i am going wrong. Plz help
I have written a C code using CodeVision AVR and Tiny2313 to detect dtmf tones using 8870 and turn on the relay if any of the valid code is found. Code is as followsm,
Code:
#include <tiny2313.h>
#include <delay.h>
#define EST PIND.1
#define STD PINA.1
#define Q4 PINA.0
#define Q3 PIND.2
#define Q2 PIND.3
#define Q1 PIND.4
#define TOE PORTD.5
#define RELAY PORTD.6
#define Phn_In PINB.0
int i=0,j=0,d1=0,d2=0,d3=0,d4=0;
char k =0;
int code[13] = {1780,1781,1782,1783,1784,1785,1786,1787,1788,1789,1790,1791,1799};
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTB=0x00;
DDRB=0x00;
// Port D initialization
// Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x60;
while (1)
{
// Place your code here
if(Phn_In==1){
if(EST==1){
delay_ms(50);
//PORTB.6 = 1;
//delay_ms(500);
TOE = 1;
delay_ms(50);
if((Q4==1) && (Q3==0) && (Q2==1) && (Q1==0)){
j=0;
i++;
}
if((Q4==0) && (Q3==0) && (Q2==0) && (Q1==1)){
j=1;
i++;
}
if((Q4==0) && (Q3==0) && (Q2==1) && (Q1==0)){
j=2;
i++;
}
if((Q4==0) && (Q3==0) && (Q2==1) && (Q1==1)){
j=3;
i++;
}
if((Q4==0) && (Q3==1) && (Q2==0) && (Q1==0)){
j=4;
i++;
}
if((Q4==0) && (Q3==1) && (Q2==0) && (Q1==1)){
j=5;
i++;
}
if((Q4==0) && (Q3==1) && (Q2==1) && (Q1==0)){
j=6;
i++;
}
if((Q4==0) && (Q3==1) && (Q2==1) && (Q1==1)){
j=7;
i++;
}
if((Q4==1) && (Q3==0) && (Q2==0) && (Q1==0)){
j=8;
i++;
}
if((Q4==1) && (Q3==0) && (Q2==0) && (Q1==1)){
j=9;
i++;
}
if((Q4==1) && (Q3==0) && (Q2==1) && (Q1==1)){ //for *
j=1;
i++;
PORTB.1=1;
delay_ms(500);
}
PORTB.1=0;
TOE = 0;
//PORTB.6 = 0;
}
if(i==1){
d1=j;
d1=d1*1000;
PORTB.2 = 1;
delay_ms(500);
PORTB.2 = 0;
}
if(i==2){
d2=j;
d1=d1+(100*d2);
PORTB.3 = 1;
delay_ms(500);
PORTB.3 = 0;
}
if(i==3){
d3=j;
d1=d1+(10*d3);
PORTB.4 = 1;
delay_ms(500);
PORTB.4 = 0;
}
if(i==4){
d4=j;
d1=d1+d4;
PORTB.5 = 1;
delay_ms(500);
PORTB.5 = 0;
for(k=0;k<13;k++){
if(d1==code[k]){
RELAY = 1;
i=0;
break;
}
}
}
}
if(Phn_In ==0){
i = 0;
RELAY = 0;
d1=0;
d2=0;
d3=0;
d4=0;
}
};
}
Logic is, when phone is off hook, i have to detect valid dtmf tone, so i checked Est pin,then made TOE pin high and read the OUTPUT and stored the digit accordingly. Used one counter 'i' to know how many times dtmf tone has been appeared, as code is 4 digit. So when i==4 means i have got all four digits then i formed complete number and checked it with numbers stored in an array. I Dont know where i am going wrong. Plz help