STC15F2K60S2串口2程序
#include "reg51.h"
sfr P4 = 0xc0;
sfr P5 = 0xc8;
sfr AUXR = 0x8e ;
sfr S2CON = 0x9a ;
sfr S2BUF = 0x9b ;
sfr T2H = 0xd6 ;
sfr T2L = 0xd7 ;
sfr IE2 = 0xaf ;
sfr IP2 = 0xb5 ;
#define S2RI 0x01 // S2CON.0
#define S2TI 0x02 // S2CON.1
unsigned char temp ;
bit flag1 = 0 , flag2 = 0 , busy = 0 ;
unsigned char xdata Uart1TxBuffer [20] = "杜兴杰你必须加油个"; //
void Uart2Init(void) //9600bps@11.0592MHz
{
S2CON = 0x50; //8位数据,可变波特率
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
T2L = 0xE0; //设定定时初值
T2H = 0xFE; //设定定时初值
AUXR |= 0x14; //启动定时器2 4 注意这里
EA = 1 ;
IE2 = 0x01 ; //开启串口中断ES2
IP2 |= 0x00 ; //串口2优先级0
}
void main( void )
char i ;
P0 = 0 ;
Uart2Init() ;
SendData (C) ;
SendData (C) ;
for ( i = 0 ; i < 20 ; i++ )
}
for ( i = 0 ; i < 20 ; i++ )
}
SendData (C) ;
SendData (C) ;
while(1)
}
}
}
void Uart2( void ) interrupt 8
if( S2CON & S2RI )
}
}
}
// while ( !( S2CON & 0x02 ) ) ;
下一步是把串口1和串口2 加在一起,还有就是加入循环队列实现流控等
评论