?? 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 + -