前阵子写的练习,程序仿真都在里面
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #include"key.h"
- #define uchar unsigned char
- #define uint unsigned int
- uchar number[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- void main()
- {
- uchar cloose,l;
- uint o;
- while(1)
- {
- P0=0X00;
- SPEAKER=1;
- if(startkey()==1) //检测是否按下开始按钮
- {
- cloose=cloosekey(); //检测是否有违规情况
- if(cloose==0) continue; //无人违规 则返回
- else P0=number[cloose]; //有人违规,显示号码
- while(endkey()==1); //蜂鸣器长鸣
- for(o=0;o<500;o++)
- speaker();
- // while(endkey()==0);
-
- }
- else{P0=0x49;} //显示“三”提示开始抢答
- while(endkey()==1)
- {
- cloose=cloosekey(); //检测是否有选手抢答
- if(cloose!=0)
- {
- P0=number[cloose]; //显示抢答选手号码
- for(l=0;l<150;l++)
- speaker(); //有选手抢答则蜂鸣器响
- while(endkey()==1);
- break; //按下结束,本轮结束
- }
- }
-
- }
- }
复制代码
所有资料51hei提供下载:
八路抢答器.rar
(54.64 KB, 下载次数: 36)
|