找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1251|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)雙機(jī)通訊

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
找大佬幫我看一下為什么按下按鈕數(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;
}



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表