void SerialPort0_ISR(void) interrupt 4
{
if (RI==1)
{
clr_RI;
if(SBUF==0xF2)
{
UART_BUFFER[0] = 0xF2;
u16CNT=1;
}
else if(SBUF==0xF1)
{
UART_BUFFER[u16CNT]=0xF1;
clr_REN;
flag=1;
if(UART_BUFFER[2]==0x80)
{
z=3;
if(UART_BUFFER[4]==0x02){ERROR=2;}
if(UART_BUFFER[4]==0x03){ERROR=3;}
if(UART_BUFFER[4]==0x04){ERROR=4;}
if(UART_BUFFER[4]==0x05){ERROR=5;}
if(UART_BUFFER[4]==0x06){ERROR=6;}
if(UART_BUFFER[4]==0x07){ERROR=7;}
if(UART_BUFFER[4]==0x08){ERROR=8;}
clr_TR0;
clr_TR2;
}
}
else
{
UART_BUFFER[u16CNT] = SBUF;
u16CNT ++;
if(u16CNT>15){u16CNT=1;}
}
}
if(TI==1)
{
clr_TI;
}
}
这是串口中断
void senddata_power(UINT8 add,UINT8 cmd)
{
UINT8 j;
UINT8 send_temp[6];
send_temp[0]=0xF1;
send_temp[1]=add;
send_temp[2]=cmd;
send_temp[3]=0x00;
send_temp[4]=add+cmd+0x00;
send_temp[5]=0xF2;
P06=1;
clr_REN;
for(j=0;j<7;j++)
{
Send_Data_To_UART0(send_temp[j]);
}
set_ES;
P06=0;
set_REN;
delay(220);
clr_ES;
}
这是串口发送函数 |