登录|立即注册|使用QQ帐号登录
论坛 > 51单片机
发帖|
看4147|回3|收藏
楼主 ID:510873 只看他
2019-11-23 17:52
要求:
1、双机通过串口连接
2、主机接受矩阵键盘按下的值,处理后通过串口发送对应数据给从机
3、从机接收主机发送的数据,通过处理后,LCD实时显示发送的数值,并在“=”发送后开始运算,同时显示结果

仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.gif
2.png

源程序:

代码:


  1. /**
  2.   P1:按键
  3.   P2:数据LCD
  4.   P3:RW,RW,EN

  5. 主从机功能分配:
  6.    
  7.     主机以字符串形式接收数据,并实时发送给从机,从机实时进行LCD显示
  8.    
  9.     当主机检测输入为"="时,从机检测接收到"=",从机计算结果,再进行LCD显示
  10. */
  11. #include <reg52.h>
  12. #include <stdio.h>
  13. #include "Keyscan.h"
  14. #include "usart.h"

  15. unsigned char num;
  16. //unsigned char str;

  17. // 主机: 以字符串形式接收数据,并实时发送给从机
  18. void main()
  19. {   
  20.     UsartInit();
  21.     delay(200);
  22.     while(1)
  23.     {         
  24.         num=KeyPro();//键盘扫描
  25.         if(num!=0xff) //按键按下
  26.         {  
  27.             putchar(num);
  28.         }
  29.     }
  30. }


代码:

  1. //主机main函数
  2. void main()
  3. {   
  4.     UsartInit();
  5.     delay(200);
  6.     while(1)
  7.     {         
  8.         num=KeyPro();
  9.         if(num!=0xff)
  10.         {  
  11.             putchar(num);
  12.         }
  13.     }
  14. }

  15. //从机main函数
  16. UsartInit();
  17.     LCD_init();
  18.     putstring("Hello,this is calaulator\r\n");
  19.     putstring("He is made from Hebin and Wangshaoji\r\n");
  20.     showstring(0,0,Hello_0);
  21.     showstring(0,1,Hello_1);
  22.     delayms(500);
  23.     while(1)
  24.     {   
  25.         showstring(0,0,dis_table0);
  26.         showstring(0,1,dis_table1);
  27.     }
  28. }
51hei.png
代码和仿真都放在资料中了
注意只支持Proteus7.5版本,其他版本打开都会报错的,dsn文件和代码51hei下载地址:
distant_calculator.zip (45.58 KB)
(下载次数: 99, 2019-11-23 17:52 上传)

下载积分: 黑币 -5


沙发 ID:649283 只看他
2019-11-25 22:23
仿真文件是Proteus7.5格式的  其他版本不行的
板凳 ID:102963 只看他
2020-6-24 08:48
楼主,您的资料全吗
地板 ID:1016455 只看他
2022-4-8 14:23
仿真文件是Proteus7.5格式的,用7.9打开果然报错

51黑电子论坛

Powered by Discuz! X3.1

首页|标准版|触屏版|电脑版