About 51 single chip microcomputer two-machine communication

Publisher:冷漠之心Latest update time:2015-01-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere



The figure above is a schematic diagram of two-machine communication. The following are the procedures for two-machine communication.

 

//For the receiver
#include
#define  uchar  unsigned  char;
#define  uint  unsigneed int;
uchar a; //For saving the sent data
uchar b[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //Digital tube displays 0-9;
void init(void)
{
 SCON = 0x50;
 PCON = 0x00;
 TMOD = 0x20;
 TH1 = 0xf4;
  TL1 =0xf4;
  TR1 = 1;
 EA=1;
 ES=1;

 }
 void main()
 {
  init();
 while(1)
 {
 P2=b[a];
  
    
 }
 void zd() interrupt 4//When entering an interrupt, either RI=1 or TI=1

{
if(RI)
{
 RI=0;
 a=SBUF;
 SBUF=a+1;
}
  else
  T1=0;
 }

//For the sender
#include
#define  uchar  unsigned  char;
#define  uint  unsigneed int;
unsigned char a;//Used to save the sent data
unsigned char b[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //Digital tube displays 0-9;
void init(void)
{
 SCON = 0x50;
 PCON = 0x00;
 TMOD = 0x20;
 TH1 = 0xf4;
  TL1 =0xf4;
  TR1 = 1;
 EA=1;
 ES=1;

 }
 void main()
 {
  init();
  P1=0xff;
  a=P1&0x0f;
  SBUF=a;
    
 }
void zd() interrupt 4//When entering interrupt, either RI=1 or TI=1

{
 if(RI)
  {
    RI=0;
    a=SBUF;
    P2=b[a];
  }
 else T1=0;
 }

Reference address:About 51 single chip microcomputer two-machine communication

Previous article:89C51 MCU Timer/Counter 0
Next article:Implementation of air conditioner remote controller based on PROTUES and single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号