赞
踩
此电路由AT89C51最小系统、四位数码管、蜂鸣器电路和按键模块组成。
运行原理:
该抢答器电路可同时进行八路优先抢答。按键按下后,蜂鸣器发声,同时数码管
显示优先抢答者的号码,抢答成功后,再按按键,显示不会改变,除非按主持人键。
复位后,显示清零,可继续抢答。
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
-
- //按键扫描,判断哪个人抢答
- void key()
- {
- uint n, flag = 1;
- n=2200;
- display(n);
- keep=1;
-
- if(key2==0)
- {
- delay(5);
- if(key2==0)
- {
-
- while(1)
- {
- n=2202;
- display(n);
-
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key2);
- delay(5);
- }
- if(key3==0)
- {
- delay(5);
- if(key3==0)
- {
- while(1)
- {
- n=2203;
- display(n);
-
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key3);
- delay(5);
- }
- if(key4==0)
- {
- delay(5);
- if(key4==0)
- {
- while(1)
- {
- n=2204;
- display(n);
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key4);
- delay(5);
- }
- if(key5==0)
- {
- delay(5);
- if(key5==0)
- {
- while(1)
- {
- n=2205;
- display(n);
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key5);
- delay(5);
- }
- if(key6==0)
- {
- delay(5);
- if(key6==0)
- {
- while(1)
- {
- n=2206;
- display(n);
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key6);
- delay(5);
- }
- if(key7==0)
- {
- delay(5);
- if(key7==0)
- {
- while(1)
- {
- n=2207;
- display(n);
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key7);
- delay(5);
- }
- if(key8==0)
- {
- delay(5);
- if(key8==0)
- {
- while(1)
- {
- n=2208;
- display(n);
- if(flag)
- {
- keep=0; //开启蜂鸣器
- delay(80);
- keep=1; // 关闭蜂鸣器
- delay(80);
- flag = 0;
- }
- if(key9==0)
- {
- delay(5);
- if(key9==0)
- {
- keep=1;
- n=2200;
- display(n);
- while(1)return;
- }
- while(!key9);
- delay(5);
- while(1);
- }
- }
- }
- while(!key8);
- delay(5);
- }
- }
-
- // 主函数
- void main()
- {
- while(1)
- {
- key(); // 判断按键
- }
- }
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。