📄 zhuji.c
字号:
#include<reg51.h>
#include<absacc.h>
#include<intrins.h>
unsigned char cort=0;
sbit P3_5=P3^5;
static temp,temp1;
/*********************************
按键扫描子程序
*********************************/
//key_serial() interrupt 0 using 1
//{
// ++cort;
//}
/*********************************
发送子程序
*********************************/
void master(void)
{
temp=SBUF;
if((temp!=temp1)&(temp!=0x00)) P2=temp;
if(cort==1)
{
SBUF=0x01;//发送地址
while(TI!=1);TI=0;//判断是否发送完毕
P3_5=0;//准备好接收
SM2=0; //发送数据标志
while(RI!=1);RI=0;//判断是否接受完毕
//P2=SBUF;//将接收到的数据送到P2口
SM2=1; //接收数据标志
P3_5=1; //准备好发送
}
if(cort==2)
{
SBUF=0x02;
while(TI!=1);TI=0;
SM2=0;
P3_5=0;
while(RI!=1);RI=0;
//P2=SBUF;
SM2=1;
P3_5=1;
}
if(cort==3)
{
SBUF=0x03;
while(TI!=1);TI=0;
SM2=0;
P3_5=0;
while(RI!=1);RI=0;
//P2=SBUF;
SM2=1;
P3_5=1;
}
temp1=temp;
cort=cort+1;
if(cort==4)cort=1;
SM2=1;
}
/***************主程序****************/
void main(void)
{
P2=0xff;
TMOD=0x20;
TL1=0xfd;
TH1=0xfd;
PCON=0x00;
TR1=1;
SCON=0xf8;
EA=1;
EX0=1;
IT0=1;
P3_5=1;//准备好发送
P2=0x00;
while(1)
{
master(); //发送
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -