?? eye121.c
字號:
/*********************************************************************
*這是在AT89C2051單片機上運行的程序,文件名為eye121.c
*功能:AT89C2051作為分站與主站W77E58通訊,雙方均有RS485接口 ,AT89C2051
* 用T1作波特率發生器, 波特率為9600,配套主站W77E58程序為EYE5.C
**********************************************************************/
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
void timedelay(uint timess);
uchar n;
uchar rbut[12];
uchar tbut[12];
uchar kc1,kc2,flag;
sbit p13=P1^3;
void timedelay(uint timess)
{
uint tj;
for (tj=timess;tj>0;tj--){;}
}
sio0() interrupt 4 using 1
{
if (RI==0) {
if (TI==0) {RI=0;TI=0;return;}
SBUF=tbut[kc1];
kc1++;
if (kc1!=10) {RI=0;TI=0;return;}
kc1=0;
p13=0; //恢復為接收方式
SCON=0xf0;
loo1:if (TI==0) goto loo1;
RI=0;
TI=0;
}
if (SM2==0) {
rbut[kc2]=SBUF;
kc2++;
if (kc2!=10) {RI=0;TI=0;return;}
rbut[1]=rbut[2]+rbut[3]+rbut[4]; //add check
if (rbut[1]!=rbut[5]) {flag=1; }
kc2=0;
p13=1; //準備發送
SCON=0xe8;
SBUF=0x01;/* 01*/
TB8=0;
SM2=0;
RI=0;
TI=0;
}
if (SBUF!=1) {RI=0; return;}/* 01*/
SM2=0;
RI=0;
}
void main()
{
SP=0x70;
timedelay(10000);
kc1=0;
kc2=0;
EA=0;
flag=0;
tbut[0]=0x01;/* 01*/
tbut[1]=0x03;
tbut[2]=0x1; /*tbut[2]-tbut[7]放6個字節 01*/
tbut[3]=0x2;
tbut[4]=0x3;
tbut[5]=0x4;
tbut[6]=0x5;
tbut[7]=0x6;
tbut[8]=21;
tbut[9]=0x0;
TMOD=0x20;
PCON=0x0;
TL1=0xfd;
TH1=0xfd; //11.0592mhz,smod=0:1200==0xe8;9600==0xfd
TR1=1;
SCON=0xf0;
ES=1;
p13=0; //準備接收
EA=1;
while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -