www.pudn.com > TELEPHONE.rar > TM8888.C, change:2008-04-03,size:2575b


#include <at89x51.h> 
#include <absacc.h> 
#include <intrins.h> 
#include <MT8888.h> 
 
void main(void) 
{ 
	init(); 
	while(1) 
	{ 
//		mode_cp(); 
		mode_DTMFOUT();		 
//		mode_DTMFIN();		 
//		ONTEL=0; 
	} 
} 
 
 
void mode_cp(void) 
{ 
		TMOD=0x11; 
		TH1=0; 
		TL1=0; 
		TH0=0; 
		TL0=0; 
		ONTEL=1; 
		P0=0xff; 
		while(INT); 
		while(!INT); 
		TR1=1; 
		while(INT); 
//		TR1=0; 
//		TR0=1; 
		while(!INT); 
		TR1=0; 
		_nop_(); 
} 
 
void mode_DTMFOUT(void) 
{ 
	uchar a; 
	ONTEL=1; 
	delayms(1000); 
	XBYTE[0x4000]=0x01;		 
	delayms(500); 
	XBYTE[0x4000]=0x0a;		 
	delayms(500); 
	XBYTE[0x4000]=0x0a;		 
	delayms(500); 
	XBYTE[0x4000]=0x05;		 
	delayms(500); 
	a=XBYTE[0x0100]; 
	P1=0x02; 
	_nop_(); 
		 
 
/*		uchar a; 
		ONTEL=1; 
		P0=0xff; 
		delayms(1000); 
		a=0x09; 
		writedata(a); 
		delayms(2000); 
		a=0x01; 
		writedata(a); 
		delayms(500); 
		a=0x0a; 
		writedata(a); 
		delayms(500); 
		a=0x0a; 
		writedata(a); 
		delayms(500); 
		a=0x05; 
		writedata(a); 
		delayms(500); 
 
		a=0x06; 
		writedata(a); 
		delayms(500); 
		a=0x07; 
		writedata(a); 
		delayms(500); 
		a=0x07; 
		writedata(a); 
		delayms(500); 
		a=0x01; 
		writedata(a); 
		delayms(500); 
		a=0x07; 
		writedata(a); 
		delayms(500); 
		a=0x04; 
		writedata(a); 
		delayms(500); 
		a=0x08; 
		writedata(a); 
		delayms(500); 
 
		a=readsr(); 
*/ 
} 
 
void mode_DTMFIN(void) 
{ 
	uchar a; 
	ONTEL=1; 
	P0=0xff; 
	do 
	{ 
		a=readsr(); 
	}while((a&0x04)==0); 
	a=readdata(); 
	_nop_(); 
} 
 
void init(void) 
{ 
	uchar a; 
	P1=0; 
	ONTEL=0; 
	delayms(100); 
 
	XBYTE[0x0100]=0; 
	XBYTE[0x0100]=0; 
	XBYTE[0x0100]=0x08; 
	XBYTE[0x0100]=0; 
	a=XBYTE[0x0100]; 
	XBYTE[0x0100]=0x01; 
	delayms(100); 
	XBYTE[0x0100]=0x09; 
	XBYTE[0x0100]=0; 
 
 
	/* 
	a=readsr(); 
	a=0x00; 
	writesr(a); 
	writesr(a); 
	a=0x08; 
	writesr(a); 
	a=0x00; 
	writesr(a); 
	a=readsr(); 
	a=0x06;//01; 
	writesr(a); 
	delayms(100); 
	a=0x0e;//09; 
	writesr(a); 
	a=0x00; 
	writesr(a); 
	*/ 
} 
 
uchar readsr(void) 
{ 
	uchar b; 
	WRE=1; 
	RDE=0; 
	RSE=1; 
	CSE=0; 
	_nop_(); 
	_nop_(); 
	b=P0&0x0f; 
	CSE=1; 
	return(b); 
}	 
 
void writesr(uchar a) 
{ 
	WRE=0; 
	RDE=1; 
	RSE=1; 
	CSE=0; 
	_nop_(); 
	_nop_(); 
	P0=a; 
	_nop_(); 
	_nop_(); 
	CSE=1; 
} 
 
uchar readdata(void) 
{ 
	uchar b; 
	WRE=1; 
	RDE=0; 
	RSE=0; 
	CSE=0; 
	_nop_(); 
	_nop_(); 
	b=P0&0x0f; 
	CSE=1; 
	return(b); 
}	 
 
void writedata(uchar a) 
{ 
	WRE=0; 
	RDE=1; 
	RSE=0; 
	CSE=0; 
	_nop_(); 
	_nop_(); 
	P0=a; 
	_nop_(); 
	_nop_(); 
	CSE=1; 
} 
 
 
void delayms(uint n) 
{ 
	uint b; 
	while(n>0) 
	{ 
		for(b=0;b<100;b++); 
		n--; 
	} 
}