//串口發送
void sendChar(char *p)//調用前關中斷,調用完成後關中斷 { while(*p != '\0') { SBUF = *P while(!TI); TI = 0; p++; } } void sendChar(char *p)//調用前關中斷,調用完成後關中斷 { while(*p != '\0') { SBUF = *P while(!TI); TI = 0; p++; } }
//串口接收
//串口初始化
void series_init() { SCON = 0x50; //串口工作方式1,允許接受 TMOD = 0x20; //定時器T1工作方式2 TH1 = 0xfd;TL1 = 0xfd; //定時初值 PCON &= 0x00; //smod = 0 TR1 = 1; //開啟定時器1 EA = 1;ES = 1; //開總中斷可串行終端 } void series_init() { SCON = 0x50; //串口工作方式1,允許接受 TMOD = 0x20; //定時器T1工作方式2 TH1 = 0xfd;TL1 = 0xfd; //定時初值 PCON &= 0x00; //smod = 0 TR1 = 1; //開啟定時器1 EA = 1;ES = 1; //開總中斷可串行終端 }
unsigned char ReceiveBuf;
//串行中斷服務函數
void series() interrupt 4
{
RI = 0;
ReceiveBuf = SBUF;
/*
do something;
*/
}
unsigned char ReceiveBuf;
//串行中斷服務函數
void series() interrupt 4
{
RI = 0;
ReceiveBuf = SBUF;
/*
do something;
*/
}