標(biāo)題: 單片機(jī)雙機(jī)通訊 [打印本頁]

作者: 林鹿    時(shí)間: 2019-7-1 16:51
標(biāo)題: 單片機(jī)雙機(jī)通訊
找大佬幫我看一下為什么按下按鈕數(shù)碼管不會(huì)動(dòng)
主機(jī)
#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;
   }
  }
}
}
從機(jī)
#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;
}








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1