📄 复件 (2) recesive.c
字号:
#include <AT89x051.H>
unsigned char receivebits;
unsigned char receivebytes;
unsigned char buf[2];
unsigned char check;
bit flag;
bit start;
unsigned int i;
unsigned char j;
void main(void)
{
check=0;
P3_3=1;
P3_4=1;
P3_5=1;
P3_7=1;
SP=0X59;
P3_0=1; //置为接收
for(i=0;i<=25;i++)
{ for(j=0;j<=10000;j++)
{
P3_1=1;
P3_1=0;
}
}
P3_3=1;
P3_4=1;
P3_5=1;
P3_7=1;
EX0=1;
IT0=1;
receivebits=0; //接收的位=0
receivebytes=0; //接收的字节=0
buf[0]=0;
buf[1]=0; //置空接收缓冲
flag=0; //没有接收到控制数据
start=0; //数据线空闲
EA=1;
while(1)
{
P3_1=0;
P3_1=1;
if(flag) //如果有控制数据
{
if((buf[1]&0x01)==0x00)
P3_3=0;
else
P3_3=1;
if((buf[1]&0x02)==0x00)
P3_4=0;
else
P3_4=1;
if((buf[1]&0x04)==0x00)
P3_5=0;
else
P3_5=1;
if((buf[1]&0x08)==0x00)
P3_7=0;
else
P3_7=1;
flag=0;
}
}
}
receivedata()interrupt 0 using 3
{
check++;
if(check==0x55)
{
P3_3=~P3_3;
P3_4=~P3_4;
P3_5=~P3_5;
P3_7=~P3_7;
EA=0;
}
/*
if(start==0) //如果目前空闲
{
if(check==0x99999999) start=1; //如果检测到低电平,则置数据线开始传输数据
return;
}
else //如果正在传输数据
{
P3_3=0;
P3_4=1;
P3_5=1;
P3_7=0;
receivebits++; //接收的位+1
buf[receivebytes]=buf[receivebytes]<<1;
if(databit) buf[receivebytes]++; //接收的数据位进缓冲
if(receivebits==8) //如果接收了1字节
{
start=0; //置数据线空闲
receivebits=0; //接收的位计数=0
receivebytes++; //接收的字节计数+1
if(receivebytes==2) //如果接收了2字节
{
flag=1; //如果组号相等,置接收到控制数据
receivebytes=0; //接收的字节计数=0
}
}
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -