原创 两片单片机串口+proteus仿真

2008-5-9 02:12 2472 7 7 分类: MCU/ 嵌入式

点击下载


 


主机的程序如下


#include <reg51.h>


//初始化串行口
void csh()
{
 SM0=0;
 SM1=1;
 REN=1;
 TI=0;
 RI=0;
 PCON=0;
 TH1=0xF3;
 TL1=0XF3;
 TMOD=0X20;
 EA=1;
 ET1=0;
 ES=1;
 TR1=1;
}


void main()
 {
  int i,j;
  char c="0";
  csh();
  while(1)
  {
   //ES=0;
   //TI=0;
   P0=c;
   SBUF=c;
   while(!TI);
   TI=0;
   //ES=1;
   for(j=0;j<50;j++)
   for(i=0;i<5000;i++);
   c++;
   if (c>9)
   c=0;
  }
}


void intrr() interrupt 4
 {
  char temp;
  temp=SBUF;
  P2=temp;
  RI=0;
 }


从机U2的程序如下
#include <reg51.h>
 unsigned char temp;
//初始化串行口
void csh()
 {
  SM0=0;
  SM1=1;
  REN=1;
  TI=0;
  RI=0;
  PCON=0;
  TH1=0xF3;
  TL1=0XF3;
  TMOD=0X20;
  EA=1;
  ET1=0;
  ES=1;
  TR1=1;
 }


void main()
 {  // char temp;
  csh();
  while(1)
  {temp=temp+2;
  if (temp>9)
  temp=0;
  //ES=0;
  //TI=0;
  P0=temp;
  SBUF=temp;
  while(!TI);
  TI=0;
   }
}


void intrr() interrupt 4
 { //char temp;
  
  temp=SBUF;
  P2=temp;
  RI=0;
  
 
 }

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /3 下一条