📄 eye1.c
字号:
/*********************************************************************
这是在AT89C52单片机上运行的程序,文件名为eye1.c
功能:AT89C52单片机作为分站与上位机(PC机或工控机)通讯,
双方均有RS485接口 ,T1作波特率发生器, 波特率为1200,
与上位机通讯的主要流程为:中断接受上位机发来的地址
信息,看是否是给本站发来的,若是, 接受后续的15个字
节,然后发送43个字节。若不是, 则不予理睬。 配套上
位机程序为xsa2.c。
*********************************************************************/
#include <reg52.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
void timedelay(uint timess);
uchar n;
uchar idata rbut[16];
uchar idata tbut[42];
uchar kc1,kc2,aa,coni;
sbit p11=P1^1;
void timedelay(uint timess)
{
uint tj;
for (tj=timess;tj>0;tj--){;}
}
sio1() interrupt 4 using 2
{
if (RI==0) {
if (TI==0) {RI=0;TI=0;return;}
SBUF=tbut[kc1];
kc1++;
if (kc1!=42) {RI=0;TI=0;return;}
kc1=0;
p11=0; //恢复为接收方式
SCON=0xf0;
loo1:if (TI==0) goto loo1;
RI=0;
TI=0;
}
if (SM2==0) {
rbut[kc2]=SBUF;
kc2++;
if (kc2!=15) {RI=0;TI=0;return;}
kc2=0;
p11=1; //准备发送
SCON=0xe8;
SBUF=0xff;
TB8=0;
SM2=0;
RI=0;
TI=0;
}
if (SBUF!=1) {RI=0; return;}
SM2=0;
RI=0;
}
void main()
{
timedelay(10000);
kc1=0;
kc2=0;
EA=0;
for (coni=0;coni<42;coni++)
{
tbut[coni]=coni;
}
TMOD=0x20;
PCON=0x0;
TL1=0xe6;
TH1=0xe6;
TR1=1; //12mh, smod=0: 1200== e6;
SCON=0xf0;
ES=1;
p11=0; //准备接收
EA=1;
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -