📄 serial.c
字号:
//初值 = 256-(2SMOD * fosc) / (fx*32*12)
// 初值 = (2097152*波特率-Fosc)/(波特率*32)
// 1200 FEE0
//extern void callid_close() ;
uchar idata Serial_SendBuf[32] ;
uchar Serial_SendLength= 0 ;
uchar idata Serial_Receive[10] ;
uchar Serial_ReceiveLength = 0 ;
uchar idata Command_status ;
void Serial_Init()
{
// TMOD = (TMOD & 0x0f) | 0x20;
// TH1 = 0xe8 ;
// TL1 = 0xe8 ;
T2CON = 0x30 ;
RCAP2H = 0xfe ;
RCAP2L = 0xe0 ;
TH2 = 0xfe ;
TL2 = 0xe0 ;
SCON = 0x50 ;
// PCON = 0 ;
TR2 = 1 ;
ET2 = 0 ;
ES = 1 ;
PS = 1 ;
mem_set(Serial_SendBuf,0,32) ;
mem_set(Serial_Receive,0,10) ;
Serial_SendLength = 0 ;
Serial_ReceiveLength = 0 ;
Command_status = 0 ;
}
void Serial_SendData()
{
uchar i ;
SBUF= Serial_SendBuf[0] ;
Serial_SendLength -- ;
for(i=0;i<Serial_SendLength;i++)
{
Serial_SendBuf[i] = Serial_SendBuf[i+1] ;
}
}
void Serial_RP_Interrupt() interrupt 4 using 2
{
uchar rxdata,i ;
EA = 0 ;
if(TI ==1)
{
TI =0 ;
if(Serial_SendLength>0)
{
SBUF= Serial_SendBuf[0] ;
Serial_SendLength -- ;
for(i=0;i<Serial_SendLength;i++)
{
Serial_SendBuf[i] = Serial_SendBuf[i+1] ;
}
}
}
if(RI ==1)
{
RI = 0 ;
rxdata = SBUF ;
Serial_Receive[Serial_ReceiveLength] = rxdata ;
Serial_ReceiveLength ++ ;
if(Serial_ReceiveLength>=10) Serial_ReceiveLength = 10 ;
if(rxdata == '#')
{
Command_status = 1 ;
}
}
EA = 1 ;
}
void Serial_SendCommand(uchar *Buf,uchar Length)
{
uchar i ;
mem_move(Serial_SendBuf,Buf,Length) ;
Serial_SendLength = Length ;
Serial_SendData() ;
i = 0 ;
while(Serial_SendLength != 0)
{
delay(10) ;
i++ ;
if(i>50) Serial_SendLength = 0 ;
}
}
/*
uchar ATCommand_Analyse()
{
uchar AT_Type,i;
if((Serial_Receive[0]!='a')&&(Serial_Receive[0] !='A')) return 0;
if((Serial_Receive[1]!='t')&&(Serial_Receive[1] !='T')) return 0;
AT_Type = Serial_Receive[2];
switch(AT_Type)
{
case 'a': //摘机应答
case 'A':
SW = 1;
Phone_ToneCtrl(TRUE) ;
return 1;
case 'h': //挂机
case 'H':
SW = 0;
Phone_ToneCtrl(FALSE) ;
return 1;
case 's':
case 'S':
return 1;
case 'd': //拨号
case 'D':
SW = 1 ;
delay(500) ;
for(i = 3; i < Serial_ReceiveLength-1; i++)
{
// send_ht9200(8) ;
delay(130) ;
send_ht9200(Serial_Receive[i]-0x30) ;
// delay(130) ;
// send_ht9200(8) ;
}
Phone_ToneCtrl(TRUE) ;
return 1;
case '1':
Phone_ToneCtrl(FALSE) ;
return 1 ;
case '2':
Callid_Ring_time = 0 ;
return 1 ;
default: return 0;
}
return 0;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -