新闻中心

EEPW首页>嵌入式系统>设计应用> 单片机与串口232通讯《续》

单片机与串口232通讯《续》

作者: 时间:2016-11-23 来源:网络 收藏
目的:这是一个通过串口发送区发送数据后,串口接收区接收发送的数据。//注意串口设置是16进制还是ASIIC码?如果是16进制,那接收到的第一个数据就是00。如ASIIC则不显示数据。

程序:

本文引用地址://m.amcfsurvey.com/article/201611/320388.htm

#include
bit point=1; //标志位
unsigned char temp;
unsigned char i;

//---------------------------------------------------------
void init()//串口初始化
{
TMOD=0x20;
SCON=0x50;
TH1=0xfD;
TR1=1;
ES=1;
EA=1;
}

//-------------------------------------------------------------------------------
void send()
{
SBUF=temp;
while(TI==0);
TI=0;

}

//----------------------------------------------------------------------------------
void UART ()interrupt4 //串口通讯中断
{
if(RI==1)
{
RI=0;
temp=SBUF;
point=1;
for(i=0;i<10;i++);
}
}

//-------------------------------------------------------------------------------------
void main()
{
temp=0x00;
init();
while(1)
{
if(point==1)
{
point=0;
send();
}
}
}



关键词:单片机串口232通

评论


技术专区

关闭