华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx

上传人:b****5 文档编号:18128605 上传时间:2022-12-13 格式:DOCX 页数:9 大小:15.89KB
下载 相关 举报
华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx_第1页
第1页 / 共9页
华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx_第2页
第2页 / 共9页
华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx_第3页
第3页 / 共9页
华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx_第4页
第4页 / 共9页
华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx

《华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。

华邦单片机双串口RS485通信中断实现程序Word格式文档下载.docx

//inttemp,ch;

ucharcheck;

ucharcont,f;

ucharg,h;

uchark,i;

voiddelay(uintz)

{

uintx,m;

for(x=z;

x>

0;

x--)

for(m=110;

m>

m--);

}

voidinit()

EA=1;

ES=1;

//开串口中断

ES1=1;

TMOD=0x20;

//定时计数器1,8位自动重装方式2

TH1=0xe8;

//设计串口1的波特率为1200

TL1=0xe8;

SCON1=0x50;

//设计串口1为工作模式1,10位数据波特率可设

PCON=0x00;

//波特率不倍增

TR1=1;

//开定时计数器1

//IP=0x10;

//设定串口0优先级最高

SCON=0x50;

T2CON=0x30;

//选择迫使定时器2做串口0的波特率发生器

RCAP2L=0xe0;

RCAP2H=0xfe;

//辞工作在捕捉模式,其自动装入TH2中,波特率为1200

TR2=1;

//开定时计数器2

PMR=0x01;

//程序访问片内1KSRAM

P0=0xff;

flag2=1;

dog=0;

f=0;

i=0;

k=0;

voidsendbyte0(chartemp)

{

re0=0;

SBUF=temp;

while(!

TI);

TI=0;

}

voidsendbyte(charch)

re=0;

SBUF1=ch;

TI_1);

TI_1=0;

ucharreceivecheck1()

uintp;

ucharsum;

sum=0;

for(p=2;

p<

23;

p++)

{

sum=sum+store[p];

}

returnsum;

voidcodesend()

intn,e,m,x;

uchartemp;

for(e=1;

e<

=5;

e++)

senddate[e]=0xbb;

senddate[6]=P0;

senddate[7]=0x00;

senddate[8]=0x12;

senddate[0]=0x1b;

temp=senddate[1];

for(m=9;

m<

27;

m++)

senddate[m]=date[n];

n++;

if(n==18)

n=0;

for(x=2;

x<

=26;

x++)

temp=temp^senddate[x];

senddate[27]=temp;

ucharreceivecheck()

ucharch,j;

ch=comd0[1];

for(j=2;

j<

=7;

j++)

ch=ch^comd0[j];

returnch;

 

voidmain()

init();

c373ctrl2=0;

XBYTE[8005]=0;

while

(1)

init();

if(flag2)

{

flag2=0;

/*for(g=0;

g<

7;

g++)

{

sendbyte(comd[g]);

}*/

TI_1=1;

}

if(flag==1)

flag=0;

f=0;

for(h=5;

h<

h++)

date[f]=store[h];

f++;

if(f==18)

{

f=0;

flag2=1;

}

}

delay(1000);

if(flag1)

TI=1;

flag1=0;

}

dog=~dog;

delay(5);

//delay(900);

/*if(flag1)

codesend();

//ES=0;

for(p=0;

28;

sendbyte0(senddate[p]);

}

//delay(200);

REN_1=1;

ES1=1;

REN=1;

ES=1;

//ES=1;

}*/

}

voidext0(void)interrupt4

ucharq;

re0=1;

//访问片内SRAM数据放到片外存储器

if(RI==1)

{

comd0[k]=SBUF;

k++;

RI=0;

if(k==9)

k=0;

check=receivecheck();

if((comd0[6]==P0)&

&

(comd0[8]==check))

{

REN=0;

//flag2=1;

ES1=0;

REN_1=0;

flag1=1;

if(TI)

//flag1=0;

TI=0;

re0=0;

codesend();

for(q=0;

q<

q++)

sendbyte0(senddate[q]);

if(q==28)

{

q=0;

TI=0;

re0=1;

}

}

voidext1()interrupt7

ucharchcek1,g;

re=1;

if(RI_1)

//ES=0;

store[i]=SBUF1;

i++;

if(i==25)

i=0;

chcek1=receivecheck1();

if(chcek1==store[23])

flag=1;

//REN=1;

//ES=0;

//ES1=0;

//REN_1=0;

RI_1=0;

if(TI_1)

ES=0;

TI_1=0;

re=0;

for(g=0;

if(g==7)

re=1;

g=0;

ES=1;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1