找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1869|回复: 2
打印 上一主题 下一主题
收起左侧

单片机之间双向通信Proteus仿真程序

[复制链接]
跳转到指定楼层
楼主


单片机源程序如下:
  1. /***************   writer:shopping.w   ******************/
  2. #include <reg52.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit LED1 = P1^0;
  6. sbit LED2 = P1^3;
  7. sbit K1 = P1^7;
  8. uchar Operation_NO = 0;
  9. uchar code DSY_CODE[]=
  10. {
  11.         0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
  12. };

  13. void Delay(uint x)
  14. {
  15.         uchar i;
  16.         while(x--)
  17.         {
  18.                  for(i=0;i<120;i++);
  19.         }
  20. }

  21. void putc_to_SerialPort(uchar c)
  22. {
  23.         SBUF = c;
  24.         while(TI == 0);
  25.         TI = 0;
  26. }

  27. void main()
  28. {
  29.         LED1=LED2=1;
  30.         P0 = 0x00;
  31.         SCON = 0x50;
  32.         TMOD = 0x20;
  33.         PCON = 0x00;
  34.         TH1  = 0xfd;
  35.         TL1  = 0xfd;
  36.         TI   = 0;
  37.         RI   = 0;
  38.         TR1  = 1;
  39.         IE   = 0x90;
  40.         while(1)
  41.         {
  42.                  Delay(100);
  43.                 if(K1 == 0)
  44.                 {
  45.                          while(K1==0);
  46.                         Operation_NO=(Operation_NO+1)%4;
  47.                         switch(Operation_NO)
  48.                         {
  49.                                  case 0:
  50.                                                 putc_to_SerialPort('X');
  51.                                                 LED1=LED2=1; break;
  52.                                 case 1:
  53.                                                 putc_to_SerialPort('A');
  54.                                                 LED1=0;LED2=1;break;
  55.                                 case 2:
  56.                                                 putc_to_SerialPort('B');
  57.                                                 LED2=0;LED1=1;break;
  58.                                 case 3:
  59.                                                 putc_to_SerialPort('C');
  60.                                                 LED1=0;LED2=0;break;
  61.                         }
  62.                 }
  63.         }
  64. }

  65. void Serial_INT() interrupt 4
  66. {
  67.         if(RI)
  68.         {
  69.                  RI = 0;
  70.                 if(SBUF>=0&&SBUF<=9)
  71.                         P0 = DSY_CODE[SBUF];
  72.                 else
  73.                         P0 = 0x00;
  74.         }
  75. }
复制代码

所有资料51hei提供下载:
单片机之间双向通信.zip (85.59 KB, 下载次数: 22)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:479983 发表于 2020-5-14 10:43 | 只看该作者
不错的资料
回复

使用道具 举报

板凳
ID:751513 发表于 2020-5-14 11:01 | 只看该作者
加油,资料很好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表