初级会员
- 积分
- 68
- 金钱
- 68
- 注册时间
- 2014-3-11
- 在线时间
- 0 小时
|
5金钱
#include "reg51.h"
#include "intrins.h"
sfr S2CON = 0x9A;
sfr AUXR = 0x8E;
sfr T2L = 0xD7;
sfr T2H = 0xD6;
sfr S2BUF = 0x9B;
sfr IE2 = 0xAF;
//sfr IP2 = 0xB5;
sfr P_SW2 = 0xBA;
#define S2RI 0x01
#define S2TI 0x02
unsigned char tmp;
//发送一个字符
void send_char(unsigned char dat)
{
ACC = dat;
S2BUF = ACC;
}
void delay(unsigned char ms)
{
while(ms--);
}
void UartInit(void) //19200bps@11.2592MHZ
{
S2CON = 0x50; //8位数据,可变波特率
AUXR |= 0x40; //定时器2时钟为Fosc,即1T
T2L = 0x70; //设置定时初值
T2H = 0xFF; //设置定时初值
AUXR |= 0x10; //启动定时器2
}
void main()
{
P_SW2 = 0x01; //串口2切换到P3.6/P3.7
IE = 0x80; //总中断使能
IE2 = 0x01; //串口2中断使能
UartInit();
while(1)
{
}
}
void Uart2() interrupt 8 using 1
{
if(S2CON & S2RI)
{
//S2RI = 0;
S2CON &= ~S2RI; //清除S2RI位
tmp = S2BUF;
delay(10);
// send_char(tmp);
}
if(S2CON & S2TI)
{
S2CON &= ~S2TI; //清除S2TI位
delay(10);
send_char(tmp);
}
}
麻烦各位帮忙看看有没有什么问题
|
|