找大佬帮我看一下为什么按下按钮数码管不会动
主机
#include <reg51.h>
sbit KEY1=P1^0;
unsigned char Seg_i=0;
unsigned char code address[]={0xfe,0xfd};
unsigned CountKey1;
void delay(unsigned char xms)
{
unsigned char i,j;
for(i=0;i<xms;i++)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
}
void main()
{
init();
while(1)
{
if(KEY1==0)
{
delay(10);
if(KEY1==0)
{
while(!KEY1);
CountKey1++;
if(CountKey1==10)
CountKey1=0;
TB8=1;
SBUF=address[0];
while(!TI);
TI=0;
TB8=0;
SBUF=CountKey1;
while(!TI);
TI=0;
}
}
}
}
从机
#include <reg51.h>
unsigned char add_buf,tx_buf;
unsigned char code addr=0xfe;
unsigned char code LED[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
SM2=1;
REN=1;
EA=1;
ES=1;
}
void main()
{
init();
while(1)
{
;
}
}
void ES_int() interrupt 4
{
RI=0;
ES=0;
if(RB8==1)
{
add_buf=SBUF;
if(add_buf==addr)
{
SM2=0;
}
}
else
{
tx_buf=SBUF;
P1=LED[tx_buf];
SM2=1;
}
ES=1;
}
|