C51与HT9170和HT9200接口程序(双音多频)
/********************************************
ht9200A/ht9170程序
双音多频接收发射程序
********************************************/
sbit DATA = P3^7 ;
sbit CLK = P3^6 ;
sbit CE = P2^7 ;
/*******************************************
DTMF 数据口:P0^0 ~ P0^3
*******************************************/
sbit DV = P2^6 ;
sbit OE = P3^2 ;
//sbit PWDN = P3^6 ;
//sbit INH = P3^7 ;
sbit DXC = P3^5 ;
sbit RING = p3^0 ;
#ifndef TRUE
define TRUE 1 ;
#endif
#ifndef FALSE
define FALSE 0 ;
#endif
uchar idata Check0 ;
uchar idata Counter0 ;
uchar idata Check1 ;
uchar idata Counter1 ;
uchar idata Check3 ;
uchar idata Counter3 ;
uchar code Table_DTMF[] = {0x0a,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0d,0x0e,0x0f,0x00,0x0b,0x0c} ;
// 0 1 2 3 4 5 6 7 8 9 A B C D * #
void senddata_ht9200(uchar in)
{
uchar i;
for(i=0;i<5;i++)
{
if(((in>>i)&0x01) == 1)
DATA = 1 ;
else DATA = 0 ;
CLK = 0 ;
CLK = 1 ;
}
}
/******************************************
发送子程序
in 为要发送的数 0-15
******************************************/
void send_ht9200(uchar in)
{
CE = 0 ;
CLK = 1 ;
time(50) ; //delay about 6 ms
EA = 0 ;
senddata_ht9200(Table_DTMF[in]) ;
EA = 1 ;
delay(100) ; //delay about 100 ms
CE = 1 ;
}
/*****************************************
DTMF 读程序
返回 DTMF值
*****************************************/
uchar DTMF_read(void)
{
uchar TEMP ;
uchar i ;
EA = 0 ;
P0 = 0xff ;
OE = 1 ;
ACC = ACC ;
TEMP = P0&0x0f ;
OE = 0 ;
EA = 1 ;
for(i=0;i<16;i++)
{
if(TEMP == Table_DTMF
)
return i ;
}
return(0xff) ;
}
/******************************************
初始化检测程序
******************************************/
void checkRING_Init()
{
Check0 = 2 ;
Counter0 = 20 ;
}
void checkDV_Init()
{
Check1 = 2;
Counter1 = 20;
}
void checkDXC_Init()
{
Check3 = 2 ;
Counter3 = 20 ;
}
/***************************************
检测有无振铃RING 程序
返回 TRUE :有
FALSE:无
***************************************/
uchar check_RING(void) //
{
uchar flag ;
flag = RING ; //check RING
if((flag == 0)&&(Counter0 < 30))
Counter0 ++ ;
if((flag == 1)&&(Counter0 > 0))
Counter0 -- ;
if(Counter0 == 30)
{
Counter0 = 20 ;
if(flag != Check0)
{
Check0 = flag ;
return TRUE ;
}
else return FALSE;
}
else if(Counter0 == 0)
{
Counter0 = 20 ;
Check0 = 1;
return FALSE;
}
else
return FALSE ;
}
/***************************************
检测有无DTMF信号 DV 程序
返回 TRUE :有
FALSE:无
***************************************/
uchar check_DV(void) //
{
uchar flag ;
flag = DV ; //check DV
if((flag == 1)&&(Counter1<30))
Counter1 ++ ;
if((flag == 0)&&(Counter1 >0))
Counter1 -- ;
if(Counter1 == 30)
{
Counter1 = 20 ;
if(flag != Check1)
{
Check1 = flag ;
return TRUE ;
}
else return FALSE ;
}
else if(Counter1 == 0)
{
Counter1 = 20 ;
&nbs
一周热门 更多>