uchar code dtmf[16]={0x0a,1,2,3,4,5,6,7,8,9,0x0d,0x0e,0x0f,0x00,0x0b,0x0c}; uchar code rdtmf[16]={0x0d,1,2,3,4,5,6,7,8,9,0,0x0e,0x0f,0x0a,0x0b,0x0c};
sbit wr=P1^0;//mt8880读写控制 sbit cs8880=P1^1;//mt8880片选 sbit rs=P1^2;//mt8880寄存器控制 sbit o2=P1^3;//mt8880读写数据锁存
W8880(1,0x0c);//初始化 W8880(1,0x01);//初始化
char Rd8880(uchar data mode) /*读状态mode=1/数据mode=0*/ { uchar data i; wdi=~wdi; cs8880=0; rs=(bit)mode; wr=1; o2=1; P0=0xff; i=P0; o2=0; cs8880=1; o2=1; i=i&0x0f; if(mode) return i; else return rdtmf; }
void Wr8880(uchar data mode,uchar data t) /*写入设置mode=1/数据mode=0*/ { wdi=~wdi; cs8880=0; rs=(bit)mode; wr=0; o2=1; if(mode) P0=t; else P0=dtmf[t]; o2=0; wr=1; cs8880=1; o2=1; }
void Dtmf_Txd(uchar dtmf)/*发送1个dtmf码*/ { uchar data kk; wdi=~wdi; kk=dtmf; Wr8880(0,kk); /*是数字,发送*/ Wr8880(1,0x05); Delay_Msec(100);/*发送结束符*/ Wr8880(1,0x04); Delay_Msec(100);/*发送结束符*/ }
uchar Dtmf_Rxd() /*接收1个dtmf码*/ { uchar data i; P0=0xff; TL1=0x00; TH1=0x4c; sec_1=0; sec=0; TR1=1; i=0xff; do { if(!int8880) { i=Rd8880(1); i=Rd8880(0); break; } wdi=~wdi; } while(sec<5);//Wait 5s if(i==0xff) return(i); else { return(i);/*返回数据*/ } } |