找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机输入数的大小比较及判断实验

[复制链接]
跳转到指定楼层
楼主
ID:72519 发表于 2015-1-21 22:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
是用51hei单片机开发板 电路图详见:http://www.51hei.com/f/51hei-5.pdf   用2个74hc573 锁存,p0口作为数据口 ,p3.6和p3.7分别是段和位的锁存端口.

  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  5. sbit D=P3^6;
  6. sbit V=P3^7;
  7. //===================
  8. uchar a=0,b=0,c;
  9. //===================
  10. uchar key_S1(void);
  11. uchar key_S2(void);
  12. void delay(uint k);
  13. //=====================
  14. void main(void)
  15. {  uchar i;
  16. while(1)
  17. {
  18. b=key_S1();
  19. a=key_S2();
  20. if(a>b)c=0x76;
  21. if(a<b)c=0x38;
  22. if(a==b)c=0x09;
  23. for(i=0;i<50;i++)
  24. {
  25. D=1;
  26. P0=SEG7[a];
  27. D=0;
  28. P0=0xff;
  29. V=1;
  30. P0=0xfe;
  31. V=0;
  32. delay(2);
  33. D=1;
  34. P0=SEG7[b];
  35. D=0;
  36. P0=0xff;
  37. V=1;
  38. P0=0xfd;
  39. V=0;
  40. delay(2);
  41. D=1;
  42. P0=c;
  43. D=0;
  44. P0=0xff;
  45. V=1;
  46. P0=0xfb;
  47. V=0;
  48. delay(2);
  49.       }
  50. }
  51. }
  52. //==============
  53. void delay(uint k)
  54. {
  55. uint i,j;
  56. for(i=0;i<k;i++){
  57. for(j=0;j<121;j++)
  58. {;}}
  59. }
  60. //===================
  61. uchar key_S1(void)
  62. {static uchar x;
  63. P2=0xff;
  64. if(P2!=0xff)
  65. {delay(10);
  66. if(P2==0xdf)
  67. {
  68. x=x+1;
  69.   }
  70.   }
  71. if(x>9)x=0;
  72. return x;
  73. }
  74. //=======================
  75. uchar key_S2(void)
  76. {static uchar y;
  77. P2=0xff;
  78. if(P2!=0xff)
  79. {delay(10);
  80. if(P2==0xbf)
  81. {
  82. y=y+1;
  83.   }
  84.   }
  85. if(y>9)y=0;
  86. return y;
  87. }
复制代码


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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