当前位置:网站首页>基于51单片机的四路抢答器仿真
基于51单片机的四路抢答器仿真
2022-07-29 05:22:00 【半生烟火一世迷离】
当主持人按下开始按键后,开始倒计时60秒,选手开始抢答,当有选手抢答后其它选手抢答无效。
并且选手抢答后倒计时停止。
由于我没有设置新一轮按键,如果需要使用新一轮抢答可以加按键开启新一轮抢答
定时器配置代码
#include <REGX52.H>
void Timer0_Init(void)
{
TMOD &= 0xF0; //配置定时器模式
TMOD |= 0x01; //设置定时器0模式
TL0 = 0x3c; //设置定时初值50ms产生一次中断
TH0 = 0xb0; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
PT0=0;
}
数码管显示选手号代码
#include <REGX52.H>
#include "Delay.h" //包含Delay头文件
sbit we1=P2^0;
//数码管段码表
unsigned char Table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
//数码管显示子函数
void Nixie(unsigned int Speed)
{
we1=0;
P0=Table[Speed]; //段码输出
Delay(1); //显示一段时间
we1=1;
P0=0x00; //段码清0,消影
}
主函数、中断服务函数、数码管显示倒计时
#include <REGX52.H>
#include "Delay.h"
#include "Timer0.h"
#include "Nixie.h"
unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//共阴极数码管段码
sbit we3=P2^2;
sbit we4=P2^3;
unsigned int flag=0,ms=60;//ms设定倒计时初始值
unsigned int Number=0;
unsigned int x,z,y=0,f=0;
void main()
{
Timer0_Init();
while(1)
{
if(P1_4==0)
{
Delay(20);while(P1_4==0);Delay(20);
y=1;//倒计时开始标志位,1开始倒计时
flag=1;//抢答标志位,1按键有效,0按键无效
}
x=ms/10;
z=ms-x*10;//计算倒计时每一位的数据放入数码管中显示
we3=0;
P0=NixieTable[x]; //段码输出
Delay(1); //显示一段时间
we3=1;
P0=0x00; //段码清0,消影
we4=0;
P0=NixieTable[z]; //段码输出
Delay(1); //显示一段时间
we4=1;
P0=0x00; //段码清0,消影
if(flag==1)
{
if(P1_0==0)
{
Delay(20);while(P1_0==0);Delay(20);
flag=0;//使其它选手无法抢答
Number=1;//获得选手号送给数码管显示
f=1;//倒计时停止
}
if(P1_1==0)
{
Delay(20);while(P1_1==0);Delay(20);
flag=0;
Number=2;
f=1;
}
if(P1_2==0)
{
Delay(20);while(P1_2==0);Delay(20);
flag=0;
Number=3;
f=1;
}
if(P1_3==0)
{
Delay(20);while(P1_3==0);Delay(20);
flag=0;
Number=4;
f=1;
}
}
Nixie(Number);//数码管显示函数
}
}
void Timer0_Routine() interrupt 1
{
unsigned int T0Count;
TL0 = 0x3c; //设置定时初值为50ms
TH0 = 0xb0; //设置定时初值
T0Count++;
if(T0Count>=20)
{
T0Count=0;
if(f==0)
{
if(y==1)
{
ms--;//1s减一次
if(ms==0)
{
ms=60;
}
}
}
else
{
ms=ms;//选手抢答后倒计时停止
}
}
}
仿真图形
本次制作的抢答器比较简单,如果需要可以自行添加代码使功能更全面。后续如果时间充足可以进一步完善。
刚刚想了想我又加上了新一轮抢答按键
if(P1_5==0)
{
Delay(20);while(P1_5==0);Delay(20);
break;//当按键按下时跳出while主循环
}
边栏推荐
- [network design] convnext:a convnet for the 2020s
- NLP领域的AM模型
- How to perform POC in depth with full flash distribution?
- 三、如何读取视频?
- [target detection] KL loss: bounding box progression with uncertainty for accurate object detection
- Wechat built-in browser prohibits caching
- "Full flash measurement" database acceleration solution
- Typical cases of xdfs & China Daily Online Collaborative Editing Platform
- torch.nn.Embedding()详解
- ML16-神经网络(2)
猜你喜欢
基于STC51:四轴飞控开源项目原理图与源码(入门级DIY)
Power Bi report server custom authentication
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
Pytorch Basics (Introductory)
Transfer feature learning with joint distribution adaptation
Wechat applet source code acquisition (download with tools)
扬尘噪声监控系统
迁移学习—Geodesic Flow Kernel for Unsupervised Domain Adaptation
ML自学笔记5
Discussion on the design of distributed full flash memory automatic test platform
随机推荐
HAL库学习笔记- 8 串口通信之使用
基于FPGA:运动目标检测(补充仿真结果,可用毕设)
Reading papers on false news detection (I): fake news detection using semi supervised graph revolutionary network
Transfer feature learning with joint distribution adaptation
1、 Focal loss theory and code implementation
ABSA1: Attentional Encoder Network for Targeted Sentiment Classification
QT学习笔记-QtSQL
五、图像像素统计
Typical cases of xdfs & China Daily Online Collaborative Editing Platform
电脑视频暂停再继续,声音突然变大
迁移学习——Transfer Joint Matching for Unsupervised Domain Adaptation
3、 How to customize data sets?
华为云14天鸿蒙设备开发-Day3内核开发
[target detection] KL loss: bounding box progression with uncertainty for accurate object detection
预训练语言模型的使用方法
HAL库学习笔记-10 HAL库外设驱动框架概述
How to use the pre training language model
京微齐力:基于HMEP060的心率血氧模块开发(1:FPGA发送多位指令)
HR面必问问题——如何与HR斗志斗勇(收集于FPGA探索者)
Wechat applet source code acquisition (download with tools)