找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4835|回复: 6
收起左侧

51单片机八路抢答器程序和仿真 压缩包

[复制链接]
ID:250610 发表于 2017-11-18 19:28 | 显示全部楼层 |阅读模式
0.png
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png 0.png
单片机源程序如下:
  1. #include <REGX51.H>
  2. #define  Keytimer_1        10
  3. sbit K0=P3^0;
  4. sbit K1=P1^0;sbit K2=P1^1;sbit K3=P1^2;sbit K4=P1^3;
  5. sbit K5=P1^4;sbit K6=P1^5;sbit K7=P1^6;sbit K8=P1^7;
  6. sbit A575=P2^0;         sbit B575=P2^1; sbit C575=P2^2;   
  7. sbit BZ=P2^3;
  8. unsigned int Keytimer=0,t=0,sec=60,OK=0,hh=0,sec1=0;

  9. unsigned char DM[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};  //8个数码管段码表
  10. unsigned char WE[4]={0x01,0x02,0x04,0x08};  //8个数码管段码表
  11. void flang();
  12. /*------------------------------------------------
  13.            公用延迟函数
  14. ------------------------------------------------*/
  15. void delayus(unsigned int y)                       
  16. {
  17.         while(y--);       
  18. }
  19. //*****************定时器初始化**************************
  20. void initialize(void)
  21. {
  22.         TMOD =0x01;
  23.         TH0 = 0x3C;
  24.         TL0 = 0xB0;           //50ms
  25.         ET0 = 1;
  26.         EA = 1;
  27.         TR0 = 1;
  28. }
  29. /*------------------------------------------------
  30.            8位数码管 指针 显示函数
  31. ------------------------------------------------*/
  32. void shumaxianshi()
  33. {
  34.         unsigned char i,ii=2,tempP[4];
  35.         if(OK==2)
  36.         {ii=4;flang();
  37.         tempP[0] = sec1/10%10;
  38.         tempP[1]=sec1%10;               
  39.         }
  40.         else
  41.         {tempP[0] = sec/10%10;
  42.         tempP[1]=sec%10;}


  43.         tempP[2]=hh/10%10;
  44.         tempP[3] = hh %10;
  45.         for(i=0;i<ii;i++)
  46.         {       
  47.                 P0=DM[tempP[i]];                                                                                   //指针赋值
  48.                 A575=1;A575=0;       
  49.                 delayus(4);
  50.                 P0=~WE[i];          
  51.                 B575=1;B575=0;
  52.                 delayus(4);                                                                                           //最低限制
  53.                 P0=0xff;          
  54.                 B575=1;B575=0;
  55.         }
  56. }
  57. unsigned char KES()
  58. {
  59.         if(K1==1&&K2==1&&K3==1&&K4==1&&K5==1&&K6==1&&K7==1&&K8==1&&K0==1)        //没有按的时候  返回    加快 51 跑的速度
  60.         return 0;
  61.         if(K0==0 && !Keytimer)
  62.         {
  63.                 Keytimer=Keytimer_1;
  64.                 return 9;       
  65.         }
  66.         if(K1==0 && !Keytimer)
  67.         {
  68.                 Keytimer=Keytimer_1;
  69.                 return 1;       
  70.         }
  71.         if(K2==0 && !Keytimer)
  72.         {
  73.                 Keytimer=Keytimer_1;
  74.                 return 2;       
  75.         }
  76.         if(K3==0 && !Keytimer)
  77.         {
  78.                 Keytimer=Keytimer_1;
  79.                 return 3;       
  80.         }
  81.         if(K4==0 && !Keytimer)
  82.         {
  83.                 Keytimer=Keytimer_1;
  84.                 return 4;       
  85.         }
  86.         if(K5==0 && !Keytimer)
  87.         {
  88.                 Keytimer=Keytimer_1;
  89.                 return 5;       
  90.         }
  91.         if(K6==0 && !Keytimer)
  92.         {
  93.                 Keytimer=Keytimer_1;
  94.                 return 6;       
  95.         }
  96.         if(K7==0 && !Keytimer)
  97.         {
  98.                 Keytimer=Keytimer_1;
  99.                 return 7;       
  100.         }
  101.         if(K8==0 && !Keytimer)
  102.         {
  103.                 Keytimer=Keytimer_1;
  104.                 return 8;       
  105.         }
  106.                 return 0;
  107. }
  108. void main()
  109. {       
  110.         unsigned char yh;
  111.         BZ=1;
  112.         A575=B575=C575=0;
  113.         P0=0x00;          
  114.         C575=1;C575=0;
  115.         initialize();
  116.         while(1)
  117.         {       
  118.                 yh=KES();
  119.                 if(yh==9)
  120.                 {
  121.                         OK++;
  122.                         if(OK==3){OK=0;sec=60,sec1=t=0;P0=0x00;          
  123.                                                 C575=1;C575=0;BZ=1;
  124.                                         }               
  125.                 }
  126.                 else if(OK==1 && yh>=1)
  127.                 {         
  128.                         OK=2;
  129.                         hh=yh;
  130.                         if(yh==1)
  131.                         {
  132.                                 P0=0x01;          
  133.                                 C575=1;C575=0;
  134.                         }
  135.                         else if(yh==2)
  136.                                 {
  137.                                         P0=0x02;          
  138.                                         C575=1;C575=0;
  139.                                 }
  140.                         else if(yh==3)
  141.                                 {
  142.                                         P0=0x04;          
  143.                                         C575=1;C575=0;
  144.                                 }
  145.                         else if(yh==4)
  146.                                 {
  147.                                         P0=0x08;          
  148.                                         C575=1;C575=0;
  149.                                 }
  150.                         else if(yh==5)
  151.                                 {
  152.                                         P0=0x10;          
  153.                                         C575=1;C575=0;
  154.                                 }
  155.                         else if(yh==6)
  156.                                 {
  157.                                         P0=0x20;          
  158.                                         C575=1;C575=0;
  159.                                 }
  160.                         else if(yh==7)
  161.                                 {
  162.                                         P0=0x40;          
  163.                                         C575=1;C575=0;
  164.                                 }
  165.                         else if(yh==8)
  166.                                 {
  167.                                         P0=0x80;          
  168.                                         C575=1;C575=0;
  169.                                 }               
  170.                 }               
  171.           shumaxianshi();               
  172.         }
  173. }

  174. void Timer0(void) interrupt 1
  175. ……………………

  176. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
八路抢答器.rar (165.37 KB, 下载次数: 80)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:447972 发表于 2018-12-17 14:33 | 显示全部楼层
真棒!
回复

使用道具 举报

ID:464414 发表于 2019-1-8 10:48 来自手机 | 显示全部楼层
谢谢!!!!!!!
回复

使用道具 举报

ID:464590 发表于 2019-1-8 16:31 | 显示全部楼层
谢谢!
回复

使用道具 举报

ID:464590 发表于 2019-1-8 16:55 | 显示全部楼层
谢谢!!!!!!!!!!!!!!!!
回复

使用道具 举报

ID:99800 发表于 2019-1-23 18:54 | 显示全部楼层
很棒不过有一个问题,中断里执行类似加分的程序可以吗
回复

使用道具 举报

ID:99800 发表于 2019-1-23 18:55 | 显示全部楼层
很棒,不过有一个问题,中断里执行类似加分的程序可以吗,统计选手积分
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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