1. 先思考設計是不是需要這麼多UART
2. 可用GPIO來模擬,以下是software UART的收發範例
void recev() routine to recieve
{
unsigned char r=0;
bit sbuff[8];
if(P3.2==0) //start bit detection
while(r<8)
{
sbuff[r]=P3.2;
r++;
TR0=1;
while(TF0==1); //delay in between bits Timer 0 is used
TR0=0;
}
if(P3.2==1) //stop bit condition achieved
TFLG=1; //flag to indicate the receive has completed
}
void transmit_vir(unsigned char dat) //a simple transmisson algorithm
{
unsigned char tx=0,cp_data;
cp_data=dat;
TX1=0; //start bit
TR0=1; //timer start
while(TF0==1);
TR0=0;
while(tx<8)
{
TX1=(0x80&dat)?1:0; //8-bit data
TR0=1;
while(TF0==1);
TR0=0;
cp_data=cp_data<<1;
tx++;
}
TFLG=1; //transmission flag
TR0=1; //baud rate
while(TF0==1);
TR0=0;
TX1=1; //stop bit
}
然後STC也有包含範例,這篇有做講解
http://www.51hei.com/bbs/dpj-39826-1.html
下載
http://cf03.ickimg.com/bbsfiles/201704/5adedeee2ea210957e37f2fc325a6bdc.rar
總會有合適的,以上供參考