📄 cm.c
字号:
#include <AT89X51.H>
#define uchar unsigned char
void mDelay(unsigned int Delay);
uchar str1[4]={226,98,0,0}; //定义发送的字节数
uchar indate[4];
uchar ap;
uchar count, count_r=0;
void main()
{
/* 系统初始化 */
TMOD = 0x20; //定时器T1使用工作方式2
TH1 = 253; // 设置初值
TL1 = 253;
TR1 = 1; // 开始计时
PCON = 0x80; // SMOD = 1
SCON = 0x50; //工作方式1,波特率9600bps,允许接收
ES = 1;
EA = 1; // 打开所以中断
TI = 0;
RI = 0;
P1=0xff;
P3_5=0;
while(1)
{
ap=P1;
while(ap==P1)
{;}
str1[2] = P1;
str1[3] = str1[2];
count = 1;
SBUF=str1[0];
P3_7=0;
mDelay(300);
while(P1!=ap)
{;}
}
}
void RSINTR() interrupt 4 using 2
{
if(TI==1)
{
TI=0;
if(count < 4)
{
SBUF= str1[count];
count++;
}
else
{
mDelay(80);
P3_7=1;
}
}
if(RI==1)
{
indate[count_r]=SBUF;
count_r++;
if (count_r >=4)
{
RI=0;
count_r=0;
if (indate[0]==str1[0] && indate[1]==str1[1])
{
switch (indate[2])
{
case 109:
P3_4=1;
P3_5=0;
break;
case 45:
P3_4=0;
P3_5=1;
str1[2] = 157;
str1[3] = 157;
count = 1;
SBUF=str1[0];
break;
}
}
else
{
count_r=0;
}
}
RI=0;
}
}
void mDelay(unsigned int Delay)
{ unsigned int i;
for(;Delay>0;Delay--)
{ for(i=0;i<124;i++)
{;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -