• 大小: 66KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签: 单片机  通讯  proteus  

资源简介

单片机双机通讯,用proteus仿真,包含工程文件

资源截图

代码片段和文件信息

#include 
#define uchar unsigned char
#define uint unsigned int

sbit LED=P1^0;
uchar code seg_table[]={0x3f0x060x5b0x4f0x66 
    0x6d0x7d0x070x7f0x6f};

uchar count=0;
uchar second=0;
uchar receive=0;


void delay(uint i)
{
  while(i--);
}

void timer0(void) interrupt 1
{
   TH0=(65536-50000)/256;
   TL0=(65536-50000)%256;
   count++;
   if(count == 20)  
   {
     count=0;
 second++;
 if(second == 60)
   second=0;
   }
}

void int0(void) interrupt 0
{
  second++;
  if(second==60)
    second=0;
}

void int1(void) interrupt 2
{
  second--;
  if(second>60)
    second=59;
}

void serial(void) interrupt 4
{  
  if(TI==1)
  {
    TI=0;
    SBUF=second;
  }
  else
  {
    RI=0;
receive=SBUF;
if(receive == 0x55)
{
      LED = ~LED;
}
  }
}


void main(void)
{
   uchar dec;
   uchar sig;

   TMOD=0x21;  //T0 mode 1 16bit timer;T1 mode 2 8bit automatic
   PCON=0x00; //SMOD=0
   TH0=(65536-50000)/256;  //time 50ms
   TL0=(65536-50000)%256;  
   
   TH1=0xfd;
   TL1=0xfd; //baudrate 9600 oscilator 12MHz

   ET0=1; //open T0 interrupt
   ET1=0;  //must close T2‘s interrupt
   EX0=1; //open int0 
   EX1=1; //open int1
   ES=1; //open serial interrupt
   EA=1; //open the general interrupt
   IT0=1; //int0 triggered by faling edge
   IT1=1; //int1 triggered by faling edge
   TR0=1; //start T0
   TR1=1; //start T1

   SM2=0; //two at89c51 communicate by uart not more than three CPUs
   SM0=0;
   SM1=1; //serial prot mode 1 10bit/frame
   REN=1;
   

   SBUF=second; //send one frame through uart to trigger the uart interrupt
   while(1)
   {
     dec=second/10;
     sig=second%10;
     P2=seg_table[dec];
     P0=seg_table[sig];
 delay(50);
   }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     104366  2014-12-09 18:44  uartcom\Last Loaded uartcom.DBK

     文件     104366  2014-12-09 18:44  uartcom\uartcom.DSN

     文件       1078  2014-12-10 16:20  uartcom\uartcom.PWI

     文件       1800  2014-12-10 16:19  uartcom\uartcpu1\uartcpu1.c

     文件       4083  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1.LST

     文件       7721  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1.m51

     文件       9259  2014-12-09 15:53  uartcom\uartcpu1\uartcpu1.plg

     文件      55216  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1.uvopt

     文件      13248  2014-12-09 15:55  uartcom\uartcpu1\uartcpu1.uvproj

     文件       5278  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1out\uartcpu1

     文件       1194  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1out\uartcpu1.hex

     文件         84  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1out\uartcpu1.lnp

     文件       5826  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1out\uartcpu1.obj

     文件        376  2014-12-10 15:31  uartcom\uartcpu1\uartcpu1out\uartcpu1.plg

     文件      55222  2014-12-10 15:18  uartcom\uartcpu1\uartcpu1_uvopt.bak

     文件          0  2014-12-09 14:36  uartcom\uartcpu1\uartcpu1_uvproj.bak

     文件        742  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2.c

     文件       2460  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2.LST

     文件       4909  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2.m51

     文件       2858  2014-12-09 16:16  uartcom\uartcpu2\uartcpu2.plg

     文件      55216  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2.uvopt

     文件      13247  2014-12-09 16:16  uartcom\uartcpu2\uartcpu2.uvproj

     文件       3420  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2out\uartcpu2

     文件        767  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2out\uartcpu2.hex

     文件         84  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2out\uartcpu2.lnp

     文件       3536  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2out\uartcpu2.obj

     文件        376  2014-12-10 15:30  uartcom\uartcpu2\uartcpu2out\uartcpu2.plg

     文件      55222  2014-12-10 15:21  uartcom\uartcpu2\uartcpu2_uvopt.bak

     文件          0  2014-12-09 15:56  uartcom\uartcpu2\uartcpu2_uvproj.bak

     目录          0  2014-12-31 21:54  uartcom\uartcpu1\uartcpu1out

............此处省略7个文件信息

评论

共有 条评论