www.pudn.com > STC.rar > BrtSerial.c, change:2009-08-31,size:2307b


#include<intrins.h> 
sfr  IAP_CONTR =  0xC7; 
sfr  CCON    = 0xD8; 
sfr  CMOD    = 0xD9; 
sfr  CL      = 0xE9; 
sfr  CH      = 0xF9; 
sfr  CCAP0L  = 0xEA; 
sfr  CCAP0H  = 0xFA; 
sfr  CCAPM0  = 0xDA; 
sfr  CCAPM1  = 0xDB; 
sbit CR      = 0xDE; 
 
sfr AUXR	= 0X8E; 
//sfr AUXR1	= 0XA2; 
sfr BRT		= 0X9C; 
#define	RELOAD_COUNT	0XFD 
#define Self_Define_ISP_Download_Command  0x22 
void serial_port_initial(); 
void send_UART(unsigned char); 
void UART_Interrupt_Receive(void); 
void soft_reset_to_ISP_Monitor(void); 
void DownDelay(void); 
 
void serial_port_initial() 
{ 
	SCON	= 0X50; 
	BRT		= RELOAD_COUNT; 
	AUXR	= 0X11; 
	//AUXR1   = 0X80; //释放该行指令,则串口从P3口切换到p1口 
	ES 		= 1; 
	EA		= 1; 
} 
void send_UART(unsigned char i) 
{ 
	ES	= 0; 
	TI	= 0; 
	SBUF	= i; 
	while(TI == 0) ; 
	TI = 0; 
	ES = 1; 
} 
void send_uchar_ascii(unsigned char ucdat) 
{ 
	 
		send_UART(ucdat/100 + '0'); 
		send_UART((ucdat/10)%10 + '0'); 
		send_UART(ucdat%10 + '0'); 
		send_UART(' '); 
	 
} 
void send_uint_ascii(unsigned int uidat) 
{ 
	 
	if(uidat<100) 
	{ 
		send_UART((uidat/10)%10 + '0'); 
		send_UART(uidat%10 + '0'); 
		send_UART(' '); 
	} 
	else if(uidat<1000) 
	{ 
		send_UART(uidat/100 + '0'); 
		send_UART((uidat/10)%10 + '0'); 
		send_UART(uidat%10 + '0'); 
		send_UART(' '); 
	} 
	else 
	{ 
		send_UART(uidat/10000 + '0'); 
		send_UART((uidat/1000)%10 + '0'); 
		send_UART((uidat/100)%10 + '0'); 
		send_UART((uidat/10)%10 + '0'); 
		send_UART(uidat%10 + '0'); 
		send_UART(' '); 
	} 
} 
 
 
void UART_Interrupt_Receive(void) interrupt 4 
{ 
	static unsigned char k = 0; 
	if(RI) 
	{ 
		RI = 0; 
		k = SBUF; 
		if(k==Self_Define_ISP_Download_Command)   //是自定义下载命令 
        { 
            DownDelay();    //延时1秒就足够了 
            DownDelay();    //延时1秒就足够了 
            soft_reset_to_ISP_Monitor();    //软复位到系统ISP监控区 
        } 
		//send_UART(k); 
	} 
	else 
	{	TI = 0;	} 
} 
void soft_reset_to_ISP_Monitor(void) 
{ 
    IAP_CONTR   =    0x60;   //0110,0000   软复位到系统ISP监控区 
} 
 
void DownDelay(void) 
{ 
    unsigned int j  =   0; 
    unsigned int g  =   0; 
    for(j=0;j<5;j++) 
    { 
        for(g=0;g<60000;g++) 
        { 
            _nop_(); 
            _nop_(); 
            _nop_(); 
            _nop_(); 
            _nop_(); 
        } 
    } 
}